Me being the main programmer on a rookie team and not knowing what to expect, and not programming in over 10 years, I incorporated the following “different” features:
1. Neutral control/Panic button: Before we knew about the v14 fix for the run on condition, I was concerned about the robot running out of control as we had encountered this problem, so I added some code that puts both motors in Neutral by pressing either joystick trigger button. (we have a 2 wheel drive CIM motor system). I left this feature in the code in case in the heat of the moment, the operator needs to stop.
if (p1_sw_trig || p2_sw_trig)
{
pwm01 = pwm02 = 127;
}
2. Scaling factor/ Turbo Mode: I found that our Cim motors run a little faster than we wanted for manueverability at full PWM output levels (0 & 255) so I used a scaling factor that is applied to the each drive wheel joystick Y position and then mapped each joystick wheel to act as a turbo button which would give us burst speed if we needed it. Consequently, we added raised casters in the back of our chassis to keep it from tipping as hitting the turbo button gave it a wicked (but cool looking) lurch like you see in funny cars on the 1/4 mile track…
Incidently, because the turbo mode is set for each drive wheel independently with the thumbwheel on its joystick, some pretty quick and possibly uncontrolled turns can be made.
Also, testing confirmed that if the operator holds down the triggers (neutral and puts both joysticks forward with both the turbo buttons on and then releases the trigger buttons that we could do a “hole shot” and a “wheelie”… well it looks cool anyhow…
The Y axis code (p1_y = (p1_y /speed) + plus_speed; & p1_y = (p2_y /speed) + plus_speed; ) is in there as we originally set this up for single joystick control and it works for that as well so I left the code in there. Here is what my crude code for that looks like:
/******************************** Slower mode **********************************************
- The following code sets all PWMs to default lower speed (dictated by scaling factor *
- (speed) and then to full output level of each joystick when its wheel button is pressed *
- and held *
*******************************************************************************************/
static int speed = 3; /* speed control scaling factor = PWM divided by this number */
static int plus_speed = 80; /* this value is added after speed control scaling factor to center and normalize
the PWM value (if speed = 2 use 64, if speed = 3 use 80, if speed = 4 use 96) */
if (p1_wheel < 60)
{
p1_x = (p1_x /speed) + plus_speed; /* adjust PWM by a factor of speed and add plus_speed to compensate /
p1_y = (p1_y /speed) + plus_speed; / adjust PWM by a factor of speed and add plus_speed to compensate */
}
if (p2_wheel < 60)
{
p2_x = (p2_x /speed) + plus_speed; /* adjust PWM by a factor of speed and add plus_speed to compensate /
p2_y = (p2_y /speed) + plus_speed; / adjust PWM by a factor of speed and add plus_speed to compensate */
}
3. Backlash Prevention: I put a simple normailizing feature on the drive wheel joysticks to center these and to prevent backlash on the motors due to a released joystick. I noticed that when the joystick was released from the forward position that it would kick the motor in reverse momentarily and I was concerned about blowing a fuse from the excessive current draw on this condition. So I added the following code:
/**************************Backlash Adjust ************************************
- This section sets the joystick X & Y zero points if PWM is between 124 & *
- 130 to avoid backlash near zero crossings *
******************************************************************************/
if (p1_x < 130 && p1_x > 124)
{
p1_x = 127; /* normalize X neutral on Joystick */
}
if (p1_y < 130 && p1_y > 124)
{
p1_y = 127; /* normalize Y neutral on Joystick */
}
if (p2_x < 130 && p2_x > 124)
{
p2_x = 127; /* normalize X neutral on Joystick */
}
if (p2_y < 130 && p2_y > 124)
{
p2_y = 127; /* normalize Y neutral on Joystick */
}
- Acceleration ramp up/down: We found that the acceleration was too quick so we added the following simple ramp up code:
/************************** Ramp up Routines ************************************
- This section ramps the joystick X & Y PWM levels for smooth transistions of *
- acceleration or deceleration *
********************************************************************************/
#define ramp_speed 3
if(pwm01 > (p1_y+ramp_speed))
{
pwm01 += ramp_speed;
}
else if (pwm01 < (p1_y-ramp_speed))
{
pwm01 -= ramp_speed;
}
else
{
pwm01 = p1_y;
}
if(pwm02 > (p2_y+ramp_speed))
{
pwm02 += ramp_speed;
}
else if (pwm02 < (p2_y-ramp_speed))
{
pwm02 -= ramp_speed;
}
else
{
pwm02 = p2_y;
}
5. Motor Bias Adjustment: Also, I found that the motor bias was different with the two CIM motors especially since one was turned 180 degrees from the other wheel that the robot would track to one side with both drive wheel joysticks in the same position. I added corrections to these but as the motors heat up I couldn’t count on this being a constant value so I incorporated a dummy plug to add a correction only if the dummy plug is installed. The code looks like this:
/* ------------ correct for motor speed if rc_04 is low */
if ((p1_y < 255) && (rc_dig_in03 == 0))
{
pwm01 = pwm01 + 2;
}
if ((p1_y > 2) && (rc_dig_in03 == 0))
{
pwm01 = pwm01 - 2;
}
**6. Troubleshooting aid: **When trouble shooting my robot’s motors and controls, I had a hard time seeing some of the joystick values in dashboard viewer so I mapped these to un0used PWM outputs so I could see what was going on which made it easier to figure this out…
pwm11 = p3_wheel; /* show us the value of p3_wheel on dash board viewer as pwm11 /
pwm09 = rc_dig_in02; / show us the value of rc_dig_in02 on dash board viewer as pwm09 /
pwm08 = rc_dig_in01; / show us the value of rc_dig_in01 on dash board viewer as pwm08 */
Sorry to be so long winded but being a rookie and not programming in quite a while I am sure that my code looks a little crude to most of you professionals out there but it does work for what it was intended.
Some of these ideas that I used, I am sure you pros have figured out better methods for or used something similar and I am hoping that you share those ideas with me…
I just wanted to share a few of my ideas with you all…
Good luck to all in your competition!