blob: 72fb79b6aeaa8376224819681dc81b9ea3f07cd8 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001/*----------------------------------------------------------------------------*/
Austin Schuh1e69f942020-11-14 15:06:14 -08002/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
Brian Silverman8fce7482020-01-05 13:18:21 -08003/* 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 "frc/IterativeRobot.h"
9
10#include <hal/DriverStation.h>
11#include <hal/FRCUsageReporting.h>
12
13#include "frc/DriverStation.h"
14
15using namespace frc;
16
17static constexpr auto kPacketPeriod = 0.02_s;
18
19IterativeRobot::IterativeRobot() : IterativeRobotBase(kPacketPeriod) {
20 HAL_Report(HALUsageReporting::kResourceType_Framework,
21 HALUsageReporting::kFramework_Iterative);
22}
23
24void IterativeRobot::StartCompetition() {
25 RobotInit();
26
Austin Schuh1e69f942020-11-14 15:06:14 -080027 if constexpr (IsSimulation()) {
28 SimulationInit();
29 }
30
Brian Silverman8fce7482020-01-05 13:18:21 -080031 // Tell the DS that the robot is ready to be enabled
32 HAL_ObserveUserProgramStarting();
33
34 // Loop forever, calling the appropriate mode-dependent function
35 while (true) {
36 // Wait for driver station data so the loop doesn't hog the CPU
37 DriverStation::GetInstance().WaitForData();
38 if (m_exit) break;
39
40 LoopFunc();
41 }
42}
43
44void IterativeRobot::EndCompetition() {
45 m_exit = true;
46 DriverStation::GetInstance().WakeupWaitForData();
47}