View unanswered posts | View active topics It is currently Fri Jul 25, 2014 5:06 am






Reply to topic  [ 5 posts ] 
Compass sensor modes? 
Author Message
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post 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?

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Tue Oct 21, 2008 7:32 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 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


Wed Oct 22, 2008 6:39 am
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post 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;
}

_________________
Jeff McBride
Benson Robotics Club


Wed Oct 22, 2008 9:49 am
Profile
Novice

Joined: Mon Oct 13, 2008 6:29 pm
Posts: 75
Location: Florida, USA
Post 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?

_________________
PHUHS Robotics
Team 516 FTW

Daytona Robofest Winning Alliance Captain
Daytona Robofest Inspire Award


Wed Oct 22, 2008 7:54 pm
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post 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.

}

_________________
Jeff McBride
Benson Robotics Club


Wed Oct 22, 2008 8:43 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.