Skip to content

Commit 2bed1dd

Browse files
Arm improvement and tuning (#69)
* code for new intake with wrist (#58) * 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 * feat/field-oriented-scoring (#62) * field oreinted scoring written, builds, untested * field-oriented scoring tested, works * left and right bumpers for pickup positions so we can pickup on both sides of the robot * fix arm offset * 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 * fix intake wrist tilt encoder port * log the intake tilt output, setpoint, and sensor reading * field-oriented intake tilting commands * wrap the tilt encoder because the zero-point is in a really annoying spot and fix the setpoints * log the intake wrist values, and show them on shuffleboard, * if arm is close to 0 and trying to go to 0 then prevent it from oscillating * added wrist setpoint to shuffleboard * made intake faster * started work on a command to pause auton execution for the arm * wrist setpoint on shuffleboard * fix extend thresholds/setpoints because we replaced the gearboxes * intake wrist tilt tuning and fixing * code no workey tilt then move claw arm thingy * Improved and Tuned Arm and Added ff to arm control * fix PR comments --------- Co-authored-by: Daniel <56051347+danielbrownmsm@users.noreply.github.com> Co-authored-by: danielbrownmsm <daniel.brown@msmrockets.org>
1 parent 92f25a4 commit 2bed1dd

File tree

7 files changed

+27
-3
lines changed

7 files changed

+27
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ deploy {
3636
def deployArtifact = deploy.targets.roborio.artifacts.frcCpp
3737

3838
// Set this to true to enable desktop support.
39-
def includeDesktopSupport = false
39+
def includeDesktopSupport = true
4040

4141
// Set to true to run simulation in debug mode
4242
wpi.cpp.debugSimulation = false

src/main/cpp/RobotContainer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ bool RobotContainer::ConfigureButtonBindings() {
7070
// second driver controls
7171
manip_right_bumper_button_->WhenPressed(*pickup_command_);
7272
manip_left_bumper_button_->WhenPressed(*pickup_reverse_command_);
73+
7374
manip_x_button_->WhenPressed(*carry_command_);
7475

7576
manip_b_button_->WhenPressed(*score_mid_command_);

src/main/cpp/Utils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,16 @@ namespace TeamOKC {
3232
double Radians(double degrees) {
3333
return degrees * M_PI / 180.0;
3434
}
35+
double sign(double value) {
36+
if (value>0) {
37+
return 1;
38+
}
39+
if (value<0) {
40+
return -1;
41+
}
42+
if (value==0) {
43+
return 0;
44+
}
45+
}
3546
} // namespace TeamOKC
3647

src/main/cpp/subsystems/Arm.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "subsystems/Arm.h"
22
#include "Parameters.h"
33
#include "ui/UserInterface.h"
4+
#include "Utils.h"
5+
46

57
bool Arm::Init() {
68
// initializing the arm
@@ -10,8 +12,10 @@ bool Arm::Init() {
1012
double arm_kP = RobotParams::GetParam("arm.lift_pid.kP", 0.005);
1113
double arm_kI = RobotParams::GetParam("arm.lift_pid.kI", 0.0);
1214
double arm_kD = RobotParams::GetParam("arm.lift_pid.kD", 0.0);
15+
double arm_kF = RobotParams::GetParam("arm.lift_pid.kF", 0.05);
1316
arm_pid_ = std::make_shared<frc::PIDController>(arm_kP, arm_kI, arm_kD);
1417
arm_pid_->SetTolerance(2, 2);
18+
arm_kF_ = arm_kF;
1519

1620
double extend_kP = RobotParams::GetParam("arm.extend_pid.kP", 0.005);
1721
double extend_kI = RobotParams::GetParam("arm.extend_pid.kI", 0.0);
@@ -42,6 +46,7 @@ bool Arm::Init() {
4246
return true;
4347
}
4448

49+
4550
bool Arm::SetControlMode(const ControlMode &mode){
4651
mode_= mode;
4752

@@ -146,8 +151,12 @@ bool Arm::TestControl() {
146151
this->arm_pid_->SetSetpoint(this->desired_state_.rotation);
147152
this->inches_pid_->SetSetpoint(this->desired_state_.extension);
148153

154+
// calculate feedforward
155+
// take the sign of the desired state, multiply it by the feedforward gain times the desired rotation squared. this looks like output = signum(setpoint) * kF * setpoint^2
156+
double ff = TeamOKC::sign(this->desired_state_.rotation) * arm_kF_ * this->desired_state_.rotation * this->desired_state_.rotation;
157+
149158
// set output
150-
this->interface_->arm_lift_power = this->arm_pid_->Calculate(this->state_.rotation);
159+
this->interface_->arm_lift_power = this->arm_pid_->Calculate(this->state_.rotation) + ff;
151160
this->interface_->arm_extend_power = this->inches_pid_->Calculate(this->state_.extension);
152161

153162
return true;

src/main/deploy/parameters.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ arm_setpoint = 94.0
8888
intake_setpoint = -40.0
8989

9090
[arm.negative_pickup]
91-
extend_setpoint = 50.0
91+
extend_setpoint = 20.0
9292
arm_setpoint = -25.0
9393
intake_setpoint = -70.0
9494

src/main/include/Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ namespace TeamOKC {
6262

6363
bool WrapAngle(double *angle);
6464
double Radians(double degrees);
65+
double sign(double value);
6566

6667
typedef struct arm_state_t {
6768
double extension;

src/main/include/subsystems/Arm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <frc2/command/SubsystemBase.h>
55
#include <io/ArmIO.h>
66
#include <memory>
7+
#include "Utils.h"
78

89
#include "Logging.h"
910
#include "wpi/DataLog.h"
@@ -56,6 +57,7 @@ class Arm : public frc2::SubsystemBase {
5657
// PID controllers
5758
std::shared_ptr<frc::PIDController> arm_pid_;
5859
std::shared_ptr<frc::PIDController> inches_pid_;
60+
double arm_kF_;
5961

6062
// controls stuff (I'd call it a state machine but it isn't really a state machine)
6163
ControlMode mode_;

0 commit comments

Comments
 (0)