10 Spinning the robot about the center of its axle

If we turn the two wheels of a differential drive robot at the same speed but in opposite directions then the robot will spin in place around the center of the axle passing through both wheels.

10.1 Write a function to spin the robot by 90 degrees

In MATLAB, create and complete the following function:

function spinLeft()
%SPINLEFT Spin the differential drive robot 90 degrees left
%   spinLeft() spins the differential drive robot 90 degrees
%   left (counter-clockwise looking down on the robot).

% 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). You should first figure out how to set the servo positions so that the robot spins in place to the left before trying to spin by 90 degrees.

Once you know how to use setServoPosition to spin the robot in place, you need to figure out how long to spin the robot so that it spins 90 degrees (i.e., you need to figure out how to compute the value t). You can compute t by observing the following:

  • you know what the wheel ground velocity (\(v_l\) or \(v_r\)) is in centimetres per second 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 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)

10.2 Test your method

Test that your method spins the robot to the left by 90 degrees. The robot is unlikely to spin exactly 90 degrees, but the spin angle should be quite close to 90 degrees. You can adjust the ground velocity value to adjust the spin angle.