blob: c8664a54fcc02cd2fb7fc791e3ddf64f23c885be [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) 2008-2019 FIRST. 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 "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
27 // Tell the DS that the robot is ready to be enabled
28 HAL_ObserveUserProgramStarting();
29
30 // Loop forever, calling the appropriate mode-dependent function
31 while (true) {
32 // Wait for driver station data so the loop doesn't hog the CPU
33 DriverStation::GetInstance().WaitForData();
34 if (m_exit) break;
35
36 LoopFunc();
37 }
38}
39
40void IterativeRobot::EndCompetition() {
41 m_exit = true;
42 DriverStation::GetInstance().WakeupWaitForData();
43}