robotics - Compass: from 359 to 0 degrees

I am trying to move a robot using a compass. We use the compass to make the robot move in straight line, it uses 2 wheels and they move a bit different.So we set a value between 0 and 359 as direction, and then check the current direction, calculate the error and fix it. Like error = current_direction - actual direction.The problem is that if for example our init direction is 90 degrees and our robot is at 45, the error will be 45 and it will fix it. If it is 0, the error will be 90 and it will fix it. The problem is that if it moves a bit more...Read more