ROBOTC.net forums
http://www.robotc.net/forums/

Compass sensor modes?
http://www.robotc.net/forums/viewtopic.php?f=52&t=840
Page 1 of 1

Author:  Atlantisbase [ Tue Oct 21, 2008 7:32 pm ]
Post subject:  Compass sensor modes?

I know that based on the documentation provided with the compass sensor that it has both a absolute heading mode and a relative heading mode. Is there a way to access these modes from with in C?

Author:  Dick Swan [ Wed Oct 22, 2008 6:39 am ]
Post subject:  Re: Compass sensor modes?

The actual compass hardware only supports an "asbolute" heading mode which has the range 0 to 360.

You can "create" your own relative heading by remembering the heading at the start of your program and then subtracting it from the current absolute heading. You'll need to do a simple adjustment if you want to avoid negative numbers. I suspect this is done in the "NXT-G" blocks

Author:  Jeff McBride [ Wed Oct 22, 2008 9:49 am ]
Post subject:  Re: Compass sensor modes?

You might find this function helpful:

Code:
//////////////////////////////////////////////////////////////////////////
// AddHeading
//
// Takes a compass heading from 0 to 359 and an angle from -359 to 359.
// Adds the angle to the compass heading and returns a new heading
// from 0 to 359.
//
// ToDo: Add error checking for the heading out of range < 0 or > 359.
// ToDo: Add error checking for the angle out of range < -359 or > 359.
//       Or modulo the angle with 360.
//////////////////////////////////////////////////////////////////////////
int addheading(int startHeading, int changeAngle)
{
   int targetHeading = startHeading + changeAngle;

   if (targetHeading < 0)
       targetHeading += 360;
   else if (targetHeading >= 360)
       targetHeading -= 360;

   return targetHeading;
}

Author:  10nisman94 [ Wed Oct 22, 2008 7:54 pm ]
Post subject:  Re: Compass sensor modes?

is there a way to have a program remember a heading by say setting a constant at the beginning of a match, and using that constant as the benchmark for your code?

Author:  Jeff McBride [ Wed Oct 22, 2008 8:43 pm ]
Post subject:  Re: Compass sensor modes?

10nisman94 wrote:
is there a way to have a program remember a heading by say setting a constant at the beginning of a match, and using that constant as the benchmark for your code?


Yes. just use a global variable. For example:

Code:
int headingAtStartOfMatch;   // Compass heading we were facing at the start of the match

task main()
{
    headingAtStartOfMatch = sensor[compassSensor];

    // rest of your code goes here.

}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/