Home > RobotC Code > Robot Angle Functions

Robot Angle Functions

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: , , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: