mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Merge "Make 3 axis Accelerometers work in LiveWindow. Fixes artf3902."
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "interfaces/Accelerometer.h"
|
||||
#include "I2C.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
/**
|
||||
* ADXL345 Accelerometer on I2C.
|
||||
@@ -14,7 +15,7 @@
|
||||
* This class allows access to a Analog Devices ADXL345 3-axis accelerometer on an I2C bus.
|
||||
* This class assumes the default (not alternate) sensor address of 0x1D (7-bit address).
|
||||
*/
|
||||
class ADXL345_I2C : public Accelerometer, public I2C
|
||||
class ADXL345_I2C : public Accelerometer, public I2C, public LiveWindowSendable
|
||||
{
|
||||
protected:
|
||||
static const uint8_t kAddress = 0x1D;
|
||||
@@ -48,6 +49,15 @@ public:
|
||||
virtual double GetAcceleration(Axes axis);
|
||||
virtual AllAxes GetAccelerations();
|
||||
|
||||
virtual std::string GetSmartDashboardType();
|
||||
virtual void InitTable(ITable *subtable);
|
||||
virtual void UpdateTable();
|
||||
virtual ITable* GetTable();
|
||||
virtual void StartLiveWindowMode() {}
|
||||
virtual void StopLiveWindowMode() {}
|
||||
|
||||
protected:
|
||||
//I2C* m_i2c;
|
||||
private:
|
||||
ITable *m_table;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "interfaces/Accelerometer.h"
|
||||
#include "SensorBase.h"
|
||||
#include "SPI.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
|
||||
class DigitalInput;
|
||||
class DigitalOutput;
|
||||
@@ -18,7 +19,7 @@ class DigitalOutput;
|
||||
* This class allows access to an Analog Devices ADXL345 3-axis accelerometer via SPI.
|
||||
* This class assumes the sensor is wired in 4-wire SPI mode.
|
||||
*/
|
||||
class ADXL345_SPI : public Accelerometer, public SensorBase
|
||||
class ADXL345_SPI : public Accelerometer, public SensorBase, public LiveWindowSendable
|
||||
{
|
||||
protected:
|
||||
static const uint8_t kPowerCtlRegister = 0x2D;
|
||||
@@ -52,9 +53,18 @@ public:
|
||||
virtual double GetAcceleration(Axes axis);
|
||||
virtual AllAxes GetAccelerations();
|
||||
|
||||
virtual std::string GetSmartDashboardType();
|
||||
virtual void InitTable(ITable *subtable);
|
||||
virtual void UpdateTable();
|
||||
virtual ITable* GetTable();
|
||||
virtual void StartLiveWindowMode() {}
|
||||
virtual void StopLiveWindowMode() {}
|
||||
|
||||
protected:
|
||||
void Init(Range range);
|
||||
|
||||
SPI* m_spi;
|
||||
SPI::Port m_port;
|
||||
private:
|
||||
ITable *m_table;
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "ADXL345_I2C.h"
|
||||
#include "I2C.h"
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
const uint8_t ADXL345_I2C::kAddress;
|
||||
const uint8_t ADXL345_I2C::kPowerCtlRegister;
|
||||
@@ -31,6 +32,7 @@ ADXL345_I2C::ADXL345_I2C(Port port, Range range):
|
||||
SetRange(range);
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_ADXL345, HALUsageReporting::kADXL345_I2C, 0);
|
||||
LiveWindow::GetInstance()->AddSensor("ADXL345_I2C", port, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,3 +103,24 @@ ADXL345_I2C::AllAxes ADXL345_I2C::GetAccelerations()
|
||||
//}
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string ADXL345_I2C::GetSmartDashboardType() {
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
void ADXL345_I2C::InitTable(ITable *subtable) {
|
||||
m_table = subtable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
void ADXL345_I2C::UpdateTable() {
|
||||
if (m_table != NULL) {
|
||||
m_table->PutNumber("X", GetX());
|
||||
m_table->PutNumber("Y", GetY());
|
||||
m_table->PutNumber("Z", GetZ());
|
||||
}
|
||||
}
|
||||
|
||||
ITable* ADXL345_I2C::GetTable() {
|
||||
return m_table;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "DigitalInput.h"
|
||||
#include "DigitalOutput.h"
|
||||
#include "SPI.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
const uint8_t ADXL345_SPI::kPowerCtlRegister;
|
||||
const uint8_t ADXL345_SPI::kDataFormatRegister;
|
||||
@@ -25,6 +26,7 @@ ADXL345_SPI::ADXL345_SPI(SPI::Port port, ADXL345_SPI::Range range)
|
||||
{
|
||||
m_port = port;
|
||||
Init(range);
|
||||
LiveWindow::GetInstance()->AddSensor("ADXL345_SPI", port, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,3 +140,24 @@ ADXL345_SPI::AllAxes ADXL345_SPI::GetAccelerations()
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string ADXL345_SPI::GetSmartDashboardType() {
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
void ADXL345_SPI::InitTable(ITable *subtable) {
|
||||
m_table = subtable;
|
||||
UpdateTable();
|
||||
}
|
||||
|
||||
void ADXL345_SPI::UpdateTable() {
|
||||
if (m_table != NULL) {
|
||||
m_table->PutNumber("X", GetX());
|
||||
m_table->PutNumber("Y", GetY());
|
||||
m_table->PutNumber("Z", GetZ());
|
||||
}
|
||||
}
|
||||
|
||||
ITable* ADXL345_SPI::GetTable() {
|
||||
return m_table;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "BuiltInAccelerometer.h"
|
||||
#include "HAL/HAL.hpp"
|
||||
#include "WPIErrors.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -18,6 +19,7 @@ BuiltInAccelerometer::BuiltInAccelerometer(Range range)
|
||||
SetRange(range);
|
||||
|
||||
HALReport(HALUsageReporting::kResourceType_Accelerometer, 0, 0, "Built-in accelerometer");
|
||||
LiveWindow::GetInstance()->AddSensor((std::string)"BuiltInAccel",0, this);
|
||||
}
|
||||
|
||||
BuiltInAccelerometer::~BuiltInAccelerometer()
|
||||
@@ -62,7 +64,7 @@ double BuiltInAccelerometer::GetZ()
|
||||
}
|
||||
|
||||
std::string BuiltInAccelerometer::GetSmartDashboardType() {
|
||||
return "Accelerometer";
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
void BuiltInAccelerometer::InitTable(ITable *subtable) {
|
||||
|
||||
@@ -10,12 +10,15 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInst
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dtjones
|
||||
*/
|
||||
public class ADXL345_I2C extends SensorBase implements Accelerometer {
|
||||
public class ADXL345_I2C extends SensorBase implements Accelerometer, LiveWindowSendable {
|
||||
|
||||
private static final byte kAddress = 0x1D;
|
||||
private static final byte kPowerCtlRegister = 0x2D;
|
||||
@@ -65,6 +68,7 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer {
|
||||
setRange(range);
|
||||
|
||||
UsageReporting.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_I2C);
|
||||
LiveWindow.addSensor("ADXL345_I2C", port.getValue(), this);
|
||||
}
|
||||
|
||||
/** {inheritdoc} */
|
||||
@@ -146,5 +150,32 @@ public class ADXL345_I2C extends SensorBase implements Accelerometer {
|
||||
return data;
|
||||
}
|
||||
|
||||
// TODO: Support LiveWindow
|
||||
public String getSmartDashboardType(){
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
private ITable m_table;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void initTable(ITable subtable) {
|
||||
m_table = subtable;
|
||||
updateTable();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void updateTable() {
|
||||
if (m_table != null) {
|
||||
m_table.putNumber("X", getX());
|
||||
m_table.putNumber("Y", getY());
|
||||
m_table.putNumber("Z", getZ());
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public ITable getTable(){
|
||||
return m_table;
|
||||
}
|
||||
|
||||
public void startLiveWindowMode() {}
|
||||
public void stopLiveWindowMode() {}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,16 @@ import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInst
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.interfaces.Accelerometer;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||
import edu.wpi.first.wpilibj.tables.ITable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author dtjones
|
||||
* @author mwills
|
||||
*/
|
||||
public class ADXL345_SPI extends SensorBase implements Accelerometer {
|
||||
public class ADXL345_SPI extends SensorBase implements Accelerometer, LiveWindowSendable {
|
||||
private static final int kPowerCtlRegister = 0x2D;
|
||||
private static final int kDataFormatRegister = 0x31;
|
||||
private static final int kDataRegister = 0x32;
|
||||
@@ -75,6 +78,7 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer {
|
||||
public ADXL345_SPI(SPI.Port port, Range range) {
|
||||
m_spi = new SPI(port);
|
||||
init(range);
|
||||
LiveWindow.addSensor("ADXL345_SPI", port.getValue(), this);
|
||||
}
|
||||
|
||||
public void free(){
|
||||
@@ -190,4 +194,33 @@ public class ADXL345_SPI extends SensorBase implements Accelerometer {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getSmartDashboardType(){
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
private ITable m_table;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void initTable(ITable subtable) {
|
||||
m_table = subtable;
|
||||
updateTable();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void updateTable() {
|
||||
if (m_table != null) {
|
||||
m_table.putNumber("X", getX());
|
||||
m_table.putNumber("Y", getY());
|
||||
m_table.putNumber("Z", getZ());
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public ITable getTable(){
|
||||
return m_table;
|
||||
}
|
||||
|
||||
public void startLiveWindowMode() {}
|
||||
public void stopLiveWindowMode() {}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class BuiltInAccelerometer implements Accelerometer, LiveWindowSendable
|
||||
public BuiltInAccelerometer(Range range) {
|
||||
setRange(range);
|
||||
UsageReporting.report(tResourceType.kResourceType_Accelerometer, 0, 0, "Built-in accelerometer");
|
||||
LiveWindow.addSensor("BuiltInAccel", 0, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +84,7 @@ public class BuiltInAccelerometer implements Accelerometer, LiveWindowSendable
|
||||
}
|
||||
|
||||
public String getSmartDashboardType(){
|
||||
return "Accelerometer";
|
||||
return "3AxisAccelerometer";
|
||||
}
|
||||
|
||||
private ITable m_table;
|
||||
|
||||
Reference in New Issue
Block a user