Log in

View Full Version : programming problem


gthakore
18-02-2002, 16:02
the x-axis have been switched and i want a way to reverse them

basically right now < make the robot go right(>)
and > makes it go (<)

how do i switch it

gaurav email at gthakore@hotmail.com

Mike Soukup
18-02-2002, 17:37
255 - (x-axis)

GreenDice
19-02-2002, 08:11
I think you better use 254 - x instead.

Ian W.
19-02-2002, 08:58
i had this problem with my y-axis, and tried some elaborate solution, but this is much easier. figures, you never think of the easy thing first. oh well, at least the code for the robot is stupidly easy to change. :D

Joe Ross
19-02-2002, 10:40
I think you would be better off with 255 - x max 254, unless you guarantee that x is never greater then 254 before that.

This will help to keep from outputing two 255's in a row which will reset the data packet and cause all kinds of interesting things to happen.

FotoPlasma
12-04-2002, 12:05
We use some robot reversal code:


'--------------------------------------------------------------------------
'| The following code reverses joystick directoin |
'| p1_sw_top[reverse jdriection];pwm1,pwm2[motor speed/direction]
'--------------------------------------------------------------------------
' it'll be confusing as hell
' but oh well
' =)

'How to Swap the Iinformation in Two Variables Without Using a Third Variable!:
'or: XOR is Your Friend =)

if p3_sw_top then forwards:
'---swap right and left pwms
PWM1 = PWM1 ^ PWM2
PWM2 = PWM1 ^ PWM2
PWM1 = PWM1 ^ PWM2
'---invert values of joysticks around 127
'------Thanks to Joe Ross from team 340! :D
PWM1 = ( 254 - PWM1 )
PWM2 = ( 254 - PWM2 )
forwards:


It's not elaborate, or even too important, but I'm really proud of it...

VanWEric
15-04-2002, 10:36
I like the whole xor thing. However, i think it is easiest to just say variable = (!variable). I think that works. If you want to see some really fun manipulation of variables, take a look at one of my previous posts (one line power??). i'll have it bit optimized for next year

Lloyd Burns
17-04-2002, 00:20
Originally posted by Joe Ross
I think you would be better off with 255 - x max 254, unless you guarantee that x is never greater then 254 before that.

This will help to keep from outputing two 255's in a row which will reset the data packet and cause all kinds of interesting things to happen.

The guarantee comes from Innovation First's code which will not allow a reading of a joystick or other pot to become more than 254.

254-x works fine, as shown in this table (in monospaced type font):

x value in :...0........127.........254 (max)
254 - x....: 254........127...........0
255 - x....: 255 ** ...128...........1

jeremy562
18-04-2002, 15:27
Reverse the wires from the speed controller to the motor. Problem solved!

Greg McCoy
18-04-2002, 15:54
Yep, that's the fastest and most efficient way of doing it. Why make your software think more then it has to?

Fast code = good code :)

jeremy562
18-04-2002, 17:37
hehe it would work in a simple situation where you only care about one axis.. but since in this case he also cares about the y-axis it wouldn't be that simple because swapping the motor wires would reverse both axes. He does need to do something in the software.. in this case :)

rbayer
18-04-2002, 17:58
At the beginning of my code, I set up a bunch of aliases for variables. (ie leftDrive VAR PWM1, etc). Then, when I run into a problem like this, I just have to change the aliases and everything else in the code changes automatically. Not easy to do for code that's already written, but something to think about next year....

Jnadke
18-04-2002, 18:17
Originally posted by FotoPlasma
We use some robot reversal code:

It's not elaborate, or even too important, but I'm really proud of it...

Or you can just write it to scratch pad ram...

Swap:
put 0, PWM1
PWM1 = PWM2
get 0, PWM2

Inverse:
PWM1 = ~PWM1
PWM2 = ~PWM2

rbayer
19-04-2002, 10:34
Using 254-x Max 254 is better, but it can still cause errors. For example, if x=255, then 254-x will evaluate to -1, which in PBASIC is approx 65,000. You then take the max and get 255. While this will prevent basic run errors, it can still cause run-time logic problems.

While it's not likely that x will be 255, its still a possibility I don't like leaving. Therefore, I would reccomend the following code:

x=2254-x Min 2000 Max 2254 - 2000

Joe Ross
19-04-2002, 10:46
Originally posted by Lloyd Burns
The guarantee comes from Innovation First's code which will not allow a reading of a joystick or other pot to become more than 254.


Can someone else confirm this, because I can swear that I have seen 255 come from a joystick.

Ian W.
19-04-2002, 12:19
if you got 255 from two joysticks in a row ,your robot would do a "not-happy dance". believe me, sending two 255 variables in the wrong place at the wrong time doesn't work very well. resets the robot, and everything goes crazy. so, no 255 variables from the joystick, ever! :D

ChrisA
20-04-2002, 12:21
heres also the easiest way to swap the x-axis values. just open up your joystick and swap the wires for the x-axis. this wont affect your y-axis in any way and is not that hard to do.

to confirm my buddy mike soukup 255-x does work and is the simplest way our team found to swap the joystick values in the code. we use it in our code right now and it works without any problems whatsoever. we have a pretty cool piece of code based off of this whole equation.