Step 1
Driving a wheeled robot
Steer a rover with a speed and a turn rate: drive a perfect circle, then write a controller that visits three beacons.
Builds on Angles, atan2 & 2-D rotation and Feedback: P and PD control, from the free Foundations.
A robot on wheels
The rover in the viewer has two wheels on one axle, each with its own motor. Spin them at the same speed and it drives straight; spin them at different speeds and it turns. This is differential drive. You don't command the wheels one by one: you give a forward speed (m/s) and a turn rate (rad/s, anticlockwise positive), and the rover works out the wheel speeds.
The rover's pose says where it is: its position on the table in metres, and its heading in radians, measured anticlockwise from the axis. rover.pose reads it.
Arcs
Hold and steady and the rover drives round a circle. In seconds it covers metres and turns radians, so a full turn () takes seconds and covers the circumference . That gives the radius:
drives straight ( is infinite) and spins on the spot.
Go to a goal
To reach a point , keep steering towards it:
- the direction to the goal is , and its distance is ;
- the heading error is , wrapped into with
rover.wrapso the rover turns the short way; - turn in proportion to it: ;
- drive at : slow down on arrival, and don't drive forwards while facing away.
Every 50 ms, read the pose and recompute. This is a feedback loop: the rover corrects its own mistakes. Foundations: Angles, atan2 & 2-D rotation covers atan2 and wrapping.
Your task
- Set
WandTsorover.run(V, W, T)drives one full circle of radius = 10 cm and comes back to the start. - Finish
go_to(goal): compute the heading error and each time round the loop. It stops within 1 cm of the goal.
The program then visits the three beacons in turn and plots the distance and heading error. The checks want the circle within 5 mm, each goal reached within 2 cm, no bumps and the tour in under 30 s.