Drawing arcs

When using a mobile EV3 robot such as the standard Lego driving base model, it's not at all obvious how to draw an arc with a given radius of curvature and a given arc angle using this command. The same is true in the standard EV3 software, whether you use the Move Steering block or the Move Tank block. After some very interesting mathematical discussions (just the kind you would hope to have with your students) with a kindly mathematician friend, I was able to obtain this relationship between the wheel separation, w, the radius of curvature of the drawn arc, r, the speed of the left wheel s1, and the speed of the right wheel s2. Note that this equation works even if one or both of the wheel speeds is negative. 

     s1/s2=(2r-w)/(2r+w)   which can be rearranged to give  r=(w/2)(s2+s1)/(s2-s1)

Deriving this equation for yourself could be a very interesting and satisfying mathematical exercise for you or your students, as it was for me... Note that the above equation works only if the pen is located at the midpoint between the wheels, as is the case for our robot. For a closer look at the above equations please see this page.

Note also that if s1=s2 then the result becomes infinite, which is to be expected since in this case the robot will move in a straight line and a straight line could be considered to be an arc with a radius of curvature that is infinite.

Another special case to note is that you can draw an arc with zero radius (in practice the robot will draw an arc with a very small radius of curvature) by making s1 and s2 equal and opposite, since this gives s2+s1 = 0 to substitute into the equation above. If you think about it, this makes sense, and if you try having the robot draw an arc in this way then you should get confirmation that this works. For example, you could try (while the pen is down) Motor.MoveSync("BC", -20, 20, 360, "True"). Don't forget that the angle turned by the motors is not the same as the angle turned by the robot, so don't expect the robot to turn through 360°.

If s1 = zero (so the left wheel is not rotating) then the equation simplifies to r=w/2 which gives you a very easy way to check how well the equation is working. Just make the robot draw at least a semicircle with s1=0 (we have't yet said seen the equation for arc angle) then measure the diameter of the drawn arc - it should simply equal w, the wheel separation. For the official Lego Driving Base model, the separation of the center of the tires, w, is 12.5cm. From this point on I will use this value in my calculations - remember that that means my calculations will only work for the standard Lego driving base or any other model that has the same wheel separation.

The diameter of the real drawn circle may be different from the calculated diameter and this highlights an issue to do with the wide tires supplied with the EV3 kit: it may not be correct to measure the wheel separation from the center of one tire to the center of the other even though this is the obvious thing to do. The physics is more complicated than that. It may be that the weight of the robot is carried more by the inner part of the tire than by the outer part of the tire, for example, which would reduce the effective wheel separation. However, having just drawn a semicircle (or more) whose diameter SHOULD have equalled the wheel separation we can now define the effective wheel separation as the diameter of the drawn semicircle you just measured. Using this value for w from now on should give you better results when using the equation. 

Let's see how the equation works in other cases. If we use speed1=20 and speed2= 40 then the equation gives   

r=(w/2)(s2+s1)/(s2-s1) = 12.5cm/2 * (40+20) / (40-20)  =  6.25cm * 60 / 20 = 6.25cm * 3 = 18.75cm

That's probably too big a radius of curvature for you to easily measure, so let's aim for a smaller, more measurable radius of curvature, say 4cm. Then we get   

s1/s2=(2r-w)(2r+w) = (2*4cm-12.5cm) / (2*4cm+12.5cm) = -4.5cm / 20.5cm =  -0.22

This does not give us specific values for s1 and s2, and indeed many speed combinations would give approximately the desired ratio. Since the ratio is negative, one motor will have to have a negative speed. We could use, for example, s1= -11 and s2=+50  or we could use s1=+11 and s2=-50.  The pen will move in different ways for these different pairs of values, but each time the radius of curvature will be 4cm. A little thought will tell you that if the sum of the two wheel speeds is positive then the pen will move forwards, and if the sum of the wheel speeds is negative then the pen will move backwards. So for the first pair of speed values (s1=-11,  s2=+50) the pen will move forwards and for the other pair the pen will move backwards.

What about the sign of r? Does that tell us anything? In the previous paragraph, r was positive, and we looked first at the pair of speeds s1=-11,  s2=+50. A little thought will tell you that in that case the pen will move forwards counter-clockwise along the arc. The other pair of values s1=+11,  s2=-50 would make the pen move backwards clockwise along the arc. So the sign of r does not tell us whether the pen will move clockwise or counter-clockwise along the arc. But both those arcs we just considered have their center of curvature to the left of the robot, so maybe r can tell us whether the center of curvature of the arc is to the left or to the right of the robot? Let's try a negative value of r, to see whether the center of curvature will be to the right of the robot as we are starting to suspect (this is of course not a mathematical proof of anything - I'll leave that up to you!). Let's try r = -8cm:

s1/s2=(2r-w)/(2r+w) = (2*-8cm-12.5cm)/(2*-8cm+12.5cm)= -28.5cm/-3.5cm  = 8.143

This could be roughly satisfied by, for example, s1=41 and s2=5 which would indeed trace an arc whose center of curvature would be to the right of the robot. I'm confident then (though I haven't proved it for you) that

A positive value of r indicates that the center of curvature of the arc will be to the left of the robot, and v.v.

In the previous paragraph I showed that the sign of r does NOT indicate whether the pen will trace its arc clockwise or counter-clockwise. Is there any way of knowing whether the arc will be traced clockwise or counter-clockwise? I propose this rule, and leave you to verify or prove it:

s1>s2 means the pen will trace the arc clockwise and v.v.

Using this rule, don't forget that 'is greater than' means 'is more positive than' so, for example, -5>-8.

The text below is not ready!

Now it's time to consider how to work out the angle(s) through which the motors must turn in order to give a specific arc angle for the drawn arc. In fact what we really need to know is the angle 'X' turned by the faster motor since this is the only angle that needs to be supplied to the Motor.MoveSync command. The angle to be turned by the slower motor can easily be calculated as A * slower speed / faster speed.

You may recall from your math classes that angle in radians = arc length / radius. Let's call the arc length L and the angle subtended by the drawn arc Y. Then Y=L/r.

When a wheel turns, it rolls along the ground a distance equal to the angle of turn in radians times the radius. The angle in radians can be obtained from the turn angle in degrees, D, by multiplying by pi/180i. So we have distance moved by wheel = D * (180/pi) * R, where R is the radius of the wheel (not to be confused with the radius of the drawn arc which I called r). Similarly,the distance moved by the pen, L = Dav * (180/pi) * R where Dav is the average angle of turn of the two wheels. 

This distance also equals the number of rotations of the wheel times its circumference. Distance = number of rotations * 2 * pi * R. Being halfway between the wheels the pen will move the average distance moved by the two wheels, taking into account whether each one is moving forwards or backwards. That means it will move the average number of rotations of the two wheels times the circumference of each wheel. The number of rotations of a wheel is its turn angle divided by 360°, so the turn angle is the number of rotations * 360°. 

We know that when a wheel turns through a full rotation its full circumference (2*pi*R) will roll along the ground. So when a wheel turns through a given angle 'a' the distance the wheel moves forwards (or backwards) is given by a/360 * 2*pi*R (note that I'm using R for the radius of the wheel to distinguish it from the r that I am using for the radius of curvature of the drawn arc). That distance that the wheel rolls might be a straight line or an arc, depending on what the other wheel is doing. If the left and right wheels turn through different angles then they will move through different distances and the distance moved by the midpoint of the wheels will be the average of the distances moved by the two wheels, taking into account whether the wheels are turning forwards or backwards. For example, if both wheels move forwards a distance of 10cm then the pen will also move a distance of 10cm. If one wheel moves 10cm forwards and the other moves 5cm forwards then the pen will move 7.5cm forwards, in an arc. The wheels will also move through arcs in this case. In one wheel moves 10cm forwards and the other moves 15cm backwards then the average of these movements (the movement of the pen) will be 2.5cm backwards.

The angle of the arc drawn by the pen will be given by its arc length divided by the circumference of the circle of which it is a part times 360°.  

 like each wheel). 

magine we let the robot draw a full circle with the pen. The circumference of the circle will be

2*pi*r  =  2*pi*(w/2)(s2+s1)/(s2-s1)   =  (pi*w)(s2+s1)/(s2-s1)

I came up with this equation (deriving this is again a very nice mathematical challenge):

where d is the diameter of the wheels of the EV3, x is the arc angle and 

One last thing to think about. What if our calculation tells us that we need a ratio equal to 40? What values of s1 and s2 would you propose? You might suggest s1=2, s2=80 but in my experience, speeds less than about 5 are not usable because the motor movement tends to become jerky, so it might not be possible to find a usable speed pair that gives the desired ratio. So there may be certain curves that the robot cannot draw - they are curves with a radius of curvature close to (but not equal to) w/2 (think about why).