Skip to content

Commit 77f21a7

Browse files
Add accelerometer implementation
1 parent 7875e39 commit 77f21a7

File tree

1 file changed

+80
-0
lines changed
  • simulation/SyntheSimJava/src/main/java/com/autodesk/synthesis

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.autodesk.synthesis;
2+
3+
import edu.wpi.first.hal.SimBoolean;
4+
import edu.wpi.first.hal.SimDevice;
5+
import edu.wpi.first.hal.SimDevice.Direction;
6+
import edu.wpi.first.hal.SimDouble;
7+
8+
/**
9+
* Accelerometer class for easy implementation of documentation-compliant simulation data.
10+
*
11+
* See https://github.com/wpilibsuite/allwpilib/blob/6478ba6e3fa317ee041b8a41e562d925602b6ea4/simulation/halsim_ws_core/doc/hardware_ws_api.md
12+
* for documentation on the WebSocket API Specification.
13+
*/
14+
public class Accel {
15+
private SimDevice m_device;
16+
private SimDouble m_range;
17+
private SimBoolean m_connected;
18+
private SimDouble m_x, m_y, m_z;
19+
20+
/**
21+
* Creates a CANMotor sim device in accordance with the WebSocket API Specification.
22+
*
23+
* @param name Name of the Accel. This is generally the class name of the originating gyro (i.e. "ADXRS450").
24+
* @param deviceId ID of the Gyro.
25+
*/
26+
public Accel(String name, int deviceId) {
27+
m_device = SimDevice.create("Accel:" + name, deviceId);
28+
29+
m_range = m_device.createDouble("range", Direction.kOutput, 0.0);
30+
m_connected = m_device.createBoolean("connected", Direction.kOutput, false);
31+
m_x = m_device.createDouble("x", Direction.kInput, 0);
32+
m_y = m_device.createDouble("y", Direction.kInput, 0);
33+
m_z = m_device.createDouble("z", Direction.kInput, 0);
34+
}
35+
36+
/**
37+
* Set the range of the accel.
38+
*
39+
* @param range Range of the accel
40+
*/
41+
public void setRange(double range) {
42+
if (Double.isNaN(range) || Double.isInfinite(range)) {
43+
range = 0.0;
44+
}
45+
46+
m_range.set(range);
47+
}
48+
49+
public void setConnected(boolean connected) {
50+
m_connected.set(connected);
51+
}
52+
53+
/**
54+
* Get the x position of the accel.
55+
*
56+
* @return x
57+
*/
58+
public double getX() {
59+
return m_x.get();
60+
}
61+
62+
/**
63+
* Get the y position of the accel.
64+
*
65+
* @return y
66+
*/
67+
public double getY() {
68+
return m_y.get();
69+
}
70+
71+
/**
72+
* Get the z position of the accel.
73+
*
74+
* @return z
75+
*/
76+
public double getZ() {
77+
return m_z.get();
78+
}
79+
80+
}

0 commit comments

Comments
 (0)