Go Down

### Topic: Direction algorithm needed. (Read 4120 times)previous topic - next topic

#### warren631

##### Nov 08, 2013, 09:20 pm
I have two wheels on my robot, left and right.  I send speed signals (spdL and spdR) in the range -100 to +100 for full speed reverse to full speed forward for each wheel.
How do I derive a direction variable (dir) from these two speeds such that -100 means the robot is  turning fully left  (or rotating anticlockwise )( spdL = -100, spdR= +100 ) and  +100 means turning fully right (or rotating clockwise) (spdL= +100, spdR= -100) and zero (spdL=spdR) means the robot is going straight ?

I have tried:
1.  dir = (spdL - spdR)/2 - does not work
2. dir = (spdL/spdR) * 100 - does not work
3. dir = ((spdL / spdR) - 1) * 100 - does not work

My mind has gone foggy, any suggestions?

#1
##### Nov 08, 2013, 09:35 pm
Tricky.

How to account for something that could be achieved multiple ways?

50R + 50L = 100combined, yet so does 25 + 75, or 0 + 100.

Maybe move the ranges out so that the combination can not be in either range.
Say -200 to -101 and 0 for off for one, and 0 for off and 101 to 200 for the other.
When added, anything from -100 to +100 is the result of both motors moving.
To reach -101 to -200, only left can be on.
To 101 to 200, only right can be on.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### warren631

#2
##### Nov 08, 2013, 10:16 pm
I don't think direction is the addition of  the motor speeds because, as you say, 100+0 = 0+100.   Is direction a ratio between L and R motors?  Or is direction the difference between L and R speeds?

#### warren631

#3
##### Nov 09, 2013, 12:09 amLast Edit: Nov 09, 2013, 12:14 am by warren631 Reason: 1
The 'logic list' is (not including the in-between values):

spdL   spdR   dir
0          0           0
100          0         50
100     100           0
100         -100     100
-100       -100     0
-100      0        -50
-100     100     -100
0           100           -50
0          -100   50
50           50          0
0             50          -50
50            0             50
50          -50          100
-50          50        -100
-50           0           -50
3                3             0
3                0             50
3               -3             100
0               3              -50
-3              3             -100

So whats the algorithm?  dir = spdL...... something ......spdR.....something?
if spdL = spdR then dir = 0  (straight)
if spdL < spdR then dir < 0   (turning left)
if spdL > spdR then dir > 0   (turning right)

#### warren631

#4
##### Nov 09, 2013, 12:23 amLast Edit: Nov 09, 2013, 12:28 am by warren631 Reason: 1
Got it (I think):

direction = ( (spdL - spdR)/(spdL+spdR))*100

.....or maybe not......

#### RbSCR

#5
##### Nov 09, 2013, 12:06 pm
Leftspeed and rightspeed alone won't give you the direction of the robot.
You also need to incorporate the wheelbase in the algorithm.

Have a look at http://rossum.sourceforge.net/papers/DiffSteer/DiffSteer.html

#### oric_dan

#6
##### Nov 09, 2013, 07:05 pmLast Edit: Nov 09, 2013, 09:36 pm by oric_dan Reason: 1
Yeah, speed alone does not give direction. Think about it. If one motor were turning some amount faster than the other, the robot trajectory would be a spiral or circle, with direction constantly changing. To go in a specific direction, you turn at some speed for a certain amount of time, then you straighten the steering wheel, and go straight after that. Etc.

#### Dwacito

#7
##### Nov 10, 2013, 07:57 amLast Edit: Nov 10, 2013, 08:04 am by Dwacito Reason: 1
I think your problem is "ill-posed".  There are two things: the turn radius, and the rotation speed.

For example in your "truth table", you say (100, 0) = 50 but also (50,0) = 50. You get the same output value because the robot is turning around the same point (same turn radius)but at different speeds.

Bu you also say (-50, o) = -50 and (0,50) = -50, which is: same rotation speed, but turning around different points.

So you need to define exactly what you want to measure. Rotation speed or centre of rotation?

Look at this picture: (seen from above)

L is left wheel, its linear speed is V_L(your spdL), right wheel R speed V_R. L is distance between wheels.

Turn radius is r (robot does a circle around O) and angular speed is theta (look at formulas above).

If you want the turn radius, it will go to infinity if robot is going straight, if robot is spinning on itself you get 0 (i.e. O = C, the robot turns around the cente of the wheels) etc.

If you want rotation speed you'll get it in rad/sec. To map from -100 to 100 you need to figure out the max turn speed your robot can do and normalize to this.

In the end you need to really think about what you want to measure. You can't have a single variable giving you turn radius and rotation speed at the same time.

Hope that helps!

Go Up