I'm currently programming an autonomous robot in java and here is my problem;
I want to know the orientation of my robot at all time, considering there is only 4 possible orientations:
Up / Down / Left / Right
I define each of these positions with the following numbers:
Up and Down = 0 , Left = 1 , Right = -1
So say my robot is currently oriented "0" (say up), and I turn 90 degrees on the right then the value should change to 1. If I rotate 90 degrees on the right again it will change back to 0.
So we have the following sequence: 0 , -1 , 0 , 1 (we can start at any point).
Basically my robot will encounter different types of obstacles. Everytime he meets one he will either turn right or left. I want him to always try to turn in the "up" direction. if the robot turns while being on a "0" position it doesn't matter because it doesn't affect the Y position (if we consider a X-Y axis). But if he is on a 1 or -1 position then he will have to turn 90° * 1 or 90° * (-1).
I'm struggling with finding how to change properly my CURRENT value depending on how many "quadrants" on the right (or left) the robot is rotating. I thought of exponents of (-1) but I couldn't figure out how.
Can you please help me with that?
Thank you!
P.S. I know I could just check the value with if conditions but there are lots of different classes and I use many times the method to rotate, so it needs to be as short and simple as possible.