We at MARS have our own acceleration code, written by your's truly. It's very simple, and it didn't take too long to type up. We use different acceleration rates for autonomous mode and human control. Here it is:
Code:
//these two variables are declared at the top of user_routines_fast.c
int AUTON_RATE_LIMIT = 1;//wheels accelerate at about 40 per sec (3 secs to max)
int RATE_LIMIT = 5; //faster accel. during manual control
//The function was added in at the bottom of the file.
//Make sure to make a prototype for this in user_routines.h!!
/*******************************************************************************
* FUNCTION NAME: Motor_Accel
* PURPOSE: Motors accelerate at certain rate (prevents wearing of transmission)
* CALLED FROM: user_routines_fast.c
* ARGUMENTS:
* Argument Type IO Description
* -------- ---- -- -----------
* pwm_out int O Value being sent to pwm
* pwm_in int I Pwm that value is being sent to
* RETURNS: int
*******************************************************************************/
int Motor_Accel(int pwm_out, int pwm_in)
{
if (autonomous_mode) //while autonomous is running...
{
printf("Motor_Accel running...\r\n");
if (pwm_out > (pwm_in + AUTON_RATE_LIMIT)) //If the input is more than your pwm, + 1...
return (pwm_in + AUTON_RATE_LIMIT); //Make it your pwm, + 1
else if (pwm_out < (pwm_in - AUTON_RATE_LIMIT)) //If it is less than your pwm, - 1...
return (pwm_in - AUTON_RATE_LIMIT); //Make it your pwm, - 1
else //And if it is within 1 either way (or the same)...
return pwm_out; //Send it as is
} //end autonomous acceleration code
else //While under human control
{
if (pwm_out > (pwm_in + RATE_LIMIT)) //If the input is more than your pwm, + 5...
return (pwm_in + RATE_LIMIT); //Make it your pwm, + 5
else if (pwm_out < (pwm_in - RATE_LIMIT)) //If it is less than your pwm, - 5...
return (pwm_in - RATE_LIMIT); //Make it your pwm, - 5
else //If it is within 5 either way...
return pwm_out; //Send it as is
} //end human control acceleration code
} //end Motor_Accel
And there it is! As I said, very simple. The only complication is having to put the pwm name in twice...
Code:
pwm03 = Motor_Accel(p1_y, pwm03);
EDIT: I forgot to mention, this isn't final. We're still taking a look at exactly how it will work. We know it works, but we don't know how
well it works...
EDIT (#2): Turning seems to be a problem, since the acceleration rates make it hard to shift from one side of 127 to the other...