I dont want my gyroscope to show - degree like if it is in 0 when I do -90 it should go to 270 not -90 degree,How can I do it?
My team had a similar issue but all Iâll say is try using YAW
Math is your friend MOD((ABS(360+sensor_value)),360) will do what you want. Programming language of your choice.
Edited to add: While displaying this may make sense (ie 270 vs -90) from an internal programming the robot having degrees from âNorthâ makes some programming easier since you can use < or > zero to know which way itâs going/drifting and make the comparable change.
In VEXCode Blocks just use the heading of the gyro.
Trust me, you will have a lot less strange behavior if you work with - 90 instead of 270 degrees.
But if u wanna u can just check if itâs less than 0 and add 360, or check if itâs above 360 and subtract 360
We are using c++ and it gives
use of uncleared identifier âMODâ
What should we do ?
Use headings since their domain is [0, 360).
The % operator is the mod operator
Display = (360 + gyroscope-value) % 360;
You shouldnât need the â360+â, or do you???
Display = gyroscope-value % 360;
Itâs an artifact from prior sensors that would return more than 360 degrees so thatâs why the mod is there. The 360+value converts -90 to 270, which was the original request
I should have made the variable gyroscope_value to make sure people donât know there is a subtraction.
There just isnât a difference if you add the 360âŚ
degrees | degrees mod 360 | (degrees+360) mod 360 |
---|---|---|
-72 | 288 | 288 |
-29 | 331 | 331 |
14 | 14 | 14 |
57 | 57 | 57 |
100 | 100 | 100 |
143 | 143 | 143 |
186 | 186 | 186 |
229 | 229 | 229 |
272 | 272 | 272 |
315 | 315 | 315 |
358 | 358 | 358 |
401 | 41 | 41 |
444 | 84 | 84 |
487 | 127 | 127 |
530 | 170 | 170 |
So lets go back. I got asked a question how to go from -90 to 270 and I did the 360-degree. Then my brain went "what if they give number greater than 360, and the mod was added.
You are correct, for this system you wonât need the âaddâ. Others may.