diff options
author | Peter Wu <lekensteyn@gmail.com> | 2014-01-09 18:07:45 +0100 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2014-01-09 18:07:45 +0100 |
commit | 3e879e2f6664b147a26bb0e302d3bb00c553262d (patch) | |
tree | 7669949299bdff02e28b9b9a835fd591b73d266b /src | |
parent | 3f107ae90b229e3f382989996d77f54faed4d8f0 (diff) | |
download | 2iv60-robots-3e879e2f6664b147a26bb0e302d3bb00c553262d.tar.gz |
Fix robot speed calculation
robot.getTimePos() returns a distance in "race pos" unit, avg_pos is
the distance in meters. Convert the former to meters and use adjust
weights for speed calculation (care less about previous speed, that one
could be braindead).
Diffstat (limited to 'src')
-rw-r--r-- | src/RobotRace.java | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java index 3c2f9cd..57e0a98 100644 --- a/src/RobotRace.java +++ b/src/RobotRace.java @@ -137,6 +137,11 @@ public class RobotRace extends Base { private final static double TARGET_ROBOT_SPEED = 19e3 / 3600; /** + * The targeted distance between the robot and the average walking position. + */ + private final double DIST_DIFF = 5; + + /** * Used for randomizing robot speed. */ private final Random random = new Random(); @@ -403,30 +408,34 @@ public class RobotRace extends Base { double avg_pos = current_t * TARGET_ROBOT_SPEED; for (Robot robot : robots) { + double robot_pos = Robot.racepost2meter(robot.getTimePos()); double old_speed = robot.getSpeed(); // initially the speed of robots is unknown, assume target speed if (old_speed <= 0) { old_speed = TARGET_ROBOT_SPEED; } /* Speed is the sum of: - * 20% previous speed - * 30% minimum speed (100% target speed = 30%) - * 50% random speed (max. 200% target speed = 100%, since it is - * random, the expected random speed is 50%.) + * 10% previous speed (on average 20% target speed) + * 50% minimum speed (100% target speed = 50%) + * 40% random speed (0% - 60% target speed) + * + * The random speed ranges from 0%-200% of the target speed. Its + * range can change to 0%-150% or 0%-250% depending on the + * difference with the expected average position. */ double speedup_factor = 2.0; - // if a robot is lagging behind too much, then give it a higher - // chance to walk faster. Similarly, if it is too fast, make - // it slow down a bit. The difference is at most 60% for the - // random speed (expected: 30%, final effect: 15%). - double pos_diff = (avg_pos - robot.getTimePos()) / TARGET_ROBOT_SPEED; - pos_diff = Math.max(-0.6, Math.min(pos_diff, 0.6)); - speedup_factor += pos_diff; + // if a robot is lagging behind too much (> 0), then give it a + // higher chance to walk faster. Similarly, if it is too fast + // (< 0), make it slow down a bit. + double pos_diff = avg_pos - robot_pos; + // do not change speed too much for huge speed differences + double n = Math.max(-DIST_DIFF, Math.min(pos_diff, DIST_DIFF)); + speedup_factor += n / DIST_DIFF * .5; double rnd = random.nextFloat(); - double speed = .2 * old_speed; - speed += .3 * TARGET_ROBOT_SPEED; - speed += .5 * rnd * speedup_factor * TARGET_ROBOT_SPEED; + double speed = .1 * old_speed; + speed += .5 * TARGET_ROBOT_SPEED; + speed += .4 * rnd * speedup_factor * TARGET_ROBOT_SPEED; robot.setSpeed(speed); } // DEBUG: average speed to robot 1 for showing expected position |