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 ?
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.
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?
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)
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.
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.