Our robot is using a four wheel, four motor omni drive system. Our code gives good output except for sometimes it swaps outputs. Instead of giving a 250, it gives a 4.
drive_ly and drive_lx are our drive joystick.
motor_fl_1 and all the others are the variables we send to the motors. fl=front left.
pwm_drive_fl are the actual motors.
Heres the code:
Code:
if ( (drive_ly + drive_lx - 127) > 254 )
motor_fl_1 = 254;
else if ( ( drive_ly + drive_lx - 127) < 0 )
motor_fl_1 = 0;
else motor_fl_1 = drive_ly + drive_lx - 127;
if ( ( 127 - drive_ly + drive_lx ) > 254 )
motor_fr_1 = 254;
else if ( ( 127 - drive_ly + drive_lx ) < 0 )
motor_fr_1 = 0;
else motor_fr_1 = 127 - drive_ly + drive_lx;
if ( ( 382 - drive_ly - drive_lx ) > 254 )
motor_br_1 = 254;
else if ( ( 382 - drive_ly - drive_lx ) < 0 )
motor_br_1 = 0;
else motor_br_1 = 382 - drive_ly - drive_lx;
if ( ( 127 + drive_ly - drive_lx ) > 254 )
motor_bl_1 = 254;
else if ( ( 127 + drive_ly - drive_lx ) < 0 )
motor_bl_1 = 0;
else motor_bl_1 = 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;
we're pretty sure its an overflow error, but this code should make up for that.
can anybody help please?