Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/more parameterization #79

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b640df0
code for new intake with wrist (#58)
danielbrownmsm Mar 23, 2023
3dd924a
feat/field-oriented-scoring (#62)
danielbrownmsm Mar 24, 2023
9759771
fix arm offset
danielbrownmsm Mar 25, 2023
1a284b5
Feat/wrist intake (#63)
danielbrownmsm Mar 25, 2023
25d4aeb
Merge branch 'scoring-integration' of https://github.com/Team-OKC-Rob…
danielbrownmsm Mar 25, 2023
298a021
fix intake wrist tilt encoder port
danielbrownmsm Mar 26, 2023
48aaeed
log the intake tilt output, setpoint, and sensor reading
danielbrownmsm Mar 26, 2023
b6f74a7
field-oriented intake tilting commands
danielbrownmsm Mar 26, 2023
0050fb7
wrap the tilt encoder because the zero-point is in a really annoying …
danielbrownmsm Mar 26, 2023
c7245a3
log the intake wrist values, and show them on shuffleboard,
danielbrownmsm Mar 26, 2023
917d674
if arm is close to 0 and trying to go to 0 then prevent it from oscil…
danielbrownmsm Mar 26, 2023
e5f1f32
reset gyro command bound to A-button
danielbrownmsm Mar 26, 2023
04c215f
added wrist setpoint to shuffleboard
danielbrownmsm Mar 26, 2023
e8aad74
made intake faster
danielbrownmsm Mar 26, 2023
5a33808
Merge branch 'master' into scoring-integration
danielbrownmsm Mar 26, 2023
895e017
started work on a command to pause auton execution for the arm
danielbrownmsm Mar 26, 2023
df3645d
Merge branch 'scoring-integration' of https://github.com/Team-OKC-Rob…
danielbrownmsm Mar 26, 2023
0408639
wrist setpoint on shuffleboard
danielbrownmsm Mar 27, 2023
fb8667c
fix extend thresholds/setpoints because we replaced the gearboxes
danielbrownmsm Mar 27, 2023
7b05742
intake wrist tilt tuning and fixing
danielbrownmsm Mar 27, 2023
3e82c1b
code no workey tilt then move claw arm thingy
danielbrownmsm Mar 27, 2023
563bdf3
Improved and Tuned Arm and Added ff to arm control
deadlyvortex Mar 28, 2023
7342a3c
fix arm setpoint, fix some intake setpoints, make the intake a little…
danielbrownmsm Mar 28, 2023
f466b8c
don't have the intake tilt to a 0 position inside the robot because w…
danielbrownmsm Mar 28, 2023
3cf9026
fix that last commit
danielbrownmsm Mar 28, 2023
cf670b0
log
danielbrownmsm Mar 28, 2023
61d5a25
make rhe a button have field-oriented human player station presets (t…
danielbrownmsm Mar 29, 2023
9e2d332
start work on a python arm vizualization script
danielbrownmsm Mar 30, 2023
24f12b4
Merge branch 'master' into Arm-Improvement-and-Tuning
danielbrownmsm Mar 30, 2023
53fa082
Merge branch 'feat/gyro-reset-button' into feat/GKC
danielbrownmsm Mar 30, 2023
5dd0f70
Merge branch 'Arm-Improvement-and-Tuning' into feat/GKC
danielbrownmsm Mar 30, 2023
deb2258
Merge branch 'feat/arm_viz' into feat/GKC
danielbrownmsm Mar 30, 2023
a0e9de3
made log-processing script only display the graphs if it's being run …
danielbrownmsm Mar 30, 2023
83f834e
expanded the arm-viz script so now we can actually visualize the arm …
danielbrownmsm Mar 30, 2023
ed4e7fc
add drawing the arm setpoint to the arm-viz script
danielbrownmsm Mar 30, 2023
fd3791f
fixed auton making the wrist go the wrong way
danielbrownmsm Mar 30, 2023
53faa18
raised intake power
danielbrownmsm Mar 30, 2023
c3c07dd
don't build unit tests at competition for faster deploy times
danielbrownmsm Mar 30, 2023
40a6894
fix setpoints
danielbrownmsm Mar 30, 2023
c924468
raise intake power, lower driving speed
danielbrownmsm Mar 30, 2023
ed27019
fix all the autos to use intake position
danielbrownmsm Mar 30, 2023
2804388
current limiting for intake
danielbrownmsm Mar 30, 2023
b81cee9
invert drive stick because it's going the wrong way
danielbrownmsm Mar 30, 2023
f5b2440
parameter tuning
danielbrownmsm Mar 30, 2023
0a8add1
palm the cube instead of intake it (we can't pick up cones from the g…
danielbrownmsm Mar 30, 2023
f61fdfa
actually use the length setpoint instead of moving both with the enco…
danielbrownmsm Mar 31, 2023
757c9c3
auto-balance tuning, invert strafing too, don't break our tilt at the…
danielbrownmsm Mar 31, 2023
d71c212
practice match logs
danielbrownmsm Mar 31, 2023
a00ebe4
competition logs
danielbrownmsm Mar 31, 2023
b9ecff9
honeslty not sure what I changed, don't care, also removed a bunch of…
danielbrownmsm Mar 31, 2023
080c5fa
Merge branch 'master' into feat/GKC
danielbrownmsm Apr 4, 2023
d588269
Merge branch 'feat/GKC' of https://github.com/Team-OKC-Robotics/FRC-2…
danielbrownmsm Apr 4, 2023
1ade41d
parameterize deadband stuff
danielbrownmsm Apr 4, 2023
bbf89e2
parameterize pid tolerances for the arm halfway
danielbrownmsm Apr 4, 2023
f1e7008
parameterized intake power in RobotContainer
danielbrownmsm Apr 5, 2023
b4b88fa
parametrized swerve commands
Apr 5, 2023
0f262c5
Merge branch 'master' into feat/more-parameterization
danielbrownmsm Apr 8, 2023
284a7ba
parametrized swerve steer
Apr 8, 2023
20c3dec
made the code built
Apr 8, 2023
2bc6c30
Merge branch 'master' into feat/more-parameterization
danielbrownmsm Apr 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <cameraserver/CameraServer.h>

void Robot::RobotInit() {
frc::CameraServer::StartAutomaticCapture().SetResolution(480, 240);
double res = RobotParams::GetParam("camera.res", 240);
frc::CameraServer::StartAutomaticCapture().SetResolution(2* res, res);

m_container.GetArm()->SetControlMode(Auto);
}
Expand Down
33 changes: 23 additions & 10 deletions src/main/cpp/RobotContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,29 @@ bool RobotContainer::InitCommands() {
score_preload_balance_auto_ = std::make_shared<ScorePreloadedBalanceAuto>(swerve_drive_, arm_, intake_);

// swerve commands
swerve_teleop_command_ = std::make_shared<TeleOpSwerveCommand>(swerve_drive_, gamepad1_, 0.8, 0.5, false); // speed mod, open loop
slow_swerve_teleop_command_ = std::make_shared<TeleOpSwerveCommand>(swerve_drive_, gamepad1_, 0.5, 1, true); // brake mode
fast_swerve_teleop_command_ = std::make_shared<TeleOpSwerveCommand>(swerve_drive_, gamepad1_, 1.5, 0.1, false); // BOOOOOOOOOST
double speed_mod = RobotParams::GetParam("swerve.speed_mod", 0.8);
double open_loop = RobotParams::GetParam("swerve.swerve_open_loop", 0.5);
double braking_speed_mod = RobotParams::GetParam("swerve.braking_speed_mod", 0.5);
double braking_open_loop = RobotParams::GetParam("swerve.swerve_braking_open_loop", 1);
double fast_speed_mod = RobotParams::GetParam("swerve.fast_speed_mod", 1.5);
double fast_open_loop = RobotParams::GetParam("swerve.swerve_fast_open_loop", 0.1);

swerve_teleop_command_ = std::make_shared<TeleOpSwerveCommand>(swerve_drive_, gamepad1_, speed_mod, open_loop, false); // speed mod, open loop
slow_swerve_teleop_command_ = std::make_shared<TeleOpSwerveCommand>(swerve_drive_, gamepad1_, braking_speed_mod, braking_open_loop, true); // brake mode
fast_swerve_teleop_command_ = std::make_shared<TeleOpSwerveCommand>(swerve_drive_, gamepad1_, fast_speed_mod, fast_open_loop, false); // BOOOOOOOOOST

reset_gyro_command_ = std::make_shared<ResetGyroCommand>(swerve_drive_);
OKC_CHECK(swerve_teleop_command_ != nullptr);

// test arm commands
extendArmCommand = std::make_shared<IncrementArmExtendCommand>(arm_, 0.5);
retractArmCommand = std::make_shared<IncrementArmExtendCommand>(arm_, -0.5);
double extend = RobotParams::GetParam("arm.extend", 0.5);
double position_increment = RobotParams::GetParam("arm.position_increment", 0.5);

extendArmCommand = std::make_shared<IncrementArmExtendCommand>(arm_, extend);
retractArmCommand = std::make_shared<IncrementArmExtendCommand>(arm_, -extend);

raiseArmCommand = std::make_shared<IncrementArmPresetPositionCommand>(arm_, 0.5);
lowerArmCommand = std::make_shared<IncrementArmPresetPositionCommand>(arm_, -0.5);
raiseArmCommand = std::make_shared<IncrementArmPresetPositionCommand>(arm_, position_increment);
lowerArmCommand = std::make_shared<IncrementArmPresetPositionCommand>(arm_, -position_increment);

// arm commands
arm_carry_command_ = std::make_shared<ArmSetStateCommand>(arm_, TeamOKC::ArmState(1, 0));
Expand All @@ -351,9 +361,12 @@ bool RobotContainer::InitCommands() {
arm_human_player_command_ = std::make_shared<ArmFieldOrientedCommand>(arm_, swerve_drive_, TeamOKC::ArmState(negative_human_player_extension_, negative_human_player_rotation_), TeamOKC::ArmState(human_player_extension_, human_player_rotation_));

// intake commands
intake_command = std::make_shared<IntakeCommand>(intake_, 0.7);
other_intake_command = std::make_shared<IntakeCommand>(intake_, -0.7);
stop_intake_command = std::make_shared<IntakeCommand>(intake_, -0.03);
double intake_power = RobotParams::GetParam("intake.intake_power", 0.7);
double idle_intake_power = RobotParams::GetParam("intake.idle_power", -0.03);

intake_command = std::make_shared<IntakeCommand>(intake_, intake_power);
other_intake_command = std::make_shared<IntakeCommand>(intake_, -intake_power);
stop_intake_command = std::make_shared<IntakeCommand>(intake_, idle_intake_power);

return true;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/cpp/SwerveModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ bool SwerveModule::Init(Location loc) {
steer_pid_ = std::make_shared<frc::PIDController>(steer_kP, steer_kI, steer_kD);

OKC_CHECK(this->steer_pid_ != nullptr);
steer_pid_->EnableContinuousInput(-180, 180);
steer_pid_->SetTolerance(2, 2); // tolerate 2 degrees of deviation, which shouldn't be a lot I don't think
double steer_pid_degrees = RobotParams::GetParam("swerve.steer_pid.degrees", 180);
double steer_pid_degrees_tolerance = RobotParams::GetParam("swerve.steer_pid.tolerance", 2);
steer_pid_->EnableContinuousInput(-steer_pid_degrees, steer_pid_degrees);
steer_pid_->SetTolerance(steer_pid_degrees_tolerance, steer_pid_degrees_tolerance); // tolerate 2 degrees of deviation, which shouldn't be a lot I don't think

// units and conversions and numbers and stuff
L2_GEAR_RATIO_ = RobotParams::GetParam("swerve.l2_gear_ratio", 6.75);
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/autos/ScorePreloadedNoDriveAuto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ ScorePreloadedNoDriveAuto::ScorePreloadedNoDriveAuto(std::shared_ptr<Arm> arm, s
frc2::WaitCommand(units::second_t(1)), // wait for cube to be dropped
IntakeCommand(intake, 0), // stop the intake
ArmSetStateCommand(arm, TeamOKC::ArmState(0.5, 0)), // bring the arm back in the robot
frc2::WaitCommand(units::second_t(4)) // wait a second so the arm is mostly in
frc2::WaitCommand(units::second_t(4)) // wait a second so the arm is mostly in0
);
}
15 changes: 8 additions & 7 deletions src/main/cpp/subsystems/Arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ bool Arm::Init() {
double arm_kD = RobotParams::GetParam("arm.lift_pid.kD", 0.0);
double arm_kF = RobotParams::GetParam("arm.lift_pid.kF", 0.05);
arm_pid_ = std::make_shared<frc::PIDController>(arm_kP, arm_kI, arm_kD);
arm_pid_->SetTolerance(2.5, 3.0);

double arm_pos_tol = RobotParams::GetParam("arm.arm_pos_tolerance", 2.5);
double arm_vel_tol = RobotParams::GetParam("arm.arm_vel_tolerance", 3.0);
arm_pid_->SetTolerance(arm_pos_tol, arm_vel_tol);
arm_kF_ = arm_kF;

double extend_kP = RobotParams::GetParam("arm.extend_pid.kP", 0.005);
Expand All @@ -35,6 +38,7 @@ bool Arm::Init() {
// pull limits from the parameters file
lift_limit_ = RobotParams::GetParam("arm.lift_limit", 100.0);
extend_limit_ = RobotParams::GetParam("arm.extend_limit", 100.0);
double calibration_power_ = RobotParams::GetParam("arm.extend_power", 69);

// initialize with default state
state_ = TeamOKC::ArmState(0, 0);
Expand Down Expand Up @@ -208,7 +212,7 @@ bool Arm::AutoControl() {
std::cout << "CALIBRATION COMPLETE" << std::endl;
} else {
// otherwise, we haven't hit it yet, so set the motor to a small negative power until we do
this->interface_->arm_extend_power = -0.1;
this->interface_->arm_extend_power = calibration_power_;
}

return true;
Expand All @@ -226,7 +230,7 @@ bool Arm::AutoControl() {
this->inches_pid_->SetSetpoint(0.5);

// if we have brought the extension in
if (abs(1.0 - state_.extension) < 1.0) {
if (inches_pid_->AtSetpoint()) {
// then move the arm
this->arm_pid_->SetSetpoint(this->desired_state_.rotation);
this->interface_->arm_lift_power = this->arm_pid_->Calculate(this->interface_->arm_duty_cycle_encoder);
Expand All @@ -237,7 +241,7 @@ bool Arm::AutoControl() {
this->interface_->arm_extend_power = this->inches_pid_->Calculate(this->interface_->arm_extend_encoder);

// if we've reached our desired rotation
if (abs(desired_state_.rotation - state_.rotation) < 2) {
if (arm_pid_->AtSetpoint()) {
// move to the next stage
this->control_state_ = EXTENDING;
}
Expand Down Expand Up @@ -290,9 +294,6 @@ void Arm::Periodic() {
case Auto:
VOKC_CALL(this->AutoControl());
break;
case Manual:
VOKC_CALL(this->ManualControl());
break;
default:
VOKC_CHECK_MSG(false, "Unhandled enum");
}
Expand Down
24 changes: 15 additions & 9 deletions src/main/cpp/subsystems/SwerveDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ bool SwerveDrive::Init() {
// Initialize Shuffleboard from parameters.
OKC_CALL(InitShuffleboard());

turn_deadband_ = RobotParams::GetParam("swerve.turn_deadband", 0.3);
strafe_deadband_ = RobotParams::GetParam("swerve.strafe_deadband", 0.15);
drive_deadband_ = RobotParams::GetParam("swerve.drive_deadband", 0.1);
invert_threshold_ = RobotParams::GetParam("swerve.invert_threshold", 100);
center_deadband_ = RobotParams::GetParam("swerve.center_deadband", 0.05);

left_front_setpoint_log_ = wpi::log::DoubleLogEntry(TeamOKC::log, "/swerve/setpoint");
left_front_output_log_ = wpi::log::DoubleLogEntry(TeamOKC::log, "/swerve/output");
left_front_steer_enc_log_ = wpi::log::DoubleLogEntry(TeamOKC::log, "/swerve/steer_enc");
Expand Down Expand Up @@ -158,17 +164,17 @@ bool SwerveDrive::VectorTeleOpDrive(const double &drive, const double &strafe, c
double turn_ = turn;

// if turn is very small
if (abs(turn) < 0.3) {
if (abs(turn) < turn_deadband_) {
turn_ = 0.0; // then zero it
// } else if (final_turn)
}

// if strafe is very small
if (abs(strafe) < 0.15) {
if (abs(strafe) < strafe_deadband_) {
strafe_ = 0.0; // then zero it
}

if (abs(drive) < 0.1) {
if (abs(drive) < drive_deadband_) {
drive_ = 0.0;
}

Expand Down Expand Up @@ -225,22 +231,22 @@ bool SwerveDrive::VectorTeleOpDrive(const double &drive, const double &strafe, c
* but it would be better to simply invert the direction that the drive motor/wheel is spinning, like normal
* differential drivetrains do. So you should never need to steer more than 90 degrees.
*/
if (abs(left_front_angle - left_front_turn) > 100) {
if (abs(left_front_angle - left_front_turn) > invert_threshold_) {
left_front_turn -= 180;
left_front_speed *= -1;
}

if (abs(left_back_angle - left_back_turn) > 100) {
if (abs(left_back_angle - left_back_turn) > invert_threshold_) {
left_back_turn -= 180;
left_back_speed *= -1;
}

if (abs(right_front_angle - right_front_turn) > 100) {
if (abs(right_front_angle - right_front_turn) > invert_threshold_) {
right_front_turn -= 180;
right_front_speed *= -1;
}

if (abs(right_back_angle - right_back_turn) > 100) {
if (abs(right_back_angle - right_back_turn) > invert_threshold_) {
right_back_turn -= 180;
right_back_speed *= -1;
}
Expand All @@ -264,14 +270,14 @@ bool SwerveDrive::VectorTeleOpDrive(const double &drive, const double &strafe, c
// really nice convoluted deadband
// this is to stop the swerve modules from immediately trying to center themselves instead of
// coasting until receiving another instruction so we don't tip
if (abs(drive_) > 0.05 || abs(strafe_) > 0.05 || abs(turn_) > 0.3) {
if (abs(drive_) > center_deadband_ || abs(strafe_) > center_deadband_ || abs(turn_) > center_deadband_) {
OKC_CALL(this->left_front_module_->SetAngle(left_front_turn));
OKC_CALL(this->left_back_module_->SetAngle(left_back_turn));
OKC_CALL(this->right_front_module_->SetAngle(right_front_turn));
OKC_CALL(this->right_back_module_->SetAngle(right_back_turn));
}

if (abs(drive_) < 0.05 && abs(strafe_) < 0.05 && abs(turn_) < 0.3) {
if (abs(drive_) < center_deadband_ && abs(strafe_) < center_deadband_ && abs(turn_) < center_deadband_) {
this->interface_->left_front_drive_motor_output = 0.0;
this->interface_->left_back_drive_motor_output = 0.0;
this->interface_->right_front_drive_motor_output = 0.0;
Expand Down
25 changes: 24 additions & 1 deletion src/main/deploy/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ drive_open_loop = 1
steer_max_output = 1
steer_open_loop = 0.0
slew_limit = 2
turn_deadband_ = 0.3
strafe_deadband_ = 0.15
drive_deadband_ = 0.1
invert_threshold_ = 100.0
center_deadband_ = 0.05
speed_mod = 0.8
swerve_open_loop = 0.5
braking_speed_mod = 0.5
braking_open_loop = 1
fast_speed_mod = 1.5
fast_swerve_open_loop = 0.1

[swerve.dist_pid]
kP = 0.5
Expand All @@ -41,6 +52,8 @@ kD = 0.0
kP = 0.005
kI = 0.0
kD = 0.000005
degrees = 180
tolerance = 2

[swerve.heading_pid]
kP = 0.04
Expand Down Expand Up @@ -70,6 +83,11 @@ extend_limit = 95
max_output = 0.7
arm_open_loop = 10
extend_open_loop = 10
arm_pos_tolerance = 2.5
arm_vel_tolerance = 3.0
extend = 0.5
position_increment
extend_power = 69

# right in front of the robot to pick stuff up
[arm.pickup]
Expand Down Expand Up @@ -135,8 +153,13 @@ kD = 0

[intake]
tilt_offset = -55.0
intake_power = 0.7
idle_power = -0.03

[intake.wrist_pid]
kP = 0.005
kI = 0.0
kD = 0.0
kD = 0.0

[camera]
res = 240
1 change: 1 addition & 0 deletions src/main/include/subsystems/Arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Arm : public frc2::SubsystemBase {

double lift_power_;
double extend_power_;
double calibration_power_;

// logs
wpi::log::DoubleLogEntry arm_lift_output_log_;
Expand Down
6 changes: 6 additions & 0 deletions src/main/include/subsystems/SwerveDrive.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class SwerveDrive : public frc2::SubsystemBase {

double control_decay = 0.1;

double turn_deadband_;
double strafe_deadband_;
double drive_deadband_;
double invert_threshold_;
double center_deadband_;

// auton
bool probably_balanced_ = false;
float last_pitch_ = 0.0;
Expand Down