Permalink
Browse files

Demonstrating adding a CANTalon to the Eclipse-generated command-base…

…d project.

Auton-Enable to watch Talon SRX blink red (reverse 50%).
Teleop-Enable to watch Talon SRX blink green (forward 50%).
  • Loading branch information...
1 parent 30e41d8 commit 24deb61fef6df69f83d5f6436d74df894f7bbf2d @ozrien ozrien committed Feb 6, 2017
@@ -13,6 +13,8 @@ void ExampleCommand::Initialize() {
// Called repeatedly when this Command is scheduled to run
void ExampleCommand::Execute() {
+ /* [CTRE] Example use for this command, this command will fire in auton. */
+ CommandBase::exampleSubsystem.get()->SetOutputOfSomeKind(-0.10);
}
// Make this return true when this Command no longer needs to run execute()
@@ -14,6 +14,9 @@
class Robot: public frc::IterativeRobot {
public:
void RobotInit() override {
+ /* [CTRE] Invoke the late initialization routines for our subsystems */
+ CommandBase::exampleSubsystem.get()->InitHardware();
+
chooser.AddDefault("Default Auto", new ExampleCommand());
// chooser.AddObject("My Auto", new MyAutoCommand());
frc::SmartDashboard::PutData("Auto Modes", &chooser);
@@ -76,6 +79,12 @@ class Robot: public frc::IterativeRobot {
void TeleopPeriodic() override {
frc::Scheduler::GetInstance()->Run();
+ /*
+ * [CTRE]
+ * Subsystem typically are called from commands, but as a simple example
+ * set our output to a hardcoded value in teleop loop.
+ */
+ CommandBase::exampleSubsystem.get()->SetOutputOfSomeKind(+0.10f);
}
void TestPeriodic() override {
@@ -13,6 +13,8 @@
// constexpr int LEFTMOTOR = 1;
// constexpr int RIGHTMOTOR = 2;
+constexpr int MY_TALON_SRX_DEVICEID = 0; /* [CTRE] DeviceID should match the web-based config */
+
// If you are using multiple modules, make sure to define both the port
// number and the module. For example you with a rangefinder:
// constexpr int RANGE_FINDER_PORT = 1;
@@ -14,3 +14,26 @@ void ExampleSubsystem::InitDefaultCommand() {
// Put methods for controlling this subsystem
// here. Call these from Commands.
+
+/**
+ * [CTRE]
+ * To ensure hardware objects are constructed after WPILIB starts up,
+ * This initialization routine should be called immedietely after
+ * entering RobotInit.
+ */
+void ExampleSubsystem::InitHardware()
+{
+ _talon = new CANTalon(MY_TALON_SRX_DEVICEID);
+}
+/**
+ * [CTRE]
+ * Example setter for some mechanism.
+ */
+void ExampleSubsystem::SetOutputOfSomeKind(double output)
+{
+ // additionally could null check _talon if need be.
+ // for example: if(_talon == 0) { return; }
+ _talon->Set(output);
+}
+
+
@@ -2,15 +2,31 @@
#define EXAMPLE_SUBSYSTEM_H
#include <Commands/Subsystem.h>
+#include "CANTalon.h" // [CTRE]
class ExampleSubsystem: public frc::Subsystem {
public:
ExampleSubsystem();
void InitDefaultCommand() override;
+
+ /**
+ * [CTRE]
+ * To ensure hardware objects are constructed after WPILIB starts up,
+ * This initialization routine should be called immediately after
+ * entering RobotInit.
+ */
+ void InitHardware();
+ /**
+ * [CTRE]
+ * Example setter for some mechanism.
+ */
+ void SetOutputOfSomeKind(double output);
+
private:
// It's desirable that everything possible under private except
// for methods that implement subsystem capabilities
+ CANTalon * _talon = 0; // [CTRE] default to zero. @see InitHardware for constructor.
};
#endif // EXAMPLE_SUBSYSTEM_H

0 comments on commit 24deb61

Please sign in to comment.