|
| 1 | +package com.autodesk.synthesis.wpilibj; |
| 2 | + |
| 3 | +import com.autodesk.synthesis.Accel; |
| 4 | + |
| 5 | +import edu.wpi.first.wpilibj.SPI; |
| 6 | + |
| 7 | +/** |
| 8 | + * ADXL362 wrapper for simulation support. |
| 9 | + * Extends the original WPILib ADXL362 accelerometer class to provide |
| 10 | + * simulated accelerometer data during simulation. |
| 11 | + */ |
| 12 | +public class ADXL362 extends edu.wpi.first.wpilibj.ADXL362 { |
| 13 | + private Accel m_Accel; |
| 14 | + |
| 15 | + /** |
| 16 | + * Constructor for ADXL362 accelerometer. |
| 17 | + * |
| 18 | + * @param port SPI port the accelerometer is connected to |
| 19 | + * @param range The range of the accelerometer |
| 20 | + */ |
| 21 | + public ADXL362(SPI.Port port, Range range) { |
| 22 | + super(port, range); |
| 23 | + init("SPI", port.value, range); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Constructor with default range. |
| 28 | + * |
| 29 | + * @param port SPI port the accelerometer is connected to |
| 30 | + */ |
| 31 | + public ADXL362(SPI.Port port) { |
| 32 | + this(port, Range.k2G); |
| 33 | + } |
| 34 | + |
| 35 | + private void init(String commType, int port, Range range) { |
| 36 | + this.m_Accel = new Accel("Accel: " + commType, port); |
| 37 | + this.m_Accel.setConnected(true); |
| 38 | + |
| 39 | + double rangeValue; |
| 40 | + switch (range) { |
| 41 | + case k2G: |
| 42 | + rangeValue = 2.0; |
| 43 | + case k4G: |
| 44 | + rangeValue = 4.0; |
| 45 | + case k8G: |
| 46 | + rangeValue = 8.0; |
| 47 | + } |
| 48 | + |
| 49 | + this.m_Accel.setRange(rangeValue); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Get the acceleration in the X-axis. |
| 54 | + * |
| 55 | + * @return X-axis acceleration in g-forces |
| 56 | + */ |
| 57 | + @Override |
| 58 | + public double getX() { |
| 59 | + return m_Accel.getX(); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Get the acceleration in the Y-axis. |
| 64 | + * |
| 65 | + * @return Y-axis acceleration in g-forces |
| 66 | + */ |
| 67 | + @Override |
| 68 | + public double getY() { |
| 69 | + return m_Accel.getY(); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Get the acceleration in the Z-axis. |
| 74 | + * |
| 75 | + * @return Z-axis acceleration in g-forces |
| 76 | + */ |
| 77 | + @Override |
| 78 | + public double getZ() { |
| 79 | + return m_Accel.getZ(); |
| 80 | + } |
| 81 | +} |
0 commit comments