tag:blogger.com,1999:blog-7028146233533395417.post7277232741294799620..comments2016-06-14T20:57:19.322+01:00Comments on Adventures in Robotics: Differential drive to forward/turnrate conversionJennyhttp://www.blogger.com/profile/14080715403232385100noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-7028146233533395417.post-8383862869391015832010-05-22T03:31:52.175+01:002010-05-22T03:31:52.175+01:00Woopsy! I made two big mistakes in the code I past...Woopsy! I made two big mistakes in the code I pasted above. The issues are with the lines setting the 'newturnrate'. In the first case, left > right, it should have been (right - left) instead of (left - right), and in the second case I should have replaced 'newspeed' with 'left'. Yes, in both cases the line is now the same.<br /><br />Here's the patched code, which should be correct this time:<br />----------------<br />// which is the outer wheel and which is the inner?<br />if (left > right) { // left is outer wheel<br /> // newspeed is average between inner and outer wheel speed<br /> newspeed = right + (left - right)/2;<br /> newturnrate = (right - left) / separation;<br />}<br />else if (right > left) { //right is outer wheel<br /> // newspeed is average between inner and outer wheel speed<br /> newspeed = left + (right - left)/2;<br /> newturnrate = (right - left) / separation;<br />}<br />else {<br /> newspeed = left; //could also be right<br /> newturnrate = 0;<br />}<br />----------------<br /><br />Hope that helps!Robertnoreply@blogger.comtag:blogger.com,1999:blog-7028146233533395417.post-62584238134816984622010-05-22T02:23:29.746+01:002010-05-22T02:23:29.746+01:00Hi Jenny,
Thanks for the code, it was very helpfu...Hi Jenny,<br /><br />Thanks for the code, it was very helpful! I did find a few inaccuracies when I used it in my project, so I made some improvements that I thought you might want to see.<br /><br />Picture the following situation: I turn my robot's left wheel on, and leave the right wheel off. The robot should now spin around its right wheel. The code you've presented above doesn't exactly do that: since the forward speed is set to the speed of the inner wheel (which is in this case standing still) the robot does not move, and rotates around its centre point instead of its inner wheel.<br /><br />Another problem arises when I turn my robot's wheels on in opposing directions. The robot should spin around its centre point; in the original code, it would do something else entirely.<br /><br />Fortunately, the situation is easily fixed. Think about the first one-wheel-blocked-case. The robot has speed there, but not the speed of the inner wheel (which is standing still). In fact, the correct speed is that of an average between the two wheels. If my left wheel is spinning at 2 m/s and the right one at 0 m/s, the correct speed is 1 m/s. A formula to compute this is:<br /><br />newspeed = inner_wheel_speed + (outer_wheel_speed - inner_wheel_speed)/2<br /><br />Now what would happen when the wheels run in opposing directions, say at 1 and -1 m/s? Using this updated code the speed is 0, and the robot turns on the spot, exactly as it should!<br /><br />Note that since 'newspeed' now no longer is equal to the inner wheel speed, the next line setting the 'newturnrate' must also be slightly changed.<br /><br />Here is the full updated code snippet:<br /><br />---------------<br />// which is the outer wheel and which is the inner?<br />if (left > right) { // left is outer wheel<br /> // newspeed is inner wheel speed<br /> newspeed = right + (left - right)/2;<br /> // newturnrate = (outer(m) - newspeed)/separation<br /> newturnrate = (left - right) / separation;<br />}<br />else if (right > left) { //right is outer wheel<br /> //newspeed is inner wheel speed<br /> newspeed = left + (right - left)/2;<br /> //newturnrate = (outer(m) - newspeed)/separation<br /> newturnrate = (right - newspeed) / separation;<br />}<br />else {<br /> newspeed = left; //could also be right<br /> newturnrate = 0;<br />}<br />---------------<br /><br />Cheers!Robertnoreply@blogger.comtag:blogger.com,1999:blog-7028146233533395417.post-75205156914264658672010-03-20T03:58:04.228+00:002010-03-20T03:58:04.228+00:00Nice ! ...Nice ! ...Arkapravohttps://www.blogger.com/profile/12257489973579585325noreply@blogger.com