summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2014-01-09 18:05:08 +0100
committerPeter Wu <lekensteyn@gmail.com>2014-01-09 18:05:08 +0100
commit3f107ae90b229e3f382989996d77f54faed4d8f0 (patch)
treeb2eb37ebd4d94ccbdf401ce3f1560d19be97e5af
parentda52a53858c833955d5dee592719a24361a120bc (diff)
download2iv60-robots-3f107ae90b229e3f382989996d77f54faed4d8f0.tar.gz
Fix confusion of meters, time pos and GST
Robots get a speed of 19 km/s (average human speed).
-rw-r--r--src/Robot.java40
-rw-r--r--src/RobotRace.java4
2 files changed, 35 insertions, 9 deletions
diff --git a/src/Robot.java b/src/Robot.java
index 0e496e1..3b9c0cb 100644
--- a/src/Robot.java
+++ b/src/Robot.java
@@ -48,15 +48,20 @@ class Robot extends BetterBase {
private double speed;
/**
- * Location of the robot on the track (in terms of GlobalState time).
+ * Location of the robot on the track (in meters).
*/
- private double robot_time_pos;
+ private double robot_pos_meters;
/**
* The lane number on which this robot is positioned. Must be a positive
* number greater or equal to zero.
*/
private final int laneNo;
+ /**
+ * Length of the race track in meters. (76 is the approximate perimeter of
+ * an ellipse with half-widths 10 and 14.)
+ */
+ private final static double TRACK_LENGTH = 76.0;
/**
* Constructs the robot with initial parameters.
@@ -479,10 +484,31 @@ class Robot extends BetterBase {
/**
* Determine the location of the robot on the track.
- * @return A positive number (time).
+ * @return A positive number between 0 (begin) and 1 (end). Higher values
+ * can also be returned which means that at least one full round has been
+ * made.
*/
public double getTimePos() {
- return robot_time_pos;
+ double pos = meter2racepos(robot_pos_meters);
+ return pos;
+ }
+
+ /**
+ * Map meters to the position on the race track.
+ * @param meter Distance in meters.
+ * @return Position on the race track.
+ */
+ public static double meter2racepos(double meter) {
+ return meter / TRACK_LENGTH;
+ }
+
+ /**
+ * Map the position on the race track to meters.
+ * @param gst Elapsed global state time.
+ * @return Distance in meters.
+ */
+ public static double racepost2meter(double gst) {
+ return gst * TRACK_LENGTH;
}
/**
@@ -494,7 +520,7 @@ class Robot extends BetterBase {
}
/**
- * Gets the speed of this robot.
+ * Gets the speed of this robot (in meters per second).
*/
public double getSpeed() {
return speed;
@@ -505,14 +531,14 @@ class Robot extends BetterBase {
*/
public void walkSome(double seconds) {
assert seconds >= 0 : "Robot cannot walk backwards!";
- robot_time_pos += speed * seconds;
+ robot_pos_meters += speed * seconds;
}
/**
* Resets the position on the track to the begin.
*/
public void resetPosition() {
- robot_time_pos = 0;
+ robot_pos_meters = 0;
}
/**
diff --git a/src/RobotRace.java b/src/RobotRace.java
index ee1fc86..3c2f9cd 100644
--- a/src/RobotRace.java
+++ b/src/RobotRace.java
@@ -132,9 +132,9 @@ public class RobotRace extends Base {
private final static double SPEED_RECALC_INTERVAL = .500;
/**
- * Desired average robot speed in meter per second.
+ * Desired average robot speed in meter per second. (Ne3 / 3600 is N km/h)
*/
- private final static double TARGET_ROBOT_SPEED = .03;
+ private final static double TARGET_ROBOT_SPEED = 19e3 / 3600;
/**
* Used for randomizing robot speed.