switching joystick axis?????

Please tell me if this is possible:

ok lets say my robot is 4 wheel drive and uses on joystick to drive the two motors. Ok now when you push the joystick forward both motors will go forward, and when you turn each motor turns in the opposite direction and so on and so forth. ok so now we have a joystick that operates the drivetrain. Lets say I want to reverse the joystick so that when you push it forward it will accually drive in the other direction. Is it possible to do this with a switch??? In other words I want the robot to have 2 ends. This is because it is sometime difficult to drive the robot backwards with the joystick pulled backwards if yah know what I mean!

Please respond if yah can tell me any information about this!!! or if you dont understand what i mean!:confused: :confused: :confused: :confused: :confused:

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

Or you could say “The opposite side of the robot goes the same direction as the joystick”,

and fore and aft (joystick) are still the same relative to the robot’s fore and aft.

We have incorporated that same thing into our robot for this year. The drivers from last year found a few times last year that they rotated around and now stick up caused the robot to be coming to them and the steering was reversed. We put a button on the custom box that says orientation reverse and now the front is the back and it is easier for them to control (so they say). Not much programming but if it helps them drive, well worth it.

Now we have to highlight both ends of the robot to give them an idea of which side is which in relation to the switch. Hmmm

Matt

I just tossed together this program now so it may not work… one of the veteran teams please check me… From what I understand your looking to push the joystick and have the robot go one way, then flip a switch, push the joystick in the same direction and have the robot reverse course. If this is what you meant then this code should work… Any questions just leme know, but remember this is untested…

'===============Reversed Drive Program =====================
if backdrive = 0 then frontdrive 'backdrive is switch name
if p1_y < 127 then yback
p1_y = 127 - ((p1_y - 127) Min 0 Max 127) 'p1_y > 127. takes # above 127 and makes it same distance below
goto xtest 'if previous line used ignore next 2
yback
p1_y = 127 + ((127 - p1_y) Min 0 Max 127) 'p1_y < 127. takes # below 127 it makes variable same distance above
xtest
if p1_x < 127 then xback 'now works on x-axis
p1_x = 127 - ((p1_x - 127) Min 0 Max 127) 'same as p1_y above 127, only with x-axis
goto xydone
xback
p1_x = 127 + ((127 - p1_x) Min 0 Max 127) 'same as p1_y below 127, only with x-axis
xydone:
frontdrive
'===========end of reversable drive==continue with tank drive program===========

This assumes the tank drive program is immediately after it. You need to add a variable in the declaring variable sections, it only needs to be 1 bit and i named it backdrive.
When backdrive is not pressed the robot will drive normal. When it is pressed it will first see if p1_y is above or below 127. It will then find the difference between p1_y and 127 and add or subtract it as appropriate. It then does the same using p1_x.

I will try to talk my programer into testing it! I just wish I had the time to learn how to use STAMP!!! I just came up with this idea because I know how hard it is to drive with the joystick backwards. Will this work so that you can still go backwards on the joystick if you want too?

Bad Brad

P.S thanks for helping me explain what i wanted lol because I just didnt know how to word it right!:rolleyes:

*Originally posted by Joe Johnson *
**Suppose you have a switch called p1_trig.


If p1_trig = 0 then DoNothing
Left_wheels = 254 - (Left_wheels MAX 254)
Right_wheels = 254 - (Right_wheels MAX 254)
DoNothing:
…**

K.I.S.S.

Left_wheels = ~Left_wheels
Right_wheels = ~Right_wheels

Just a simple inverse of the bits. As long as you do that min and max stuff where it is supposed to be done (in the drive calculations), you should be fine.

We used that on our drive system last year. When our team went under the bar, it would actually do it backwards. A simple three position toggle switch is all we needed. Forward is forward, back is backwards, and the center was neutral, which meant that the arm etc. still worked but that drive wheels wouldn’t move. That was useful in troubleshooting in case someone bumped into the joystick.

~Tom Faircihld~

If p1_trig = 0 then DoNothing
Left_wheels = 254 - (Left_wheels MAX 254)
Right_wheels = 254 - (Right_wheels MAX 254)
DoNothing:

The above is probably the simplest way to do it. I tend to drag it out more in my program simply because I like to see the thinking process. However you have to then tell it what right_wheel and left_wheel are. I presume there pwm1 and pwm2 as listed in tankdrive. Make sure to put this just after the tankdrive section.

Left_wheels = ~Left_wheels
Right_wheels = ~Right_wheels

This may work. I’m not exactly sure about negations in pbasic. It could end up attempting to put in a negative… Use it at your own risk.

The code I put in is untested but shows exactly what it does step by step. Its probably not the best but it should work. Just try them 1 at a time and see which one you like. A standard 2 position switch, a button on the joystick, or even the wheel on the joystick can be used to control which way it drives.

If you have specific questions on the pbasic editor you can post them here or feel free to e-mail me. I taught myself how to use it and the basic program commands in under a week so it shouldn’t be that hard to help you if you need.

*Originally posted by Joseph F *
**

This may work. I’m not exactly sure about negations in pbasic. It could end up attempting to put in a negative… Use it at your own risk.
… **

Uhhh… that’s not a negative sign (unary operator). That’s a tilde (inverse operator).

Say you have a value of 0 (binary 00000000). The inverse sign inverses all the bits to 255 (11111111). Simplest way of doing it.

Example: 00010100 = ~11101011

Same concept for toggling relays…
Example:
relay_solenoid var bit
relay_solenoid = 0 'solenoid should be deactivated
relay_solenoid = ~relay_solenoid ’ toggle the solenoid state

This code is simpler than using if-then statements to check the current state of the bit. All you’re doing is altering it.

Suggestion is to read the stamp manual. I did and I learned more than I ever wanted to know about the PBASIC programming language. Just head over to The PBASIC programming manual and check it out. Be careful, it’s 2 mb.