-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathCompassSensor.java
More file actions
38 lines (26 loc) · 854 Bytes
/
Copy pathCompassSensor.java
File metadata and controls
38 lines (26 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import processing.core.*;
class SensorCompass extends Sensor{
// Random noise applyed to the final reading
private static final int NOISE_AMOUNT = 3;
// Interval to read the sensor in seconds
private static final float READ_INTERVAL = 0.01f;
float[] values = new float[1];
SensorCompass(GameSimulator g, Robot r){
super(g, r);
}
float lastRead = 0;
public float[] readValues(){
if(game.getTime() >= lastRead + READ_INTERVAL)
doReading();
return values;
}
private void doReading(){
Robot thisRobot = getRobot();
float orientation = (float)Math.toDegrees(thisRobot.orientation);
// Fix orientation (from 0-359)
int multiples = (int)(orientation / 360);
orientation = orientation - multiples * 360;
orientation = MathUtil.fixAngle(orientation);
values[0] = getReadingAfterNoise(orientation, NOISE_AMOUNT);
}
}