Dear all,
I am learn about Compass Navigation using dinsmore
1655. The source book from Brian Bagnall "Core Lego
Mindstroms". I am allready have compasssensor class :
How to showing degree in LCD RCX Bricks ?.
Please help me. Thank you.
This the code :
import josx.platform.rcx.*;
class CompassSensor implements SensorConstants {
private Sensor s1;
private Sensor s2;
public int s1_min = 660;
public int s2_min = 646;
public int s1_max = 925;
public int s2_max = 958;
private float midth;
private float a;
private float b;
public CompassSensor(Sensor sensor1, Sensor sensor2) {
sensor1.setTypeAndMode(SENSOR_TYPE_LIGHT,
SENSOR_MODE_RAW);
sensor1.activate();
s1 = sensor1;
sensor2.setTypeAndMode(SENSOR_TYPE_LIGHT,
SENSOR_MODE_RAW);
sensor2.activate();
s2 = sensor2;
}
public void initialize() {
midth = (s1_max + s1_min) / 2;
a = (s1_max - s1_min)/(s2_max - s2_min);
b = s2_max - (a * s1_max);
}
public int getAngle() {
int s1Raw = s1.readValue();
int s2Raw = s2.readValue();
float cosine = s1Raw - midth;
float sine = s2Raw - midth;
float angle = (float)Math.atan2(sine, cosine);
angle = (float)Math.toDegrees(angle);
if(angle < 0)
angle += 360;
return (int)angle;
}
}
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Lejos-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lejos-discussion