![]() |
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.
|
Re: Inverting Axis
Show us what you have first so we can suggest different approaches on how you can accomplish it.
|
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 |
Re: Inverting Axis
Quote:
Code:
if (reversing) { //Put whatever code you use to detect if you're reversing here |
Re: Inverting Axis
Quote:
|
Re: Inverting Axis
Quote:
Quote:
|
Re: Inverting Axis
Quote:
|
Re: Inverting Axis
Quote:
It is however better practice to place the - in front of the variable instead of multiplying by -1. |
Re: Inverting Axis
Quote:
1for aesthetic reasons and to discourage the compiler from generating a floating-point multiply |
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. |
Re: Inverting Axis
Quote:
OBTW, you pass the Turing test. |
Re: Inverting Axis
Quote:
|
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? |
Re: Inverting Axis
Quote:
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. |
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.. |
Re: Inverting Axis
Quote:
I guess neither is simpler. |
Re: Inverting Axis
I swapped b and c between the two. Let's correct the prose. I meant to say that b was between a and c, and you didn't know whether a or c were larger.
|
Re: Inverting Axis
Code:
double strafe = mainStick.getRawAxis(3);This is my code for regular driving for mecanum but I feel that if I inverted the motot not everything else would be the same. |
Re: Inverting Axis
Quote:
Code:
|
| All times are GMT -5. The time now is 13:03. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi