Skip to content

Commit a81a762

Browse files
X-EX3-XokcroboticsteamAbbeySiegX-EX3-Xdanielbrownmsm
authored
Feat/actual claw (#37)
* added hardware files * changed names of motors * defined * labeled buttons * arm sw, hw, cpp, and IO * changed file names * renamed more files * added swerve drive to branch * changed hw, actua, and sen names * it's being weird * test commit * functions added I think * last changes for 1-21-23, added parameter,util * I update the hardware and software interfaces * I changed the software and hardware interfaces and I defined functions in the subsystems * fleshed out claw subsystem * IT WORKSSSS EVERYTHING WORKSSSSSSSSSSSSSSS * fixed include error, added Reset() to claw * The changes Justin asked for * final changes i think * fixed errors * final changes hopefully * changing the #include * solving the case errors * removed claw files for fix * added files back * change backwards slash to a forwards slash because maybe that's making it fail CI because linux v. windows * fix backward->forward slash in ClawIO.cpp --------- Co-authored-by: okcroboticsteam <okcroboticsteam@gmail.com> Co-authored-by: AbbeySieg <abbeys2025@gmail.com> Co-authored-by: X-EX3-X <ouranous64@gmail.org> Co-authored-by: Daniel <56051347+danielbrownmsm@users.noreply.github.com>
1 parent fa90bae commit a81a762

File tree

10 files changed

+166
-4
lines changed

10 files changed

+166
-4
lines changed

src/main/cpp/Utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ namespace TeamOKC {
1919
return true;
2020
}
2121
} // namespace TeamOKC
22+

src/main/cpp/io/ClawIO.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#include "io/ClawIO.h"
3+
4+
void ClawIO::Periodic() {
5+
// Process all the inputs and outputs to/from high level software.
6+
VOKC_CALL(ProcessIO());
7+
}
8+
9+
void ClawIO::SimulationPeriodic() {
10+
// SimulationPeriodic
11+
}
12+
13+
bool ClawIO::ProcessIO() {
14+
OKC_CHECK(sw_interface_ != nullptr);
15+
OKC_CHECK(hw_interface_ != nullptr);
16+
OKC_CHECK(hw_interface_->claw_open_and_close_encoder != nullptr);
17+
18+
// Set the software outputs
19+
// If the encoder should be reset, reset it
20+
if (sw_interface_->reset_claw_open_and_close) {
21+
hw_interface_->claw_open_and_close_encoder->SetPosition (0);
22+
// Lower the encoder reset flag
23+
sw_interface_->reset_claw_open_and_close = false;
24+
}
25+
hw_interface_->claw_open_and_close_motor->Set(sw_interface_->claw_open_and_close_power);
26+
sw_interface_->encoder_reading = hw_interface_->claw_open_and_close_encoder->GetPosition();
27+
28+
return true;
29+
}
30+

src/main/cpp/subsystems/Claw.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "subsystems/Claw.h"
2+
3+
bool Claw::Init(){
4+
return true;
5+
}
6+
7+
bool Claw::ResetPositionEncoder(){
8+
return true;
9+
}
10+
bool Claw::ResetPositionPID(){
11+
return true;
12+
}
13+
bool Claw::SetPosition(){
14+
// SetPosition (30); //cone
15+
// SetPosition (0); //close
16+
// SetPosition (50);//cube
17+
return true;
18+
}
19+
bool Claw::Reset(){
20+
return true;
21+
}
22+
void Claw::Periodic(){
23+
return;
24+
}
25+
void Claw::SimulationPeriodic(){
26+
return;
27+
}

src/main/include/Parameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ namespace RobotParams {
2626
return true;
2727
}
2828
} // namespace RobotParams
29+

src/main/include/RobotContainer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "commands/arm/ManualArmCommand.h"
4646

4747

48-
4948
/**
5049
* This class is where the bulk of the robot should be declared. Since
5150
* Command-based is a "declarative" paradigm, very little robot logic should

src/main/include/hardware/Actuators.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <memory>
44
#include <rev/CANSparkMax.h>
5+
#include "frc/DigitalInput.h"
56

67

78

@@ -44,4 +45,8 @@ typedef struct actuators_t {
4445
std::unique_ptr<rev::CANSparkMax> arm_up_motor;
4546
std::unique_ptr<rev::CANSparkMax> arm_extend_motor;
4647

48+
// Claw things
49+
std::unique_ptr<rev::CANSparkMax> claw_motor;
50+
std::unique_ptr<frc::DigitalInput> claw_IR_sensor;
51+
4752
} Actuators;

src/main/include/hardware/Hardware.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
43
#include <frc/motorcontrol/MotorControllerGroup.h>
54

65
#include "hardware/Actuators.h"

src/main/include/hardware/Sensors.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
#include <memory>
44

55
#include "AHRS.h"
6-
#include "frc/AnalogEncoder.h"
6+
7+
#include <frc/DigitalInput.h>
78
#include <rev/RelativeEncoder.h>
9+
#include "frc/AnalogEncoder.h"
10+
11+
// == sensor ports ==
12+
#define DEPLOY_LIMIT_SWITCH 2
13+
#define RETRACTED_LIMIT_SWITCH 3
14+
15+
#define BALL_DETECTOR 9
816

917
// == sensor ports ==
1018
#define LEFT_FRONT_STEER_ENCODER 0
@@ -16,6 +24,7 @@ typedef struct sensors_t {
1624
// navX IMU
1725
std::unique_ptr<AHRS> ahrs;
1826

27+
1928
// swerve drive drive encoders
2029
std::unique_ptr<rev::SparkMaxRelativeEncoder> left_front_drive_encoder;
2130
std::unique_ptr<rev::SparkMaxRelativeEncoder> left_back_drive_encoder;
@@ -37,4 +46,4 @@ typedef struct sensors_t {
3746
// arm encoders
3847
std::unique_ptr<rev::SparkMaxRelativeEncoder> arm_lift_encoder;
3948

40-
} Sensors;
49+
} Sensors;

src/main/include/io/ClawIO.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#pragma once
2+
3+
#include <memory>
4+
5+
#include <frc/motorcontrol/MotorControllerGroup.h>
6+
#include <frc2/command/SubsystemBase.h>
7+
#include <frc/DigitalInput.h>
8+
#include <rev/CANSparkMax.h>
9+
10+
#include "Utils.h"
11+
12+
13+
typedef struct claw_config_t {
14+
15+
} ClawConfig;
16+
17+
typedef struct claw_hardware_interface_t {
18+
rev::CANSparkMax *const claw_open_and_close_motor;
19+
rev::SparkMaxRelativeEncoder *const claw_open_and_close_encoder;
20+
} ClawHardware;
21+
22+
typedef struct claw_software_interface_t {
23+
24+
// actuator outputs
25+
double claw_open_and_close_power;
26+
double encoder_reading;
27+
bool reset_claw_open_and_close;
28+
} ClawSoftware;
29+
30+
class ClawIO : public frc2::SubsystemBase {
31+
public:
32+
ClawIO(ClawHardware *hw_interface,
33+
ClawSoftware *sw_interface)
34+
: hw_interface_(hw_interface), sw_interface_(sw_interface) {}
35+
36+
/**
37+
* Will be called periodically whenever the CommandScheduler runs.
38+
*/
39+
void Periodic() override;
40+
41+
/**
42+
* Will be called periodically whenever the CommandScheduler runs during
43+
* simulation.
44+
*/
45+
void SimulationPeriodic() override;
46+
47+
bool ProcessIO();
48+
49+
private:
50+
ClawHardware *const hw_interface_;
51+
ClawSoftware *const sw_interface_;
52+
};

src/main/include/subsystems/Claw.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
#pragma once
6+
7+
#include <frc2/command/SubsystemBase.h>
8+
9+
class Claw : public frc2::SubsystemBase {
10+
public:
11+
Claw();
12+
~Claw();
13+
14+
bool Init();
15+
16+
bool ResetPositionEncoder();
17+
bool ResetPositionPID();
18+
19+
bool SetPosition();
20+
bool Reset();
21+
22+
/**
23+
* Will be called periodically whenever the CommandScheduler runs.
24+
*/
25+
void Periodic() override;
26+
27+
/**
28+
* Will be called periodically whenever the CommandScheduler runs during
29+
* simulation.
30+
*/
31+
void SimulationPeriodic() override;
32+
33+
private:
34+
// Components (e.g. motor controllers and sensors) should generally be
35+
// declared private and exposed only through public methods.
36+
37+
};
38+
39+

0 commit comments

Comments
 (0)