![]() |
programming problem
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 |
255 - (x-axis)
|
I think you better use 254 - x instead.
|
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
|
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. |
We use some robot reversal code:
Code:
'-------------------------------------------------------------------------- |
impressive
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
|
Quote:
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 |
Here's the REALLY easy solution
Reverse the wires from the speed controller to the motor. Problem solved!
|
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 :) |
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 :)
|
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....
|
Quote:
Swap: put 0, PWM1 PWM1 = PWM2 get 0, PWM2 Inverse: PWM1 = ~PWM1 PWM2 = ~PWM2 |
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 |
Quote:
|
| All times are GMT -5. The time now is 04:00. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi