Thank Mr David. I'll try it. May be work in my compass sensor dinsmore 1655. I am beginner in java programming. Would you like to tell me detail code ?. Many thank.

From: David Levy <[EMAIL PROTECTED]...>
Re: Ask Compass Programming 
2006-05-18 06:05
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


Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.

Reply via email to