-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9efb05
commit c467506
Showing
3 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/CommandRobot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
package edu.wpi.first.wpilibj2.command; | ||
|
||
import edu.wpi.first.hal.FRCNetComm.tInstances; | ||
import edu.wpi.first.hal.FRCNetComm.tResourceType; | ||
import edu.wpi.first.hal.HAL; | ||
import edu.wpi.first.wpilibj.TimedRobot; | ||
|
||
/** | ||
* CommandRobot is a wrapper over TimedRobot designed to work well with Command based programming. | ||
* | ||
* <p>The CommandRobot class is intended to be subclassed by a user creating a robot program. | ||
*/ | ||
public class CommandRobot extends TimedRobot { | ||
/// The CommandScheduler instance. | ||
protected CommandScheduler m_scheduler = CommandScheduler.getInstance(); | ||
|
||
/// The Command run during autonomous. | ||
protected Command m_autonomousCommand = | ||
Commands.print("Default auto Command override autonomousInit to add your own."); | ||
|
||
/** Constructor for CommandRobot. */ | ||
protected CommandRobot() { | ||
this(kDefaultPeriod); | ||
} | ||
|
||
/** | ||
* Constructor for CommandRobot. | ||
* | ||
* @param period Period in seconds. | ||
*/ | ||
protected CommandRobot(double period) { | ||
super(period); | ||
HAL.report(tResourceType.kResourceType_Framework, tInstances.kFramework_CommandControl); | ||
} | ||
|
||
@Override | ||
public final void robotInit() {} | ||
|
||
@Override | ||
public final void robotPeriodic() { | ||
m_scheduler.run(); | ||
} | ||
|
||
@Override | ||
public void autonomousInit() { | ||
if (m_autonomousCommand != null) { | ||
m_scheduler.schedule(m_autonomousCommand); | ||
} | ||
} | ||
|
||
@Override | ||
public final void autonomousPeriodic() {} | ||
|
||
@Override | ||
public void autonomousExit() {} | ||
|
||
@Override | ||
public final void teleopInit() { | ||
if (m_autonomousCommand != null) { | ||
m_scheduler.cancel(m_autonomousCommand); | ||
} | ||
} | ||
|
||
@Override | ||
public final void teleopPeriodic() {} | ||
|
||
@Override | ||
public final void teleopExit() {} | ||
|
||
@Override | ||
public final void disabledInit() {} | ||
|
||
@Override | ||
public final void disabledPeriodic() {} | ||
|
||
@Override | ||
public final void disabledExit() {} | ||
} |
40 changes: 40 additions & 0 deletions
40
wpilibNewCommands/src/main/native/cpp/frc2/command/CommandRobot.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "frc2/command/CommandRobot.h" | ||
#include "units/time.h" | ||
|
||
frc2::CommandRobot::CommandRobot(units::second_t period) | ||
: frc::TimedRobot(period) { | ||
HAL_Report(HALUsageReporting::kResourceType_Framework, | ||
HALUsageReporting::kFramework_CommandControl); | ||
} | ||
|
||
void frc2::CommandRobot::RobotInit() {} | ||
|
||
void frc2::CommandRobot::RobotPeriodic() { | ||
m_scheduler.Run(); | ||
} | ||
|
||
void frc2::CommandRobot::AutonomousInit() { | ||
if (m_autonomousCommand) { | ||
m_scheduler.Schedule(m_autonomousCommand); | ||
} | ||
} | ||
|
||
void frc2::CommandRobot::AutonomousPeriodic() {} | ||
|
||
void frc2::CommandRobot::AutonomousExit() {} | ||
|
||
void frc2::CommandRobot::TeleopInit() { | ||
if (m_autonomousCommand) { | ||
m_scheduler.Cancel(m_autonomousCommand); | ||
} | ||
} | ||
|
||
void frc2::CommandRobot::TeleopPeriodic() {} | ||
|
||
void frc2::CommandRobot::TeleopExit() {} | ||
|
||
void frc2::CommandRobot::DisabledInit() {} | ||
|
||
void frc2::CommandRobot::DisabledPeriodic() {} | ||
|
||
void frc2::CommandRobot::DisabledExit() {} |
62 changes: 62 additions & 0 deletions
62
wpilibNewCommands/src/main/native/include/frc2/command/CommandRobot.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) FIRST and other WPILib contributors. | ||
// Open Source Software; you can modify and/or share it under the terms of | ||
// the WPILib BSD license file in the root directory of this project. | ||
|
||
#pragma once | ||
|
||
#include <frc/TimedRobot.h> | ||
#include <hal/FRCUsageReporting.h> | ||
#include <units/time.h> | ||
|
||
#include "frc2/command/CommandPtr.h" | ||
#include "frc2/command/CommandScheduler.h" | ||
#include "frc2/command/Commands.h" | ||
|
||
namespace frc2 { | ||
/** | ||
CommandRobot is a wrapper over TimedRobot designed to work well with Command | ||
* based programming. | ||
* | ||
* <p>The CommandRobot class is intended to be subclassed by a user creating a | ||
* robot program. | ||
*/ | ||
class CommandRobot : public frc::TimedRobot { | ||
protected: | ||
/// The CommandScheduler instance. | ||
frc2::CommandScheduler& m_scheduler = frc2::CommandScheduler::GetInstance(); | ||
|
||
/// The Command run during autonomous. | ||
frc2::CommandPtr m_autonomousCommand = frc2::cmd::Print( | ||
"Default auto Command override autonomousInit to add your own."); | ||
|
||
/** | ||
* Constructor for CommandRobot. | ||
* | ||
* @param period Period in seconds. | ||
*/ | ||
explicit CommandRobot(units::second_t period = kDefaultPeriod); | ||
|
||
public: | ||
void RobotInit() final; | ||
|
||
void RobotPeriodic() final; | ||
|
||
void AutonomousInit() final; | ||
|
||
void AutonomousPeriodic() final; | ||
|
||
void AutonomousExit() final; | ||
|
||
void TeleopInit() final; | ||
|
||
void TeleopPeriodic() final; | ||
|
||
void TeleopExit() final; | ||
|
||
void DisabledInit() final; | ||
|
||
void DisabledPeriodic() final; | ||
|
||
void DisabledExit() final; | ||
}; | ||
} // namespace frc2 |