Skip to content

Commit

Permalink
Account for implementation of modulo
Browse files Browse the repository at this point in the history
In C++, the % operator, which is normally the modulo operator, is
actually implemented as a division remainder function, which is subtly
different.
In mathematics, both functions would return the same thing, i.e. the
remainder of the division of two numbers. However, while the remainder
in modular arithmetic is always (taken as) positive, the remainder in
division can be negative if either the dividend or divisor is negative.

Since there is currently no scenario in which physicalAngle should
naturally become negative, the solution chosen has been to add 270
degrees to physicalAngle, instead of subtracting 90 degrees (due to the
rotation of the simulator).
  • Loading branch information
cgmc committed Apr 19, 2016
1 parent 91c8aa7 commit f7dbe3e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion source/mega/simulator/simulator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void respond(scanResponse scanResp) {
}

void respond(compassCommand* com) {
SPI_Wrapper::sendCompassResponse(com->uniqueID, ((physicalAngle - 90) % 360), true);
SPI_Wrapper::sendCompassResponse(com->uniqueID, ((physicalAngle + 270) % 360), true);
}

void moveRobot(moveCommand* com) {
Expand Down

0 comments on commit f7dbe3e

Please sign in to comment.