blob: e242d03a18abc535c1cc471ca7305e5e1d8cd1ab [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008-2017. 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 the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#include "RobotBase.h"
9
10#include <cstdio>
11
12#include "DriverStation.h"
13#include "HAL/HAL.h"
14#include "HLUsageReporting.h"
15#include "Internal/HardwareHLReporting.h"
16#include "RobotState.h"
17#include "SmartDashboard/SmartDashboard.h"
18#include "Utility.h"
19#include "WPILibVersion.h"
20#include "networktables/NetworkTable.h"
21
22using namespace frc;
23
24std::thread::id RobotBase::m_threadId;
25
26/**
27 * Constructor for a generic robot program.
28 *
29 * User code should be placed in the constructor that runs before the Autonomous
30 * or Operator Control period starts. The constructor will run to completion
31 * before Autonomous is entered.
32 *
33 * This must be used to ensure that the communications code starts. In the
34 * future it would be nice to put this code into it's own task that loads on
35 * boot so ensure that it runs.
36 */
37RobotBase::RobotBase() : m_ds(DriverStation::GetInstance()) {
38 m_threadId = std::this_thread::get_id();
39
40 RobotState::SetImplementation(DriverStation::GetInstance());
41 HLUsageReporting::SetImplementation(new HardwareHLReporting());
42
43 NetworkTable::SetNetworkIdentity("Robot");
44 NetworkTable::SetPersistentFilename("/home/lvuser/networktables.ini");
45
46 SmartDashboard::init();
47
48 std::FILE* file = nullptr;
49 file = std::fopen("/tmp/frc_versions/FRC_Lib_Version.ini", "w");
50
51 if (file != nullptr) {
52 std::fputs("C++ ", file);
53 std::fputs(WPILibVersion, file);
54 std::fclose(file);
55 }
56}
57
58/**
59 * Determine if the Robot is currently enabled.
60 * @return True if the Robot is currently enabled by the field controls.
61 */
62bool RobotBase::IsEnabled() const { return m_ds.IsEnabled(); }
63
64/**
65 * Determine if the Robot is currently disabled.
66 * @return True if the Robot is currently disabled by the field controls.
67 */
68bool RobotBase::IsDisabled() const { return m_ds.IsDisabled(); }
69
70/**
71 * Determine if the robot is currently in Autonomous mode.
72 * @return True if the robot is currently operating Autonomously as determined
73 * by the field controls.
74 */
75bool RobotBase::IsAutonomous() const { return m_ds.IsAutonomous(); }
76
77/**
78 * Determine if the robot is currently in Operator Control mode.
79 * @return True if the robot is currently operating in Tele-Op mode as
80 * determined by the field controls.
81 */
82bool RobotBase::IsOperatorControl() const { return m_ds.IsOperatorControl(); }
83
84/**
85 * Determine if the robot is currently in Test mode.
86 * @return True if the robot is currently running tests as determined by the
87 * field controls.
88 */
89bool RobotBase::IsTest() const { return m_ds.IsTest(); }
90
91/**
92 * Indicates if new data is available from the driver station.
93 * @return Has new data arrived over the network since the last time this
94 * function was called?
95 */
96bool RobotBase::IsNewDataAvailable() const { return m_ds.IsNewControlData(); }
97
98/**
99 * Gets the ID of the main robot thread
100 */
101std::thread::id RobotBase::GetThreadId() { return m_threadId; }