View Single Post
  #1   Spotlight this post!  
Unread 05-02-2007, 10:19
Mark_Benedict Mark_Benedict is offline
Registered User
FRC #0612
 
Join Date: Jan 2007
Location: Northern VA
Posts: 3
Mark_Benedict will become famous soon enoughMark_Benedict will become famous soon enough
Exclamation Save the Gearbox, Save the Game

Chantilly Academy Robotics Team 612 has developed code that slows the wear on the kit-of-parts planetary gearbox.

The code gradually changes the speed based on the joystick value.

NOTE: in this code, pwm01 is the left side, pwm02 is the right. This also assumes that you are using 2 joystick drive, with the left joystick Port 1 on the Operator Interface, and with the right joystick on Port 2 on the Operator Interface.

Here it is:

/***** Put these lines of code into user_routines.c at the top *****/
#define aRate 3 //This is the rate at which the motor speeds up
#define dRate 8 //This is the rate at which the motor slows down
void accelR(int); //method explained below
void accelL(int); //method explained below


/***** This goes with the above
*FUNCTION NAME: accelL
*PURPOSE: to gradually increase or decrease motor output on pwm01
*CALLED FROM: user_routines.c
*ARGUMENTS: num, the input target value for the motor output
*RETURNS: void
*****/
void accelL(int num)
{
static int leftMotorTemp = 127;
if(pwm01 >= 127)
{
if(num > leftMotorTemp)
leftMotorTemp += aRate;
else if(num < leftMotorTemp)
leftMotorTemp -= dRate;
}
else if(pwm01 < 127)
{
if(num > leftMotorTemp)
leftMotorTemp += dRate;
else if(num < leftMotorTemp)
leftMotorTemp -= aRate;
}
if(leftMotorTemp > 255)
leftMotorTemp = 255;
else if(leftMotorTemp < 0)
leftMotorTemp = 0;

pwm01 = leftMotorTemp;
}


/***** This goes with the above
*FUNCTION NAME: accelR
*PURPOSE: to gradually increase or decrease motor output on pwm02
*CALLED FROM: user_routines.c
*ARGUMENTS: num, the input target value for the motor output
*RETURNS: void
*****/
void accelR(int num)
{
static int rightMotorTemp = 127;
if(pwm02 >= 127)
{
if(num > rightMotorTemp)
rightMotorTemp += aRate;
else if(num < rightMotorTemp)
rightMotorTemp -= dRate;
}
else if(pwm02 < 127)
{
if(num > rightMotorTemp)
rightMotorTemp += dRate;
else if(num < rightMotorTemp)
rightMotorTemp -= aRate;
}
if(rightMotorTemp > 255)
rightMotorTemp = 255;
else if(rightMotorTemp < 0)
rightMotorTemp = 0;

pwm02 = rightMotorTemp;
}


/***** Put this into Process_Data_From_Master_uP
accelL(p1_y); Changes left side based on left joystick y-value
accelR(p2_y); Changes right side bases on right joystick y-value

//End of code


What this code does is gradually change the speed. This will do several things:
  • Make driving easier by decreasing sensitivity
  • Prevent circuit breaker pops
  • Decrease gearbox wear
  • Prevent or slow chain and/or belt wear

Our driver really likes the code, so we will keep it after FIRST sends out the fix.

Sorry about the edit. We have several versions of the same code floating around.

Last edited by Mark_Benedict : 05-02-2007 at 14:00. Reason: version control mess-up