Archive

Posts Tagged ‘function’

Robot Angle Functions

December 23, 2010 Leave a comment

One more article before I retire for the Christmas holiday.  It is valuable at times to know the normalized degrees of rotation.  I found some cool functions that take any number of degrees and converts them to either 0-359 degrees, or –180 to 179 degrees depending on your needs.

This code uses the MOD operator in RobotC to return the number of degrees left over after dividing by 360.  These are pretty handy functions.

1 // Returns an angle in degrees between 0 and 359 2 int norm_360(int deg) { 4 return deg%360; 5 } 6 7 // Returns an angle in degrees between -180 and 179 8 int norm_180(int deg) { 9 return norm_360(deg + 180)-180; 10 } 11

* Thanks Xander for the reminder about the RobotC mod operator.

Advertisements
Categories: RobotC Code Tags: , , , ,