Fix GearsBot log methods not being called periodically (#2280)

Add logging for C++ Wrist and Claw
This commit is contained in:
sciencewhiz
2020-01-17 20:18:15 -08:00
committed by Peter Johnson
parent 2eb5c54476
commit ac8177e10d
14 changed files with 88 additions and 29 deletions

View File

@@ -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); },

View File

@@ -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 <frc/smartdashboard/SmartDashboard.h>
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(); }

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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(); }

View File

@@ -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};

View File

@@ -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};

View File

@@ -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;

View File

@@ -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;