Author |
Message |
matpat10
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 |
|
 |
kittysniper101
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 |
|
 |
Ford Prefect
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) 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 |
|
 |
kittysniper101
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 |
|
 |
Ford Prefect
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 
_________________ 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 |
|
 |
Ethan Spitz
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: 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 |
|
 |
tfriez
Site Admin
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 |
|
 |
Ian McBride
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 |
|
 |
matpat10
Rookie
Joined: Tue Nov 18, 2008 5:13 pm Posts: 9
|
 Re: Help with the Compass Sensor?
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 |
|
 |
Jeff McBride
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 |
|
 |
twmatthias
Rookie
Joined: Mon Nov 17, 2008 4:15 pm Posts: 3
|
 Re: Help with the Compass Sensor?
|
Thu Dec 04, 2008 3:23 pm |
|
 |
goteam237
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 |
|
 |
kittysniper101
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 |
|
|