|
Re: 2008 Omni Drive Code Help
First uses this:
pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);
They Add 2000 to prevent a negative value and when they call LIMIT_MIX ()
It evaluates the result and subtract out the 2000. I think your code could be changed to
motor_fl_1 = Limit_Mix(2000 + drive_ly + drive_lx - 127);
motor_fr_1 = Limit_Mix(2000 + 127 - drive_ly + drive_lx);
motor_br_1 = Limit_Mix(2000 + 382 - drive_ly - drive_lx);
motor_bl_1 = Limit_Mix(2000+ 127 + drive_ly - drive_lx);
if ( (motor_fl_1 < 137) && ( motor_fl_1 > 117 ) )
pwm_drive_fl = 127;
else pwm_drive_fl = motor_fl_1;
if ( (motor_fr_1 < 137) && ( motor_fr_1 > 117 ) )
pwm_drive_fr = 127;
else pwm_drive_fr = motor_fr_1;
if ( (motor_br_1 < 137) && ( motor_br_1 > 117 ) )
pwm_drive_br = 127;
else pwm_drive_br = motor_br_1;
if ( (motor_bl_1 < 137) && ( motor_bl_1 > 117 ) )
pwm_drive_bl = 127;
else pwm_drive_bl = motor_bl_1;
This should prevent any over runs even if your joystick is doing something weird. Are you using a chicket?
Although I must admit I don't understand the "382 - drive_ly - drive_lx" but I'll assume you know the formula to be correct and that the problem you're having is from a violation in a positive integer math problem.
Hope that helps
Steve
|