# Drive Equations

How many of you are remapping your drive equations from what they are in the default code? If so, how?
An example of a remapping would be to make the joystick less sensitive around 127 and more sensitive farther out. This can enhance control.

We simply broke the joystick transfer function into two piecewise functions - one for the first 50% of joystick movement, and one for the other half. The first half is less sensistive, allowing finer control, while the second is more sensitive, letting you throw the robot into full speed quickly.

Parobolic, with the two parts cut out, using a lookuptable created with a small C program, so that we don’t have to do any sin calculating on the CPU.

How would you go about making that table? Becase I would like to do something like this with our robot.

rom unsigned char joystick_transfer[254] = {0, 1, 2…254};

pwm01 = joystick_transfer[p1_y];

For example, my smoothed out motor curve looks as shown in the image at the bottom of this post.

If you’re wondering what equation I used: it is as follows, in Java syntax (in the C code, I just have a lookup table):

(i is the joystick input)

pwm_output * = 127-42.5*(Math.pow (1.010889286,-i+127)-1)+Heaviside (i-127)42.5(Math.pow (1.010889286,-i+127)-1)+Heaviside (i-127)42.5(Math.pow (1.010889286,i-127)-1);

Heaviside (i) is just a fancy term. By definition,

Heaviside (i) = 0 if i < 0
Heaviside (i) = 1 if i >= 0.

Thus, Heaviside (i-127) is 1 if i >= 127 and 0 otherwise.

It allows me to write the whole function in one equation. So really, this is two exponential functions stuck together.

If you want the syntax for the table,

``````rom const int drive_lookup]= {0, 0, 0, 0, 0, 5, 10, 13, 15, 16,
18, 20, 21, 23, 24, 26, 28, 29, 31, 32, 34, 35, 36, 38, 39, 41,
42, 43, 45, 46, 47, 49, 50, 51, 53, 54, 55, 56, 58, 59, 60, 61,
62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 88, 89, 90, 91, 92, 93,
94, 94, 95, 96, 97, 98, 98, 99, 100, 101, 101, 102, 103, 103, 104,
105, 106, 106, 107, 108, 108, 109, 110, 110, 111, 111, 112, 113,
113, 114, 114, 115, 116, 116, 117, 117, 118, 118, 119, 120, 120,
121, 121, 122, 122, 123, 123, 124, 124, 125, 125, 126, 126, 127,
127, 127, 128, 128, 129, 129, 130, 130, 131, 131, 132, 132, 133,
133, 134, 135, 135, 136, 136, 137, 137, 138, 139, 139, 140, 140,
141, 142, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149,
150, 150, 151, 152, 152, 153, 154, 155, 155, 156, 157, 158, 159,
159, 160, 161, 162, 163, 164, 165, 165, 166, 167, 168, 169, 170,
171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 197, 198,
199, 200, 202, 203, 204, 206, 207, 208, 210, 211, 212, 214, 215,
217, 218, 219, 221, 222, 224, 225, 227, 229, 230, 232, 233, 235,
237, 238, 240, 245, 250, 254, 254, 254, 254, 254, 254};
``````

You can plug this right into your program and just say:

``````
pwm01 = drive_lookup [p1_y];
``````

At the endpoints, I chose to replace several of the last terms with an endvalue. Notice how there are several 254 terms at the end and several zeros in the beginning.*

Thanks for the table version, but where exactly do you put this in the program? I’ve tried copying your code into DefaultRoutine() as well as Process_Data_From_Master_uP(), both result in errors. I searched the forums and found a lot of threads about making lookup tables but none about where to acutally put the code.

We have something a lot like this. However, we have only one side of it, and just do 254 - lookTable[value].

Interesting question.

Hovercraft FTW! =)

Paul Dennis

Though we haven’t decided yet which one we want to use on our robot, we have three possible equations for throttling/sensitivity. (This is on a tank-drive system)

First I include this code:
if (Joystick >= 255)
Joystick = 254;
if (Throttle >= 255)
Throttle = 254;

Then I use one of these three equations (these are the pseudocode versions):

1. pwm = ((Joystick - 127) * (Throttle) / 254) + 127

2. pwm = ((Joystick-127)^3 / 16129) + 127

3. pwm = (cuberoot{Joystick-127} * 16129) + 127

In the first one, a joystick with a throttle on it (like the CH Flightstick Pro I have) can be used to adjust the maximum speed in both directions. When the throttle is at zero, the robot can’t move, and when it is at full, the joysticks act normally. At a throttle of 127 (halfway), the joystick can go from 63.5 to 190.5. Besides simply reducing the maximum speeds, this approach also decreases sensitivity when the speed it lower (in other words, you can move more precisely). NOTE: the one throttle controls speed for both tank-drive joysticks.

In the second formula, the equation forms an exponential graph that gets sharper as it moves away from 127. This equation means that the robot will move slowly at first, but gain speed faster and faster.

In the third formula, for which I still have to figure out the coding, the graph is the inverse of that in #2. Speed gains very quickly at first, then more and more slowly.

NOTE: each of these formulas, when in the code, will be included inside a Limit_Mix call in order to prevent exceeding the 0-254 range.