# Ramp Up Drivetrain Motors

Hey guys,

Got a question: In a past competition last year, we had issues with our drivetrain. We slightly geared out our drivetrain (obviously to a rate too high with the weight of our robot)- so basically I believe we were tripping our motors when our driver would immediately shove the joysticks to full force during teleop. We’ve learned from this and have made changes, but one of the suggestions was to control the ramping speed of the joystick value. (i.e. if the driver were to push it from 0-127 very quickly- it would slowly ramp it up). Does anyone do this specifically for their drivetrain? We’re doing a similar process for our flywheel- however that is a constant speed, not controlled directly by a joystick. If anyone does do this, I’d be interested in seeing some code/pseudocode. I don’t find it necessary with a 1-to-1 gearing, however- I’m interested in seeing how it is possible. Hope this question makes sense…

Thanks! Happy Thanksgiving!

Steve

what you do is store your value from the joystick to a variable, lets call it Power.

then you run this in a loop or task

and at then end of every loop you have a second variable called, LastPower

and at the end of the loop you say

lastPower = power;

ok now a third variable, the difference between power and last power, lets call it DeltaPower

so DeltaPower = LastPower - Power;

then we say, if deltapower > 10 ( or whatever you want) deltaPower = 10;

then we add delta power to last power
so
Power = lastPower + DeltaPower;
and the send power to the motors
this means that your motor power cannot change by more than 10 units per loop, and you can change that number to make them ramp up slower or faster, so some pseudo code

int power
int lastPower
Int DeltaPower
int MaxChange = 10;
While(true){
Power = Joystick
DeltaPower = (LastPower - Power);
if(DeltaPowe > MaxChange){
DeltaPower = MaxChange;
}
Power = LastPower + DeltaPower;
Motor[Drive] = power
LastPower = Power;
wait1Msec(20);
}

1 Like

Just so you know, the Smart Motor Library ramps up motors and is very helpful in keeping the motors from burning out. Here is a link to the thread about it:

Smart motor library

I handle this with an array called rampSpeed and a task called acceleration:

``````int rampSpeed[10] = {0,0,0,0,0,0,0,0,0,0};
{
//constants to avoid magic numbers
const unsigned int NUMBER_OF_PORTS = 10;
const int MAX_SPEED = 127;
const int MIN_SPEED = -127;
const unsigned int RAMP_DELAY = 1;

while(true)
{
//loop through all the motors
for(int port=0; port<NUMBER_OF_PORTS; port++)
{
//if the motor is too low, raise it
if(rampSpeed[port] > motor[port])
motor[port] += 1;

//if the motor power is to too high, lower it
else if(rampSpeed[port] < motor[port])
motor[port] -= 1;

//if the motor power is more than the max speed, fix it
if(motor[port] >= MAX_SPEED)
motor[port] = MAX_SPEED;

//if the motor is less than the min speed, fix it
else if(motor[port] <= MIN_SPEED)
motor[port] = MIN_SPEED;
}
//delay to smooth motor ramping
wait1Msec(RAMP_DELAY);
}
``````

Each index in the rampSpeed array represents a motor. Due to how RobotC handles motor naming, you can simply call the motor name as the index of the array. With this task running, send power to the array instead of the actual motor. (ex: rampSpeed[leftDrive1] = 127;).