11 Turning the robot to the left
If we turn both wheels forward where the right wheel turns faster than the left wheel then the robot will move forward turning to the left. The radius of the turn depends on the speeds of the left and right wheels.
11.1 Write a function to turn the robot by 90 degrees
In MATLAB, create and complete the following function:
function turnLeft(R)
%TURNLEFT Turn the differential drive robot left by 90 degrees
% turnLeft(R) turns the differential drive robot left by
% 90 degrees where the radius of the turn is given by R.
%
% R must be greater than or equal to 0.
% inter-wheel distance of robot in cm
L = 12.3;
% your code starts here
% your code stops here
pause(t)
stopRobot()
When you implement this function, you should use motor positions equal to the zero-speed positions plus-or-minus 15 motor units (similar to the positions used in moveForward
) for the right wheel. You will then need to compute the correct number of motor units for the left wheel.
This function is similar to spinLeft
in that you need to figure out how to compute t
. You can compute t
by observing the following:
- you know what the wheel ground velocity \(v_r\) is corresponding to 15 motor units from
moveForward
- the approximate inter-wheel distance of robot \(L\) is given to you in the function
- you can calculate the left wheel ground velocity \(v_l\) using \(R\), \(L\), and \(v_r\) using the formulae provided to you earlier in the lab
- once you have \(v_l\) (in \(\text{cm}/s\)) you can compute the left motor position in motor units
- you can calculate the angular velocity \(\omega\) in radians per second using the formulae provided to you earlier in the lab
- you know the angle of rotation (90 degrees which is equal to \(\pi/2\) radians)
11.2 Test your method
Before trying to move the robot with your method, pick up the robot without touching the wheels (or prop up the front of the robot so that the wheels are not touching anything) and call turnLeft
with a radius of 10 cm. The left motor should turn very slowly compared to the right motor
Test that your method turns the robot through a 90 degree arc of radii 0, 15, and 30 centimetres. Note that turnLeft(0)
should produce the same motion as spinLeft()
.
The robot is unlikely to turn exactly 90 degrees with a turning radius of exactly R
, but the angle should be quite close to 90 degrees and the turning radius should be quite close to R
. You can adjust the ground velocity value to adjust the turning angle and radius.