Skip to content

Commit 1a284b5

Browse files
Feat/wrist intake (#63)
* code for new intake with wrist still need to write commands for it though * actually create hardware objects for the new intake * update values from hardware in the software interface * wrote commands to move the wrist to a certain position, either just straight to a position or incrementing it * bind some of the wrist commands we need * wrist tilt encoder on shuffleboard * clean up the intake commands and add some more OKC_CALL stuff * add an offset to the tilt encoder * fix intake parameters * more okc checks
1 parent 3dd924a commit 1a284b5

File tree

15 files changed

+177
-11
lines changed

15 files changed

+177
-11
lines changed

src/main/cpp/RobotContainer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ bool RobotContainer::ConfigureButtonBindings() {
7171

7272
manip_b_button_->WhenPressed(*arm_score_mid_command_);
7373
manip_y_button_->WhenPressed(*arm_score_high_command_);
74+
75+
manip_left_stick_button_->WhenHeld(*inc_wrist_tilt_command_);
76+
manip_right_stick_button_->WhenHeld(*dec_wrist_tilt_command_);
7477

7578
WPI_UNIGNORE_DEPRECATED
7679

@@ -343,6 +346,9 @@ bool RobotContainer::InitCommands() {
343346
intake_command = std::make_shared<IntakeCommand>(intake_, 0.3);
344347
other_intake_command = std::make_shared<IntakeCommand>(intake_, -0.3);
345348
stop_intake_command = std::make_shared<IntakeCommand>(intake_, -0.01);
349+
350+
inc_wrist_tilt_command_ = std::make_shared<IncrementIntakePositionCommand>(intake_, 1);
351+
dec_wrist_tilt_command_ = std::make_shared<IncrementIntakePositionCommand>(intake_, -1);
346352

347353
return true;
348354
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <frc2/command/CommandBase.h>
2+
#include <frc2/command/CommandHelper.h>
3+
4+
#include "Utils.h"
5+
#include "subsystems/Intake.h"
6+
7+
#include "commands/intake/IncrementIntakePositionCommand.h"
8+
9+
IncrementIntakePositionCommand::IncrementIntakePositionCommand(std::shared_ptr<Intake> intake, double angle) {
10+
// Set everything.
11+
intake_ = intake;
12+
angle_ = angle;
13+
14+
if (intake_ != nullptr) {
15+
this->AddRequirements(intake_.get());
16+
}
17+
}
18+
19+
void IncrementIntakePositionCommand::Initialize() {
20+
VOKC_CHECK(intake_ != nullptr);
21+
VOKC_CALL(intake_->SetControlMode(Auto));
22+
}
23+
24+
25+
void IncrementIntakePositionCommand::Execute() {
26+
VOKC_CHECK(intake_ != nullptr);
27+
VOKC_CALL(intake_->IncrementIntakeTilt(angle_));
28+
}
29+
30+
bool IncrementIntakePositionCommand::IsFinished() {
31+
// Always end this command.
32+
return true;
33+
}

src/main/cpp/commands/intake/IntakeCommand.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ IntakeCommand::IntakeCommand(std::shared_ptr<Intake> intake,
1313
power_ = power;
1414

1515
if (intake_ != nullptr) {
16-
this->AddRequirements(intake_.get());
17-
18-
intake_->SetControlMode(Manual);
16+
this->AddRequirements(intake_.get());
1917
}
2018
}
2119

22-
20+
void IntakeCommand::Initialize() {
21+
VOKC_CALL(intake_ != nullptr);
22+
VOKC_CALL(intake_->SetControlMode(Manual));
23+
}
2324

2425

2526
void IntakeCommand::Execute() {
2627
VOKC_CHECK(intake_ != nullptr);
2728
VOKC_CALL(intake_->SetIntakePower(power_))
28-
29-
3029
}
3130

3231
bool IntakeCommand::IsFinished() {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <frc2/command/CommandBase.h>
2+
#include <frc2/command/CommandHelper.h>
3+
4+
#include "Utils.h"
5+
#include "subsystems/Intake.h"
6+
7+
#include "commands/intake/IntakePositionCommand.h"
8+
9+
IntakePositionCommand::IntakePositionCommand(std::shared_ptr<Intake> intake, double angle) {
10+
// Set everything.
11+
intake_ = intake;
12+
angle_ = angle;
13+
14+
if (intake_ != nullptr) {
15+
this->AddRequirements(intake_.get());
16+
}
17+
}
18+
19+
void IntakePositionCommand::Initialize() {
20+
VOKC_CHECK(intake_ != nullptr)
21+
VOKC_CALL(intake_->SetControlMode(Auto));
22+
}
23+
24+
25+
void IntakePositionCommand::Execute() {
26+
VOKC_CHECK(intake_ != nullptr);
27+
VOKC_CALL(intake_->SetIntakeTilt(angle_));
28+
}
29+
30+
bool IntakePositionCommand::IsFinished() {
31+
// Always end this command.
32+
return true;
33+
}

src/main/cpp/io/IntakeIO.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#include "Parameters.h"
33

44
bool IntakeIO::Init() {
5-
return true;
5+
offset_ = RobotParams::GetParam("intake.tilt_offset", 0.0);
6+
7+
return true;
68
}
79

810
void IntakeIO::Periodic() {
@@ -43,7 +45,7 @@ bool IntakeIO::ProcessIO() {
4345

4446
// wrist encoder
4547
OKC_CHECK(hw_interface_->wrist_encoder != nullptr);
46-
sw_interface_->tilt_encoder = hw_interface_->wrist_encoder->GetAbsolutePosition(); // TODO parameterize and offset and stuff
48+
sw_interface_->tilt_encoder = hw_interface_->wrist_encoder->GetAbsolutePosition() + offset_;
4749

4850
// === outputs ===
4951
hw_interface_->intake_motor->Set(sw_interface_->intake_power);

src/main/cpp/subsystems/Intake.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ bool Intake::Init() {
77
OKC_CHECK(this->interface_ != nullptr);
88

99
// the PID controller for the wrist
10-
double wrist_kP = RobotParams::GetParam("intale.wrist_pid.kP", 0.005);
11-
double wrist_kI = RobotParams::GetParam("intale.wrist_pid.kI", 0.0);
12-
double wrist_kD = RobotParams::GetParam("intale.wrist_pid.kD", 0.0);
10+
double wrist_kP = RobotParams::GetParam("intake.wrist_pid.kP", 0.005);
11+
double wrist_kI = RobotParams::GetParam("intake.wrist_pid.kI", 0.0);
12+
double wrist_kD = RobotParams::GetParam("intake.wrist_pid.kD", 0.0);
1313
wrist_pid_ = std::make_shared<frc::PIDController>(wrist_kP, wrist_kI, wrist_kD);
1414

1515
// wrist_pid_->SetTolerance(1, 1);
@@ -42,6 +42,14 @@ bool Intake::SetIntakeTilt(double degrees) {
4242
return true;
4343
}
4444

45+
bool Intake::IncrementIntakeTilt(double degrees) {
46+
OKC_CHECK(this->wrist_pid_ != nullptr);
47+
48+
this->wrist_pid_->SetSetpoint(this->wrist_pid_->GetSetpoint() + degrees);
49+
50+
return true;
51+
}
52+
4553
bool Intake::SetControlMode(const ControlMode &mode){
4654
mode_= mode;
4755

@@ -61,6 +69,7 @@ bool Intake::AutoControl() {
6169
OKC_CHECK(this->wrist_pid_ != nullptr);
6270

6371
interface_->tilt_power = this->wrist_pid_->Calculate(interface_->tilt_encoder);
72+
interface_->intake_power = intake_power_;
6473

6574
return true;
6675
}
@@ -80,6 +89,8 @@ void Intake::Periodic() {
8089
default:
8190
VOKC_CHECK_MSG(false, "unhandled intake enum");
8291
}
92+
93+
VOKC_CALL(IntakeUI::nt_tilt->SetDouble(this->interface_->tilt_encoder));
8394
}
8495

8596

src/main/cpp/ui/UserInterface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,10 @@ namespace ClawUI {
6565
frc::ShuffleboardTab &nt_tab = frc::Shuffleboard::GetTab("claw");
6666

6767
nt::GenericEntry *const nt_claw_encoder = nt_tab.Add("claw encoder", 0.0).GetEntry();
68+
}
69+
70+
namespace IntakeUI {
71+
frc::ShuffleboardTab &nt_tab = frc::Shuffleboard::GetTab("claw");
72+
73+
nt::GenericEntry *const nt_tilt = nt_tab.Add("wrist encoder", 0.0).GetEntry();
6874
}

src/main/deploy/parameters.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,6 @@ cone = 5
107107
kP = 0.01
108108
kI = 0
109109
kD = 0
110+
111+
[intake]
112+
tilt_offset = 0.0

src/main/include/RobotContainer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
//intake
5050
#include "commands/intake/IntakeCommand.h"
51+
#include "commands/intake/IntakePositionCommand.h"
52+
#include "commands/intake/IncrementIntakePositionCommand.h"
5153

5254
// misc
5355
#include <frc2/command/Command.h>
@@ -182,4 +184,7 @@ class RobotContainer {
182184
std::shared_ptr<IntakeCommand> intake_command;
183185
std::shared_ptr<IntakeCommand> other_intake_command;
184186
std::shared_ptr<IntakeCommand> stop_intake_command;
187+
188+
std::shared_ptr<IncrementIntakePositionCommand> inc_wrist_tilt_command_;
189+
std::shared_ptr<IncrementIntakePositionCommand> dec_wrist_tilt_command_;
185190
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <frc2/command/CommandBase.h>
4+
#include <frc2/command/CommandHelper.h>
5+
6+
#include "Utils.h"
7+
#include "subsystems/Intake.h"
8+
9+
/**
10+
*
11+
*/
12+
class IncrementIntakePositionCommand
13+
: public frc2::CommandHelper<frc2::CommandBase, IncrementIntakePositionCommand> {
14+
public:
15+
/**
16+
* Creates a new IncrementArmExtendCommand.
17+
*
18+
* @param arm The subsystem used by this command.
19+
*/
20+
explicit IncrementIntakePositionCommand(std::shared_ptr<Intake> intake, double angle);
21+
22+
void Execute() override;
23+
void Initialize() override;
24+
bool IsFinished() override;
25+
26+
private:
27+
std::shared_ptr<Intake> intake_;
28+
double angle_;
29+
};

0 commit comments

Comments
 (0)