blob: a504524ed0fdefc5cbef495bf63ca503491e3def [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2014. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#include "BuiltInAccelerometer.h"
8#include "HAL/HAL.hpp"
9#include "WPIErrors.h"
10#include "LiveWindow/LiveWindow.h"
11
12/**
13 * Constructor.
14 * @param range The range the accelerometer will measure
15 */
16BuiltInAccelerometer::BuiltInAccelerometer(Range range) {
17 SetRange(range);
18
19 HALReport(HALUsageReporting::kResourceType_Accelerometer, 0, 0,
20 "Built-in accelerometer");
21 LiveWindow::GetInstance()->AddSensor((std::string) "BuiltInAccel", 0, this);
22}
23
24/** {@inheritdoc} */
25void BuiltInAccelerometer::SetRange(Range range) {
26 if (range == kRange_16G) {
27 wpi_setWPIErrorWithContext(
28 ParameterOutOfRange, "16G range not supported (use k2G, k4G, or k8G)");
29 }
30
31 setAccelerometerActive(false);
32 setAccelerometerRange((AccelerometerRange)range);
33 setAccelerometerActive(true);
34}
35
36/**
37 * @return The acceleration of the RoboRIO along the X axis in g-forces
38 */
39double BuiltInAccelerometer::GetX() { return getAccelerometerX(); }
40
41/**
42 * @return The acceleration of the RoboRIO along the Y axis in g-forces
43 */
44double BuiltInAccelerometer::GetY() { return getAccelerometerY(); }
45
46/**
47 * @return The acceleration of the RoboRIO along the Z axis in g-forces
48 */
49double BuiltInAccelerometer::GetZ() { return getAccelerometerZ(); }
50
51std::string BuiltInAccelerometer::GetSmartDashboardType() const {
52 return "3AxisAccelerometer";
53}
54
55void BuiltInAccelerometer::InitTable(std::shared_ptr<ITable> subtable) {
56 m_table = subtable;
57 UpdateTable();
58}
59
60void BuiltInAccelerometer::UpdateTable() {
61 if (m_table != nullptr) {
62 m_table->PutNumber("X", GetX());
63 m_table->PutNumber("Y", GetY());
64 m_table->PutNumber("Z", GetZ());
65 }
66}
67
68std::shared_ptr<ITable> BuiltInAccelerometer::GetTable() const { return m_table; }