diff --git a/src/main/cpp/Utils.cpp b/src/main/cpp/Utils.cpp index 0643b07..f11480b 100644 --- a/src/main/cpp/Utils.cpp +++ b/src/main/cpp/Utils.cpp @@ -19,3 +19,4 @@ namespace TeamOKC { return true; } } // namespace TeamOKC + diff --git a/src/main/cpp/io/ClawIO.cpp b/src/main/cpp/io/ClawIO.cpp new file mode 100644 index 0000000..e1f21dd --- /dev/null +++ b/src/main/cpp/io/ClawIO.cpp @@ -0,0 +1,30 @@ + +#include "io/ClawIO.h" + +void ClawIO::Periodic() { + // Process all the inputs and outputs to/from high level software. + VOKC_CALL(ProcessIO()); +} + +void ClawIO::SimulationPeriodic() { + // SimulationPeriodic +} + +bool ClawIO::ProcessIO() { + OKC_CHECK(sw_interface_ != nullptr); + OKC_CHECK(hw_interface_ != nullptr); + OKC_CHECK(hw_interface_->claw_open_and_close_encoder != nullptr); + + // Set the software outputs + // If the encoder should be reset, reset it + if (sw_interface_->reset_claw_open_and_close) { + hw_interface_->claw_open_and_close_encoder->SetPosition (0); + // Lower the encoder reset flag + sw_interface_->reset_claw_open_and_close = false; + } + hw_interface_->claw_open_and_close_motor->Set(sw_interface_->claw_open_and_close_power); + sw_interface_->encoder_reading = hw_interface_->claw_open_and_close_encoder->GetPosition(); + + return true; +} + diff --git a/src/main/cpp/subsystems/Claw.cpp b/src/main/cpp/subsystems/Claw.cpp new file mode 100644 index 0000000..a8827b5 --- /dev/null +++ b/src/main/cpp/subsystems/Claw.cpp @@ -0,0 +1,27 @@ +#include "subsystems/Claw.h" + +bool Claw::Init(){ + return true; +} + +bool Claw::ResetPositionEncoder(){ + return true; +} +bool Claw::ResetPositionPID(){ + return true; +} +bool Claw::SetPosition(){ + // SetPosition (30); //cone + // SetPosition (0); //close + // SetPosition (50);//cube + return true; +} +bool Claw::Reset(){ + return true; +} +void Claw::Periodic(){ + return; +} +void Claw::SimulationPeriodic(){ + return; +} diff --git a/src/main/include/Parameters.h b/src/main/include/Parameters.h index 3981530..6c0fa6b 100644 --- a/src/main/include/Parameters.h +++ b/src/main/include/Parameters.h @@ -26,3 +26,4 @@ namespace RobotParams { return true; } } // namespace RobotParams + diff --git a/src/main/include/RobotContainer.h b/src/main/include/RobotContainer.h index 0c21fbc..17a8d35 100644 --- a/src/main/include/RobotContainer.h +++ b/src/main/include/RobotContainer.h @@ -45,7 +45,6 @@ #include "commands/arm/ManualArmCommand.h" - /** * This class is where the bulk of the robot should be declared. Since * Command-based is a "declarative" paradigm, very little robot logic should diff --git a/src/main/include/hardware/Actuators.h b/src/main/include/hardware/Actuators.h index 6fb06dd..4823cd9 100644 --- a/src/main/include/hardware/Actuators.h +++ b/src/main/include/hardware/Actuators.h @@ -2,6 +2,7 @@ #include #include +#include "frc/DigitalInput.h" @@ -44,4 +45,8 @@ typedef struct actuators_t { std::unique_ptr arm_up_motor; std::unique_ptr arm_extend_motor; + // Claw things + std::unique_ptr claw_motor; + std::unique_ptr claw_IR_sensor; + } Actuators; \ No newline at end of file diff --git a/src/main/include/hardware/Hardware.h b/src/main/include/hardware/Hardware.h index 5aa1fe1..0482041 100644 --- a/src/main/include/hardware/Hardware.h +++ b/src/main/include/hardware/Hardware.h @@ -1,6 +1,5 @@ #pragma once - #include #include "hardware/Actuators.h" diff --git a/src/main/include/hardware/Sensors.h b/src/main/include/hardware/Sensors.h index f5bc898..efc327a 100644 --- a/src/main/include/hardware/Sensors.h +++ b/src/main/include/hardware/Sensors.h @@ -3,8 +3,16 @@ #include #include "AHRS.h" -#include "frc/AnalogEncoder.h" + +#include #include +#include "frc/AnalogEncoder.h" + +// == sensor ports == +#define DEPLOY_LIMIT_SWITCH 2 +#define RETRACTED_LIMIT_SWITCH 3 + +#define BALL_DETECTOR 9 // == sensor ports == #define LEFT_FRONT_STEER_ENCODER 0 @@ -16,6 +24,7 @@ typedef struct sensors_t { // navX IMU std::unique_ptr ahrs; + // swerve drive drive encoders std::unique_ptr left_front_drive_encoder; std::unique_ptr left_back_drive_encoder; @@ -37,4 +46,4 @@ typedef struct sensors_t { // arm encoders std::unique_ptr arm_lift_encoder; -} Sensors; +} Sensors; \ No newline at end of file diff --git a/src/main/include/io/ClawIO.h b/src/main/include/io/ClawIO.h new file mode 100644 index 0000000..7cd359c --- /dev/null +++ b/src/main/include/io/ClawIO.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +#include +#include +#include +#include + +#include "Utils.h" + + +typedef struct claw_config_t { + +} ClawConfig; + +typedef struct claw_hardware_interface_t { + rev::CANSparkMax *const claw_open_and_close_motor; + rev::SparkMaxRelativeEncoder *const claw_open_and_close_encoder; +} ClawHardware; + +typedef struct claw_software_interface_t { + + // actuator outputs + double claw_open_and_close_power; + double encoder_reading; + bool reset_claw_open_and_close; +} ClawSoftware; + +class ClawIO : public frc2::SubsystemBase { +public: + ClawIO(ClawHardware *hw_interface, + ClawSoftware *sw_interface) + : hw_interface_(hw_interface), sw_interface_(sw_interface) {} + + /** + * Will be called periodically whenever the CommandScheduler runs. + */ + void Periodic() override; + + /** + * Will be called periodically whenever the CommandScheduler runs during + * simulation. + */ + void SimulationPeriodic() override; + + bool ProcessIO(); + +private: + ClawHardware *const hw_interface_; + ClawSoftware *const sw_interface_; +}; \ No newline at end of file diff --git a/src/main/include/subsystems/Claw.h b/src/main/include/subsystems/Claw.h new file mode 100644 index 0000000..67191ac --- /dev/null +++ b/src/main/include/subsystems/Claw.h @@ -0,0 +1,39 @@ +// 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 + +class Claw : public frc2::SubsystemBase { + public: + Claw(); + ~Claw(); + + bool Init(); + + bool ResetPositionEncoder(); + bool ResetPositionPID(); + + bool SetPosition(); + bool Reset(); + + /** + * Will be called periodically whenever the CommandScheduler runs. + */ + void Periodic() override; + + /** + * Will be called periodically whenever the CommandScheduler runs during + * simulation. + */ + void SimulationPeriodic() override; + + private: + // Components (e.g. motor controllers and sensors) should generally be + // declared private and exposed only through public methods. + +}; + +