|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Inverting Axis
Hello, I am trying to find a way for when our driver starts reversing with our mecanum drive robot, the rotation axis gets inverted.
|
|
#2
|
|||
|
|||
|
Re: Inverting Axis
Show us what you have first so we can suggest different approaches on how you can accomplish it.
|
|
#3
|
|||||
|
|||||
|
Re: Inverting Axis
I'd suggest multiplying the axis you want to invert by -1. Example code:
Code:
if (reversing) { //Put whatever code you use to detect if you're reversing here
myMotor.set(joystick.getYAxis() * -1); //Set a motor to the inverse of the Y axis.
}
|
|
#4
|
|||||
|
|||||
|
Re: Inverting Axis
Quote:
Code:
if (reversing) { //Put whatever code you use to detect if you're reversing here
myMotor.set(-joystick.getYAxis()); //Set a motor to the inverse of the Y axis.
}
|
|
#5
|
||||
|
||||
|
Re: Inverting Axis
Quote:
|
|
#6
|
|||||
|
|||||
|
Re: Inverting Axis
Quote:
Last edited by GeeTwo : 02-02-2015 at 11:56. Reason: fix quote tag |
|
#7
|
||||
|
||||
|
Re: Inverting Axis
Quote:
|
|
#8
|
|||||
|
|||||
|
Re: Inverting Axis
Quote:
It is however better practice to place the - in front of the variable instead of multiplying by -1. |
|
#9
|
||||
|
||||
|
Re: Inverting Axis
Quote:
1for aesthetic reasons and to discourage the compiler from generating a floating-point multiply |
|
#10
|
|||||
|
|||||
|
Re: Inverting Axis
Quote:
I do not know of any source that explicitly states it, and I haven't found one in a quick Google search. It's just the way I learned and it is the way I do it at work. |
|
#11
|
|||||
|
|||||
|
Re: Inverting Axis
Quote:
OBTW, you pass the Turing test. |
|
#12
|
||||
|
||||
|
Re: Inverting Axis
Quote:
|
|
#13
|
|||||
|
|||||
|
Re: Inverting Axis
I did a bit of Googling, and it does seem that several optimizers will generate the same code for both cases. Optimizers appear to have come a ways since I last paid close attention.
It still makes sense to me to ask for -x (or 0-x) rather than -1 * x. Provided that the code is equally (or arguably better) readable by people, why not give the computer the simplest directions? |
|
#14
|
||||
|
||||
|
Re: Inverting Axis
Nobody is arguing otherwise.
Quote:
That's why I asked if this (very reasonable, in my opinion) use of the unary operator in this case might be part of a widely-accepted Java coding standard that could be referenced in support of the recommendation. |
|
#15
|
|||||
|
|||||
|
Re: Inverting Axis
Quote:
Logically, you want to do a conditional: if (c is between a and b, and you don't know whether a is larger or smaller than b) then... Human simpler (use this!): if ((a<b) && (b<c) || (a>b) && (b>c)) then.. Probably machine quicker, but don't use: if ((a-b)*(b-c) > 0) then.. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|