Download source: robotsrc1.zip or JAR file RobotTest1.jar
This app tests robot motion by executing three cases:
Gregory Dudek and Michael Jenkin, Computational Principles of Mobile Robots, Cambridge University Press, 2000. ISBN 0-521-56876-5.
RobotTest1.javaSee Robot.java
import javafx.animation.Animation;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.shape.*;
import javafx.scene.layout.Pane;
import javafx.scene.layout.BorderPane;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.util.Duration;
import javafx.collections.*;
import java.util.*;
public class RobotTest1 extends Application
{
@Override // Override the start method in the Application class
public void start(Stage primaryStage)
{
// Create a pane
TestPanel pane = new TestPanel();
// Create a handler for animation
EventHandler<ActionEvent> eventHandler = e -> {
pane.update();
};
// Create an animation
Timeline animation = new Timeline(
new KeyFrame(Duration.millis(50), eventHandler));
animation.setCycleCount(Timeline.INDEFINITE);
animation.play(); // Start animation
BorderPane layout = new BorderPane();
Label label = new Label();
pane.status = label;
pane.showVelocity();
layout.setCenter(pane);
layout.setBottom(label);
// Create a scene and place it in the stage
Scene scene = new Scene(layout, 440, 460);
primaryStage.setTitle("Robot test 1"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
public static void main(String args[] )
{
launch(args);
}
}
class TestPanel extends Pane
{
int wait;
double wd, ht;
Robot robot;
double simtime = 0.0;
int stage = 0;
Label status;
TestPanel()
{
Path p = new Path();
ObservableList<PathElement> pe = p.getElements();
for (int n=0; n<9; n++) {
pe.add(new MoveTo(10,10+n*50));
pe.add(new LineTo(410,10+n*50));
pe.add(new MoveTo(10+n*50,10));
pe.add(new LineTo(10+n*50,410));
}
p.setStroke(Color.RED);
getChildren().add(p);
robot = new Robot(210,210,6,-6,Color.rgb(120,120,255));
robot.draw(this);
}
public void showVelocity() {
status.setText(" " + robot.showVelocity());
}
public void update()
{
wd = getWidth();
ht = getHeight();
double tstep, tmore;
tmore = 1.0;
/*
while (tmore>0.0) {
tmore = 0.0;
}
*/
robot.move(0.05);
simtime = simtime + 0.05;
if (simtime>12*Math.PI && stage==2) {
stage = 0;
simtime = 0;
robot.setPose(210,210,0);
robot.setVelocity(6,-6);
showVelocity();
}
else if (simtime>8*Math.PI && stage==1) {
stage = 2;
robot.setPose(210,210,0);
robot.setVelocity(47,53);
showVelocity();
}
else if (simtime>4*Math.PI && stage==0) {
stage = 1;
robot.setPose(210,204,0);
robot.setVelocity(0,6);
showVelocity();
}
}
}
Maintained by John Loomis, updated Tue Feb 20 17:35:20 2018