This thread is some testing I did on 269 motor, which is basically the exact same theory in this thread: https://vexforum.com/t/24cs-motor-control-value-remapping/23959/1 But in a different situation – free spinning 269 motor.

So we know that the relationship between the value assigned to a motor, which is the voltage at the port, and the free-spinning velocity of the motor, is positive but not linear. It is a concave up curve with a dead band of approximately ± 15, depending on your mechanics and motor choice.

What Jordan did was 5 second speed calculation for every motor value, which is good, but in my opinion still not precise enough. So, in my tesing, I feel like taking my time and really getting some good data. I did 3 seconds of acceleration plus 20 second interval average speed test, because I do realize that my motor gets fast and slow in every turn. So, all compiled together, starting from 15 to 127, took me about an hour to produce some fine data.

Posting the same stuff I did a few days ago, but in a much much higher resolution, encoder value over 20 seconds and scaled down to RPM:

https://vexforum.com/attachment.php?attachmentid=9338&stc=1&d=1431716357

I tried to do regression before, but excel gives a perfect 5th order regression but does not give me the extremely precise formula for it. All the numbers are rounded up and when it comes to 5th order regression, it’s a big deal and values get pathetically off. Plus, I do not want the cortex to make 5th order calculations with constants with 10 decimal places every loop.

So exactly the same as what Jordan did, I fixed the data in excel, mapped out what I can and estimated&filled in the rest, and here we go. I felt comfortable with the linearized control and it seems to give a lot more freedom to develop skills.

And the final algorithm for free spinning linearization of 296 motor:

```
int LinearizedMotorValue (float target)
{
int estimationArray[114] = {0,15,15,15,16,16,16,16,16,16,17,17,17,18,
18,19,19,19,20,20,21,21,21,22,22,22,23,23,23,23,24,24,25,25,26,26,27,27,28,28,
29,29,30,30,30,31,31,31,32,33,33,34,34,35,35,36,36,37,37,38,38,39,40,40,41,41,
42,42,43,43,44,45,45,46,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
65,66,67,69,70,71,74,76,79,82,84,86,89,94,98,104,111,116,121,124,125,127};
float expected;
if (target == 0)
{
expected = 0;
}
else if (target > 0 && target <= 113)
{
expected = estimationArray[target+1];
}
else if (target < 0 && target >= -113)
{
expected = -estimationArray-target+1];
}
else if (target > 113)
{
expected = 127;
}
else if (target < -113)
{
expected = -127;
}
return expected;
}
```

The max velocity in my test was consistently 113, so a completely linearized joystick control program looks like this:

```
while(true)
{
motor[port2] = LinearizedMotorValue (113*vexRT[Ch3]/127);
wait1Msec(20);
}
```

So, this is it guys. I thought this would be a more general case for people who plan to do testing and programming with free spinning 296 motors, or maybe visualizing the speed reduction of drivetrain motors by comparing your data with this algorithm.

Today was my last day in lab, as I am graduating next week, and I am happy that I did everything I wanted to do as a high school VRC programmer, including this, PID velocity and rerun program. Will talk about the rerun program I did that’s inspired by Ruiqi Mao in another thread.

Excel data file: [https://drive.google.com/file/d/0B0g-KfZY4HIhd2g5amhWNUxRajQ/view?usp=sharing

Codes attached below.

Cheers people,

Martin](https://drive.google.com/file/d/0B0g-KfZY4HIhd2g5amhWNUxRajQ/view?usp=sharing)

pid test.c (18.2 KB)