|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#2
|
||||||
|
||||||
|
This is easily done...
Suppose you have a switch called p1_trig.
Suppose that you have 2 variables called Left_wheels and Right_wheels that are bytes that you output to the appropriate PWM channel to make the wheels go round. Then the following code turns your joysticks around (in a sense) in that what used to make your robot go forward will now make it go backward. Just Prior to the output statement put: . . . If p1_trig = 0 then DoNothing Left_wheels = 254 - (Left_wheels MAX 254) Right_wheels = 254 - (Right_wheels MAX 254) DoNothing: . . . Joe J. P.S. The MAX 254 takes care of the case when you may have (foolishly) set a PWM value to 255. This may cause trouble for the master CPU if you actual DO set a value of a PWM to 255, but that is only a possibility. It is a certainty that a value of 255 will cause the transformation above to make an error if you don't have the MAX 254 bit. Why? Well, thing about it. 255 probably was intended to make the machine go as fast as possible FORWARD. So, in the transformed case you want the robot to go as fast as possible REARWARD. Now, if you stuff in 255 without the MAX 254 stuff, the value of 255 will yield -1 which using the magic of 16 bit unsigned math will transform to 255 -- so... the robot will go Full FORWARD -- not the drive intended because they intended the machine to be going Full REVERSE. I am not sure I made that very clear but it will have to do for now. JJ. P.P.S Don't try using this Left_wheel = 254 - Left_wheel MIN 0 Trust me, this will not yield the desired result. JJ |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how do i control a piston with a joystick | Ryan Foley | Programming | 2 | 27-05-2003 17:13 |
| Fried program slots? | Jeff Waegelin | Programming | 18 | 19-03-2003 18:08 |
| question about one joystick drive programing | james700 | Programming | 13 | 29-01-2003 14:49 |
| robot goes haywire with the one joystick default code | Miles | Programming | 7 | 24-01-2003 14:58 |
| joystick problem | archiver | 2000 | 12 | 23-06-2002 23:08 |