I'm using the one from HiTechnic.com.
compassSensor = Sensor.S1;
compassSensor.setTypeAndMode(SensorConstants.SENSOR_TYPE_LIGHT,
SensorConstants.SENSOR_MODE_PCT);
compassSensor.activate();
compassSensor.readValue() returns a value from 0 - 99.
compassAngle -
north = 0,east = 25,south= 50 ,west = 75
angleInDegrees-
0 = north ( pointing to right on x-axis)
90 = east ( pointing up on y axis)
-90 = west
180 = south
Negotiate coordinate: say (100,100)
public void negotiatePoint(int anX, int anY) {
rotSensor.setPreviousValue(0);
// Determine relative points
int x1 = anX - getCurrentX();
int y1 = anY - getCurrentY();
// Calculate angle to go to:
setAngleInRads((double)Math.atan2(y1,x1));
// Calculate distance to travel:
if(y1 != 0) {
distanceToTravel =
y1/(float)Math.sin(getAngleInRads());
}
else
{
distanceToTravel =
x1/(float)Math.cos(getAngleInRads());
}
}
private void setAngleInRads(double anAngleInRads) {
angleInRads = anAngleInRads;
// Convert angle from rads to degrees:
double angleInDegrees =
(float)Math.toDegrees(anAngleInRads);
// convert degrees (-180 to 180) to compass 0 - 99
if (angleInDegrees < 0) {
compassAngle = (angleInDegrees + 360) / 3.6;
}
else
{
compassAngle = (angleInDegrees) / 3.6;
}
}
>>From: made agus <[EMAIL PROTECTED]>
>> 2006-05-16 21:38
>>I was try Navigation Lego with compass sensor
pewatron
>>6100/dinsmore 1655. I am successfull try read the
>>sensor (from Core Lego Mindstorms book by Brian
>>Bagnall). But i have a problem when try get the
angle
>>(CompassSensor.java). Any can help me ?. Many thank.
>>Regards,
>>Agoes
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Lejos-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lejos-discussion