View unanswered posts | View active topics It is currently Sat Jan 19, 2019 5:10 pm

 Page 1 of 1 [ 13 posts ]
 Print view Previous topic | Next topic
Help with the Compass Sensor?
Author Message
Rookie

Joined: Tue Nov 18, 2008 5:13 pm
Posts: 9
Help with the Compass Sensor?
Does anyone know how to get the compass sensor to work during the autonomous portion of the program? Everything else works fine: the ultrasonic, the motors, servos, etc.

Fri Nov 21, 2008 3:56 pm
Rookie

Joined: Mon Nov 10, 2008 8:54 pm
Posts: 8
Re: Help with the Compass Sensor?
use the motor and sensor setup and make sure you named the compass sensor something ex: compass
then just saying SensorValue[compass] will return the compass reading
note that the compass increases in value clockwise not counter-clockwise like the unit circle
that caused quite a few problems until I figured that out....

Sat Nov 22, 2008 1:23 pm
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Re: Help with the Compass Sensor?
how else should the compass heading increase if NOT clockwise?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Sat Nov 22, 2008 3:55 pm
Rookie

Joined: Mon Nov 10, 2008 8:54 pm
Posts: 8
Re: Help with the Compass Sensor?
i had just assumed it would be like a unit circle where counter-clockwise is increasing values...
just didnt want him to make the same dumb mistake as I did

Sat Nov 22, 2008 4:16 pm
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Re: Help with the Compass Sensor?
you've probably been thinking of sth like this
 Code:float CompassHeading2MathAngle(float cValue){   float k;   k= 90-cValue;   if (k<0) k+=360;   if (k>=360) k-=360;   return k;}

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Sat Nov 22, 2008 4:30 pm
Rookie

Joined: Sat Nov 22, 2008 7:14 pm
Posts: 12
Location: NJ
Re: Help with the Compass Sensor?
Declare the Compass Sensor

Then use something like this:
 Code:if(SensorValue(CompassName) != 0){//north    motor[motorD] = 100;    motor[motorE] = -100;}

That will have the robot turn till it faces north.

0 = North
90 = East
180 = South
270 = West

_________________
Ethan Spitz
Team 464 Programmer

Sat Nov 22, 2008 7:29 pm

Joined: Wed Jan 24, 2007 10:42 am
Posts: 620
Re: Help with the Compass Sensor?
You'll only get 'absolute heading' from the compass sensor in ROBOTC. I believe a few people on the forum have written code about getting a "relative heading" from the compass sensor, so look around.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net

Mon Nov 24, 2008 11:02 am
Rookie

Joined: Sat Nov 29, 2008 4:21 am
Posts: 4
Re: Help with the Compass Sensor?
We came to the conclusion that trying to use absolute headings during the competition would be problematic, because we have no idea what orientation the field will be in relative to anything else. Therefore we wrote a function to take the current heading and some angle, and add them accounting for the wrap around that occurs with 0 and 360. It looks something like this:

This doesn't do anything with the motors it simply returns a new compass heading based on an angle that you want to turn. You can then write something to turn to a new heading, or maintain a heading, or something else that is based on compass values.

_________________
Ian McBride
Benson Robotics Club

Sat Nov 29, 2008 3:29 pm
Rookie

Joined: Tue Nov 18, 2008 5:13 pm
Posts: 9
Re: Help with the Compass Sensor?
Ian McBride wrote:

What exactly does the "+=" and the "-=" mean? We thought it was "greater than or equal to" or "less than or equal to".... and it'd be helpful if you perhaps could clarify.

Tue Dec 02, 2008 5:44 pm
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Re: Help with the Compass Sensor?
The code:

x += 3;

is shorthand for this:

x = x + 3;

Likewise, x -= 3 is the same as x = x - 3;

Similarly, x++ is the same as x = x + 1 and so on.

Welcome to C.

_________________
Jeff McBride
Benson Robotics Club

Tue Dec 02, 2008 5:48 pm
Rookie

Joined: Mon Nov 17, 2008 4:15 pm
Posts: 3
Re: Help with the Compass Sensor?
 Jeff McBride wrote:{snip}...Welcome to C.

And Java, as well!

Theo

Thu Dec 04, 2008 3:23 pm
Rookie

Joined: Mon Oct 27, 2008 5:41 pm
Posts: 5
Re: Help with the Compass Sensor?
we had a quick question about the compass sensor... does this sensor always begin facing north i.e. on power up... position 0 is automatically north??? or is it that it will go towards the magnetic north??? if the second, does that mean the courses always are pointing in a certain direction???????

Sat Dec 06, 2008 10:53 pm
Rookie

Joined: Mon Nov 10, 2008 8:54 pm
Posts: 8
Re: Help with the Compass Sensor?
it uses magnetic north so you will have to make some code that will give you a relative direction if you want to navigate using relative directions ie:left & right
hint for the code: think about what you said about it starting at 0 and how you would achieve that with math given a reading
also if you don't know what global variables are you might want to look them up if you want to use a relative heading in more than one function

Sun Dec 07, 2008 1:05 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 13 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning