2014-07-21 08:57:03 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
/* Copyright (c) FIRST 2014-2016. All Rights Reserved. */
|
2014-07-21 08:57:03 -04:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2014-07-21 08:57:03 -04:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "BuiltInAccelerometer.h"
|
|
|
|
|
#include "HAL/HAL.hpp"
|
2014-07-22 18:04:00 -04:00
|
|
|
#include "WPIErrors.h"
|
2014-12-30 18:20:35 -08:00
|
|
|
#include "LiveWindow/LiveWindow.h"
|
2014-07-21 08:57:03 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
* @param range The range the accelerometer will measure
|
|
|
|
|
*/
|
2015-06-24 01:06:29 -07:00
|
|
|
BuiltInAccelerometer::BuiltInAccelerometer(Range range) {
|
2015-06-25 15:07:55 -04:00
|
|
|
SetRange(range);
|
2014-07-22 18:04:00 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
HALReport(HALUsageReporting::kResourceType_Accelerometer, 0, 0,
|
|
|
|
|
"Built-in accelerometer");
|
Revert changes preventing old user code from compiling.
I'm not 100% sure whether we want these, but they are a quick
find and replace to do.
Basically, there are two primary things that we have done
this summer that break existing user code:
-Changing GetInstance() calls to return references instead
of pointers. This forces users to change from doing something
like LiveWindow::GetInstance()->AddSensor() to LiveWindow::GetInstance().AddSensor().
-Making PIDGet() and related calls const, forcing users to change
the function signatures wherever they override them.
The GetInstance() calls don't really matter to me either way,
especially since there are no real ownership issues going on there,
unlike the rest of the smart pointer-related changes.
For the const stuff, it is certainly more correct to mandate that
user PIDGet() functions be const and the such, but at the same time,
I'm not sure that there is any strong need for it, and the errors
generated are not the most helpful. While this wouldn't necessarily
be an issue for more experienced teams or completely new teams (who
don't have any old code to be reusing), it may cause issues for more
average teams who aren't familiar with the intricacies of C++ anything.
Change-Id: I6e7007982069292ea70e6d0fc8ca40203340df1b
2015-07-24 19:19:40 -04:00
|
|
|
LiveWindow::GetInstance()->AddSensor((std::string) "BuiltInAccel", 0, this);
|
2014-07-22 18:04:00 -04:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
void BuiltInAccelerometer::SetRange(Range range) {
|
|
|
|
|
if (range == kRange_16G) {
|
|
|
|
|
wpi_setWPIErrorWithContext(
|
|
|
|
|
ParameterOutOfRange, "16G range not supported (use k2G, k4G, or k8G)");
|
|
|
|
|
}
|
2014-07-22 18:04:00 -04:00
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
setAccelerometerActive(false);
|
|
|
|
|
setAccelerometerRange((AccelerometerRange)range);
|
|
|
|
|
setAccelerometerActive(true);
|
2014-07-21 08:57:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The acceleration of the RoboRIO along the X axis in g-forces
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
double BuiltInAccelerometer::GetX() { return getAccelerometerX(); }
|
2014-07-21 08:57:03 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The acceleration of the RoboRIO along the Y axis in g-forces
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
double BuiltInAccelerometer::GetY() { return getAccelerometerY(); }
|
2014-07-21 08:57:03 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The acceleration of the RoboRIO along the Z axis in g-forces
|
|
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
double BuiltInAccelerometer::GetZ() { return getAccelerometerZ(); }
|
2014-07-21 10:07:46 -04:00
|
|
|
|
2015-06-19 17:23:54 -07:00
|
|
|
std::string BuiltInAccelerometer::GetSmartDashboardType() const {
|
2015-06-25 15:07:55 -04:00
|
|
|
return "3AxisAccelerometer";
|
2014-07-21 10:07:46 -04:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
void BuiltInAccelerometer::InitTable(std::shared_ptr<ITable> subtable) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table = subtable;
|
|
|
|
|
UpdateTable();
|
2014-07-21 10:07:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BuiltInAccelerometer::UpdateTable() {
|
2015-06-23 04:49:51 -07:00
|
|
|
if (m_table != nullptr) {
|
2015-06-25 15:07:55 -04:00
|
|
|
m_table->PutNumber("X", GetX());
|
|
|
|
|
m_table->PutNumber("Y", GetY());
|
|
|
|
|
m_table->PutNumber("Z", GetZ());
|
|
|
|
|
}
|
2014-07-21 10:07:46 -04:00
|
|
|
}
|
|
|
|
|
|
2015-07-29 16:48:04 -04:00
|
|
|
std::shared_ptr<ITable> BuiltInAccelerometer::GetTable() const { return m_table; }
|