From ac8177e10d92ef03c1072928ccdb2f6a2c424491 Mon Sep 17 00:00:00 2001 From: sciencewhiz Date: Fri, 17 Jan 2020 20:18:15 -0800 Subject: [PATCH] Fix GearsBot log methods not being called periodically (#2280) Add logging for C++ Wrist and Claw --- .../main/cpp/examples/GearsBot/cpp/RobotContainer.cpp | 7 +------ .../cpp/examples/GearsBot/cpp/subsystems/Claw.cpp | 10 ++++++++-- .../examples/GearsBot/cpp/subsystems/DriveTrain.cpp | 4 +++- .../cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp | 4 +++- .../cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp | 6 ++++-- .../cpp/examples/GearsBot/include/subsystems/Claw.h | 11 ++++++++++- .../examples/GearsBot/include/subsystems/DriveTrain.h | 8 +++++++- .../examples/GearsBot/include/subsystems/Elevator.h | 8 +++++++- .../cpp/examples/GearsBot/include/subsystems/Wrist.h | 11 ++++++++--- .../wpilibj/examples/gearsbot/RobotContainer.java | 8 +------- .../wpilibj/examples/gearsbot/subsystems/Claw.java | 10 +++++++++- .../examples/gearsbot/subsystems/DriveTrain.java | 10 +++++++++- .../examples/gearsbot/subsystems/Elevator.java | 10 +++++++++- .../wpilibj/examples/gearsbot/subsystems/Wrist.java | 10 +++++++++- 14 files changed, 88 insertions(+), 29 deletions(-) diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp index f79b3fc75e..11a1d75b2a 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/RobotContainer.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -25,11 +25,6 @@ RobotContainer::RobotContainer() frc::SmartDashboard::PutData(&m_wrist); frc::SmartDashboard::PutData(&m_claw); - m_claw.Log(); - m_wrist.Log(); - m_elevator.Log(); - m_drivetrain.Log(); - m_drivetrain.SetDefaultCommand(TankDrive( [this] { return m_joy.GetY(frc::GenericHID::JoystickHand::kLeftHand); }, [this] { return m_joy.GetY(frc::GenericHID::JoystickHand::kRightHand); }, diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Claw.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Claw.cpp index 7f2a60f8ac..e4ebc14639 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Claw.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Claw.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -7,6 +7,8 @@ #include "subsystems/Claw.h" +#include + Claw::Claw() { // Let's show everything on the LiveWindow SetName("Claw"); @@ -21,4 +23,8 @@ void Claw::Stop() { m_motor.Set(0); } bool Claw::IsGripping() { return m_contact.Get(); } -void Claw::Log() {} +void Claw::Log() { + frc::SmartDashboard::PutBoolean("Claw switch", IsGripping()); +} + +void Claw::Periodic() { Log(); } diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/DriveTrain.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/DriveTrain.cpp index 8eec077dac..6bc946cdd7 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/DriveTrain.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/DriveTrain.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -67,3 +67,5 @@ double DriveTrain::GetDistanceToObstacle() { // Really meters in simulation since it's a rangefinder... return m_rangefinder.GetAverageVoltage(); } + +void DriveTrain::Periodic() { Log(); } diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp index acdd07cbef..d5e4ddd8b7 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Elevator.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -31,3 +31,5 @@ double Elevator::GetMeasurement() { return m_pot.Get(); } void Elevator::UseOutput(double output, double setpoint) { m_motor.Set(output); } + +void Elevator::Periodic() { Log(); } diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp index eeb94bb762..a335a6392c 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/cpp/subsystems/Wrist.cpp @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -23,9 +23,11 @@ Wrist::Wrist() : frc2::PIDSubsystem(frc2::PIDController(kP_real, 0, 0)) { } void Wrist::Log() { - // frc::SmartDashboard::PutData("Wrist Angle", &m_pot); + frc::SmartDashboard::PutNumber("Wrist Angle", GetMeasurement()); } double Wrist::GetMeasurement() { return m_pot.Get(); } void Wrist::UseOutput(double output, double setpoint) { m_motor.Set(output); } + +void Wrist::Periodic() { Log(); } diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h index 063ca432c3..a660c1c3cd 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Claw.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -41,8 +41,17 @@ class Claw : public frc2::SubsystemBase { */ bool IsGripping(); + /** + * The log method puts interesting information to the SmartDashboard. + */ void Log(); + /** + * Log the data periodically. This method is automatically called + * by the subsystem. + */ + void Periodic() override; + private: frc::PWMVictorSPX m_motor{7}; frc::DigitalInput m_contact{5}; diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h index a80429d5ff..0fed5529ad 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/DriveTrain.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -60,6 +60,12 @@ class DriveTrain : public frc2::SubsystemBase { */ double GetDistanceToObstacle(); + /** + * Log the data periodically. This method is automatically called + * by the subsystem. + */ + void Periodic() override; + private: frc::PWMVictorSPX m_frontLeft{1}; frc::PWMVictorSPX m_rearLeft{2}; diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h index 8acecbb117..5d2cbd1264 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Elevator.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -39,6 +39,12 @@ class Elevator : public frc2::PIDSubsystem { */ void UseOutput(double output, double setpoint) override; + /** + * Log the data periodically. This method is automatically called + * by the subsystem. + */ + void Periodic() override; + private: frc::PWMVictorSPX m_motor{5}; double m_setpoint = 0; diff --git a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h index 8b54e7efd8..795d2a4c4c 100644 --- a/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h +++ b/wpilibcExamples/src/main/cpp/examples/GearsBot/include/subsystems/Wrist.h @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -32,11 +32,16 @@ class Wrist : public frc2::PIDSubsystem { /** * Use the motor as the PID output. This method is automatically called - * by - * the subsystem. + * by the subsystem. */ void UseOutput(double output, double setpoint) override; + /** + * Log the data periodically. This method is automatically called + * by the subsystem. + */ + void Periodic() override; + private: frc::PWMVictorSPX m_motor{6}; double m_setpoint = 0; diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/RobotContainer.java index 69eb8ae740..40d3f11da6 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/RobotContainer.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/RobotContainer.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -76,12 +76,6 @@ public class RobotContainer { SmartDashboard.putData(m_wrist); SmartDashboard.putData(m_claw); - // Call log method on all subsystems - m_wrist.log(); - m_elevator.log(); - m_drivetrain.log(); - m_claw.log(); - // Configure the button bindings configureButtonBindings(); } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java index b0d2515fdc..86859f1b44 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Claw.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -60,4 +60,12 @@ public class Claw extends SubsystemBase { public boolean isGrabbing() { return m_contact.get(); } + + /** + * Call log method every loop. + */ + @Override + public void periodic() { + log(); + } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java index a0aaa32e4a..9c85429d21 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/DriveTrain.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -121,4 +121,12 @@ public class DriveTrain extends SubsystemBase { // Really meters in simulation since it's a rangefinder... return m_rangefinder.getAverageVoltage(); } + + /** + * Call log method every loop. + */ + @Override + public void periodic() { + log(); + } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java index 4f5c77f354..5492046d65 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Elevator.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -75,4 +75,12 @@ public class Elevator extends PIDSubsystem { public void useOutput(double output, double setpoint) { m_motor.set(output); } + + /** + * Call log method every loop. + */ + @Override + public void periodic() { + log(); + } } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java index dbd952e1c7..1b321394c3 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/subsystems/Wrist.java @@ -1,5 +1,5 @@ /*----------------------------------------------------------------------------*/ -/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */ +/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ /* Open Source Software - may be modified and shared by FRC teams. The code */ /* must be accompanied by the FIRST BSD license file in the root directory of */ /* the project. */ @@ -72,4 +72,12 @@ public class Wrist extends PIDSubsystem { public void useOutput(double output, double setpoint) { m_motor.set(output); } + + /** + * Call log method every loop. + */ + @Override + public void periodic() { + log(); + } }