2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-01-01 01:05:57 -07:00
|
|
|
/* Copyright (c) FIRST 2008-2017. All Rights Reserved. */
|
2013-12-15 18:30:16 -05: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. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2014-08-08 10:48:00 -07:00
|
|
|
#include "SampleRobot.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
#include "DriverStation.h"
|
|
|
|
|
#include "LiveWindow/LiveWindow.h"
|
2016-05-20 17:30:37 -07:00
|
|
|
#include "Timer.h"
|
2017-06-30 22:33:43 -04:00
|
|
|
#include "llvm/raw_ostream.h"
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "networktables/NetworkTable.h"
|
|
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
using namespace frc;
|
|
|
|
|
|
2017-07-01 01:12:28 -04:00
|
|
|
/**
|
|
|
|
|
* Start a competition.
|
|
|
|
|
*
|
|
|
|
|
* This code needs to track the order of the field starting to ensure that
|
|
|
|
|
* everything happens in the right order. Repeatedly run the correct method,
|
|
|
|
|
* either Autonomous or OperatorControl or Test when the robot is enabled.
|
|
|
|
|
* After running the correct method, wait for some state to change, either the
|
|
|
|
|
* other mode starts or the robot is disabled. Then go back and wait for the
|
|
|
|
|
* robot to be enabled again.
|
|
|
|
|
*/
|
|
|
|
|
void SampleRobot::StartCompetition() {
|
|
|
|
|
LiveWindow* lw = LiveWindow::GetInstance();
|
|
|
|
|
|
|
|
|
|
RobotInit();
|
|
|
|
|
|
|
|
|
|
// Tell the DS that the robot is ready to be enabled
|
|
|
|
|
HAL_ObserveUserProgramStarting();
|
|
|
|
|
|
|
|
|
|
RobotMain();
|
|
|
|
|
|
|
|
|
|
if (!m_robotMainOverridden) {
|
|
|
|
|
while (true) {
|
|
|
|
|
if (IsDisabled()) {
|
|
|
|
|
m_ds.InDisabled(true);
|
|
|
|
|
Disabled();
|
|
|
|
|
m_ds.InDisabled(false);
|
|
|
|
|
while (IsDisabled()) m_ds.WaitForData();
|
|
|
|
|
} else if (IsAutonomous()) {
|
|
|
|
|
m_ds.InAutonomous(true);
|
|
|
|
|
Autonomous();
|
|
|
|
|
m_ds.InAutonomous(false);
|
|
|
|
|
while (IsAutonomous() && IsEnabled()) m_ds.WaitForData();
|
|
|
|
|
} else if (IsTest()) {
|
|
|
|
|
lw->SetEnabled(true);
|
|
|
|
|
m_ds.InTest(true);
|
|
|
|
|
Test();
|
|
|
|
|
m_ds.InTest(false);
|
|
|
|
|
while (IsTest() && IsEnabled()) m_ds.WaitForData();
|
|
|
|
|
lw->SetEnabled(false);
|
|
|
|
|
} else {
|
|
|
|
|
m_ds.InOperatorControl(true);
|
|
|
|
|
OperatorControl();
|
|
|
|
|
m_ds.InOperatorControl(false);
|
|
|
|
|
while (IsOperatorControl() && IsEnabled()) m_ds.WaitForData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Robot-wide initialization code should go here.
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
2015-10-20 11:12:02 -07:00
|
|
|
* Users should override this method for default Robot-wide initialization which
|
|
|
|
|
* will be called when the robot is first powered on. It will be called exactly
|
|
|
|
|
* one time.
|
|
|
|
|
*
|
|
|
|
|
* Warning: the Driver Station "Robot Code" light and FMS "Robot Ready"
|
|
|
|
|
* indicators will be off until RobotInit() exits. Code in RobotInit() that
|
|
|
|
|
* waits for enable will cause the robot to never indicate that the code is
|
|
|
|
|
* ready, causing the robot to be bypassed in a match.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SampleRobot::RobotInit() {
|
2017-06-30 22:33:43 -04:00
|
|
|
llvm::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n";
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Disabled should go here.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Programmers should override this method to run code that should run while the
|
2016-05-20 17:30:37 -07:00
|
|
|
* field is disabled.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SampleRobot::Disabled() {
|
2017-06-30 22:33:43 -04:00
|
|
|
llvm::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n";
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Autonomous should go here.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Programmers should override this method to run code that should run while the
|
2016-05-20 17:30:37 -07:00
|
|
|
* field is in the autonomous period. This will be called once each time the
|
|
|
|
|
* robot enters the autonomous state.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SampleRobot::Autonomous() {
|
2017-06-30 22:33:43 -04:00
|
|
|
llvm::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n";
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Operator control (tele-operated) code should go here.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Programmers should override this method to run code that should run while the
|
2016-05-20 17:30:37 -07:00
|
|
|
* field is in the Operator Control (tele-operated) period. This is called once
|
|
|
|
|
* each time the robot enters the teleop state.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SampleRobot::OperatorControl() {
|
2017-06-30 22:33:43 -04:00
|
|
|
llvm::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n";
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test program should go here.
|
2016-05-20 17:30:37 -07:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* Programmers should override this method to run code that executes while the
|
2016-05-20 17:30:37 -07:00
|
|
|
* robot is in test mode. This will be called once whenever the robot enters
|
|
|
|
|
* test mode
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SampleRobot::Test() {
|
2017-06-30 22:33:43 -04:00
|
|
|
llvm::outs() << "Default " << __FUNCTION__ << "() method... Overload me!\n";
|
2013-12-15 18:30:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Robot main program for free-form programs.
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
|
|
|
|
* This should be overridden by user subclasses if the intent is to not use the
|
2016-05-20 17:30:37 -07:00
|
|
|
* Autonomous() and OperatorControl() methods. In that case, the program is
|
|
|
|
|
* responsible for sensing when to run the autonomous and operator control
|
|
|
|
|
* functions in their program.
|
2015-06-25 15:07:55 -04:00
|
|
|
*
|
|
|
|
|
* This method will be called immediately after the constructor is called. If it
|
2016-05-20 17:30:37 -07:00
|
|
|
* has not been overridden by a user subclass (i.e. the default version runs),
|
|
|
|
|
* then the Autonomous() and OperatorControl() methods will be called.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
void SampleRobot::RobotMain() { m_robotMainOverridden = false; }
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2017-07-08 10:50:56 -04:00
|
|
|
SampleRobot::SampleRobot() {
|
|
|
|
|
HAL_Report(HALUsageReporting::kResourceType_Framework,
|
|
|
|
|
HALUsageReporting::kFramework_Simple);
|
|
|
|
|
}
|