|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
2008 Omni Drive Code Help
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;
can anybody help please? |
|
#2
|
|||||
|
|||||
|
Re: 2008 Omni Drive Code Help
Anytime you add two chars together you risk overflow. Try making all your variables ints. Overflow is still possible, but only when you're working with numbers a lot larger than joystick and motor values.
|
|
#3
|
||||
|
||||
|
Re: 2008 Omni Drive Code Help
yea that was our first idea too.
we made everything signed ints in order to avoid this issue. but somehow when we tried to limit mix them into the 0-254 range, the limit mix failed or something. but no matter what happened it still didnt work. could it be that we never casted them back into unsigned chars before assigning them to the pwm? because when i tried that we got pure 254 for all four outputs. thanks for the help by the way. much appreciated. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
Re: 2008 Omni Drive Code Help
thanks for that code. and yes we are using a chicklet to enable us to use an xbox 360 controller. does that make a difference?
and we tried using the default limit mixes, they cased the same problem, which is why i wrote my own up in that code. we suspected that somewhere there was a datatype conversion that messed us up, so we tried to eliminate all of them. Last edited by Vasily Zaitsev : 26-01-2008 at 22:59. Reason: added content |
|
#6
|
|||
|
|||
|
Re: 2008 Omni Drive Code Help
Chicklet can give weird outputs if the calibration is off or if the battery goes low.
I had that problem once and have made sure the battery we use is fully charged whenever we use it. Try using one of the joysticks as a test to see if the problem occurred in the code or just when the Chicklet and Xbox controller is being used. Since you are having the problem occur with default code and the Chicklet/Xbox, that's almost certainly the problem. Default is pretty solid. If the numbers are inverting in default code with that 250 to 4 flip, it's probably happening because the system is getting that information in to begin with. Good luck Steve |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help in Kevin's 2008 default code | robotrobot2 | Programming | 5 | 20-01-2008 14:36 |
| Lego Omni Drive | Synergy1848 | Robot Showcase | 19 | 03-01-2007 11:51 |
| pic: vex omni drive | 1902_Battery_SGT | FIRST Tech Challenge | 6 | 28-05-2006 17:55 |
| omni drive vs tank | |20807 61|2|_ | Technical Discussion | 49 | 17-01-2006 13:54 |
| Omni-drive autonomous questions | Andrew Schuetze | Programming | 6 | 17-01-2006 12:15 |