View unanswered posts | View active topics It is currently Wed Jul 23, 2014 5:10 pm






Reply to topic  [ 13 posts ] 
Help with the Compass Sensor? 
Author Message
Rookie

Joined: Tue Nov 18, 2008 5:13 pm
Posts: 9
Post 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
Profile
Rookie

Joined: Mon Nov 10, 2008 8:54 pm
Posts: 8
Post 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
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 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)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Nov 22, 2008 3:55 pm
Profile
Rookie

Joined: Mon Nov 10, 2008 8:54 pm
Posts: 8
Post 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
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 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)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Nov 22, 2008 4:30 pm
Profile
Rookie

Joined: Sat Nov 22, 2008 7:14 pm
Posts: 12
Location: NJ
Post 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
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 601
Post 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
Profile
Rookie

Joined: Sat Nov 29, 2008 4:21 am
Posts: 4
Post 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:
Code:
int AddHeading(int angle)
{
    int currentHeading = sensorValue[compass];
    int targetHeading;
   
    targetHeading = currentHeading + angle;
    if (targetHeading > 360)
        targetHeading -= 360;
    if (targetHeading < 0)
        targetHeading += 360;
    return targetHeading;
}

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
Profile
Rookie

Joined: Tue Nov 18, 2008 5:13 pm
Posts: 9
Post Re: Help with the Compass Sensor?
Ian McBride wrote:
Code:
int AddHeading(int angle)
{
    int currentHeading = sensorValue[compass];
    int targetHeading;
   
    targetHeading = currentHeading + angle;
    if (targetHeading > 360)
        targetHeading -= 360;
    if (targetHeading < 0)
        targetHeading += 360;
    return targetHeading;
}



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
Profile
Professor

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

Joined: Mon Nov 17, 2008 4:15 pm
Posts: 3
Post 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
Profile
Rookie

Joined: Mon Oct 27, 2008 5:41 pm
Posts: 5
Post 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
Profile
Rookie

Joined: Mon Nov 10, 2008 8:54 pm
Posts: 8
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 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.