|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools |
Rating:
|
Display Modes |
|
#1
|
|||
|
|||
|
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:
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 |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [wiki]: how to save more than one prog. in the RC | Edourdo | FIRSTwiki | 1 | 04-02-2007 17:29 |
| Save a variable | dawonn | Programming | 7 | 23-04-2005 08:30 |
| SCRRF Save the Regional | Redhead Jokes | Southern California Regional Robotics Forum | 0 | 03-05-2003 14:54 |
| Duel on the Delaware - Save $$$ Now | MOEWidow | Off-Season Events | 11 | 30-04-2003 21:28 |
| Save the rookies!!! Please help us to design a crate... | Eugene | Technical Discussion | 7 | 05-02-2002 20:22 |