# Ramping Motors

In autonomous mode, moving your robot at a slower speed will result in more precise control, since your wheels don't jerk around as much while stopping/starting.
If you want speed as well as precision, you should ramp up/down your motors to full speed. For example:

When starting, use something like:

void rampUp(int curPwr, int maxPwr, int ms)
{
int res = 10;
for(int t = 0; t < ms; t += res)
{
int pwr = curPwr + t*(maxPwr - curPwr)/ms;
//set motors to pwr
wait1Ms(res);
}
}

which allows you to gradually ramp up your motors to a given speed within a given time.

Ramping down in a time span is similar, but more commonly you will want to ramp down to stop at a specific encoder value, which is more complicated (pseudo-code at times):

void travelToRampedHalt(int maxPwr, int distTotal, int rampDist)
{
//zero encoders
int minPwr = 50; //this should be the minimum power level required for reliable forward motion
//set motors to maxPwr

while(encoders < distTotal - rampDist) { } //go forward at full speed until it's time to ramp down

while(encoders < distTotal) //ramp down time
{
int pwr = maxPwr - (maxPwr - minPwr)*(encoderVal - distTotal + rampDist)/rampDist; //this scales the power from max->minPwr over the rampDist
//set motors to pwr
}
//set motors to zero
}

The above function will travel at maxPwr until within rampDist of the destination, at which point it will ramp down and stop.

Turning wastes so little time that's it's probably better to just turn at a slower speed instead of bothering with ramping.