This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
(Moderators: fry, REAS)
   a spinning car problem...
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: a spinning car problem...  (Read 657 times)

WWW Email
a spinning car problem...
« on: Jun 2nd, 2004, 8:16am »

This seems to be quite simple, but arrgghhh I can't figure it out:
There is a car with 2 wheels. Each wheel can rotate at different speed. So if one goes clockwise and one goes counter-clockwise, the car will spin; and if one goes faster than the other, the car will curve; and if they are of the same speed, the car will go straight...
So let wheel-A rotate at speed X, and wheel-B at speed Y -- how can we find out by how much the car is turning & moving?
Any help will be greatly appreciated. Thanks

Re: a spinning car problem...
« Reply #1 on: Jun 2nd, 2004, 6:17pm »

on Jun 2nd, 2004, 8:16am, william wrote:
So let wheel-A rotate at speed X, and wheel-B at speed Y -- how can we find out by how much the car is turning & moving

If only I had learned math...
Here's how far I got (no time and I am too slow):
Assume that both wheels are W units apart. Then if the speed of the outside wheel is twice that of the inside wheel, it is tracking a circle with a circumference twice that of the inside wheel, which I think would mean that its turning radius is twice that of the inside wheel. This I think would put the outside wheel at radius 2 * W and the inside wheel at radius W.  
[formula should be here]
If one wheel has a negative speed then the turning point is between them; then you might have to compare how far each speed is from zero to determine where the turning point lies.
« Last Edit: Jun 2nd, 2004, 6:28pm by kevinP »  

Kevin Pfeiffer

WWW Email
Re: a spinning car problem...
« Reply #2 on: Jun 3rd, 2004, 3:20am »

Hi Kevin, thanks for your excellent insights! Yes, the wheels should be W units apart.
I think what I'm trying to calculate is the new position & rotation of the car after each time step...  
If only I had been a good student at high-school... ah!

Re: a spinning car problem...
« Reply #3 on: Jun 3rd, 2004, 11:13am »

If you want to get a perfect answer, I think you have to do an integration.. however, if you've got a locked time step (e.g. every 0.1 time units) then you can get away with a fixed calculation and get a "good enough" answer to look at.
However, what that is, I'm not entirely 100% sure.
Here is a stream of consciousness answer, as I'm thinking it up, I'm assuming that the wheels can't slip, etc...
I know that the rotation speed (in degrees/time unit or radians, whatever) is directly proportiaonal to the distance a wheel will travel.
So wheel A turns at X degrees/time and B turns at Y, and X and Y can be negative.
So A travels 2*pi*WheelRadius*(360/degrees/time unit) per time unit, call this Da, and wheel b moves Db.
And there's a fixed axle length, C
If X and Y are opposite signs, (i.e. one is +ve, and one is -ve) then you can say that the axle rotates around a point somewhere between A and B.
This point is the same as the ratio of Da and Db I think, e.g. if Da is twice Db, the rotation point is 2/3 of the way along the axle towards B: (Bad ascii art time)

 ^^ . . .^^
Wheel A  Wheel B
Da = 2*Db
 . . .^^
 Whole system rotates around this point

To work out the angle the whole thing rotaes we know that the thing rotates, and so the wheels take a circular path, and so the angle required is given by finding out for one wheel, in this case A (could be B, you just need to chose one)
omega = 360 * Da/(2*pi*(C*(Da/(Da+Db))));
(I think, you work out the circumference of a circle with radius of whatever the distance between the rotation point and wheel A is, divide the distance wheel A travels by that, to get the fraction of a circle it travels, then multiply by 360 to get an answer in degrees (or by 2*pi in radians))
If one wheel is not moving, the whole system rotates around that wheel, using the same dtails as above, except you know the raio between Da and Db is infinite, so it's just a special case where the rotation point is a wheel, instead of part way down the axle)
Now, fo rwhen both wheels are going in the same direction...
I *think* you can work this out, since the two wheels trace out the circumference of two different circles, but with the same centre point.. e.g. draw 2 circles with the same cntre point, but with different radiuses.
Now, we get to the part I'm slightly less sure of.. assume wheel A is faster than wheel B for now.
There is a circle of radius T for which there's one of radius T- axle length), U, such that the length of an arc of V degrees of T and U are the same as Da and Db.
Adn now I think I need to go away with a bit of paper and scribble for a while to work out how to work out T, U and V, but it's probably something to do with the ratio of Da and Db again
« Last Edit: Jun 3rd, 2004, 11:14am by JohnG »  

Re: a spinning car problem...
« Reply #4 on: Jun 3rd, 2004, 11:34am »

Ah, think I've got it.. not going to write down all my scribblings this time, but, I think the angle of circle that the arcs of both wheels trace out, (gamma) can be found by:
(Da = distance travelled by wheel A, Db = distance travelled by wheel B, C = axle length)
gamma = (360*(Da/(Db+C)))/(2*pi);
change 360 to 2*pi for angle in radians...
And once we have gamma, we can find the radius of the circles that A and B trace, the radius of circle drawn by A = ((Da*360)/gamma)/2*pi, and B is the same but with Db instead of Da.
Now you just have to work out how to implement this I think, and then test to see if I'm right
Re: a spinning car problem...
« Reply #5 on: Jun 3rd, 2004, 1:44pm »

The steering model you describe is called differential steering. There's an excellent paper on simulating it here:
And a google search will turn up example applets and source code I'm sure.  I have an implementation somewhere which I will post this weekend if I can find it.

WWW Email
Re: a spinning car problem...
« Reply #6 on: Jun 4th, 2004, 7:10am »

Thanks very much for the methods and pointers! They're most excellent.
I'll try the methods and post the results here...

WWW Email
Re: a spinning car problem...
« Reply #7 on: Jun 5th, 2004, 10:57am »

Got it!
The article on differential steering is very helpful, and very similar to John's thoughts.  
Fortunately, dreadful calculus isn't necessary since I don't need to predict the car's course. Hurrah!
(the scrollbar isn't very accurate, try use key Q,W and O,P for steering.)
Thanks again for the help!

Re: a spinning car problem...
« Reply #8 on: Jun 5th, 2004, 5:37pm »

Cool!  Well done.
Could really do with a couple of Joysticks (or a PS2 controller though) don't you think?  I had exactly the same problem with keyboard input when I wrote something similar.  In the end I think I made the levels have a slight decay back to the midpoint (so that you had to keep the key down if you wanted to go forward, but that it was quicker to let go and then hit the back key to go into reverse).

WWW Email
Re: a spinning car problem...
« Reply #9 on: Jun 6th, 2004, 2:13pm »

Thanks Tom. Yes, the inputs in the applet are a bit rough. Joysticks will be nice! ....reminded me of an old arcade game that has 2 joysticks, with which you control your robot to fight others. Fun!
After learning "differential steering" (phew!), I start making some tests of Braitenberg's Vehicles...
« Last Edit: Jun 6th, 2004, 2:14pm by william »  
Pages: 1 

« Previous topic | Next topic »