Skip to content

Commit

Permalink
set brake mode bug fix (#106)
Browse files Browse the repository at this point in the history
* change set_brake_mode to set_brake_mode_all
  • Loading branch information
Rocky14683 authored Jun 28, 2024
1 parent ddec0fd commit d960b35
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 79 deletions.
157 changes: 79 additions & 78 deletions src/VOSS/chassis/DiffChassis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ DiffChassis::DiffChassis(std::initializer_list<int8_t> left_motors,

this->slew_step = slew_step > 0 ? slew_step : 200;
this->brakeMode = brakeMode;
this->left_motors->set_brake_mode(this->brakeMode);
this->right_motors->set_brake_mode(this->brakeMode);
this->left_motors->set_brake_mode_all(this->brakeMode);
this->right_motors->set_brake_mode_all(this->brakeMode);
this->prev_voltages = {0, 0};
}

Expand All @@ -55,88 +55,89 @@ void DiffChassis::arcade(double forward_speed, double turn_speed) {

void DiffChassis::set_brake_mode(pros::motor_brake_mode_e mode) {
this->brakeMode = mode;
this->left_motors->set_brake_mode(mode);
this->right_motors->set_brake_mode(mode);
this->left_motors->set_brake_mode_all(mode);
this->right_motors->set_brake_mode_all(mode);
}

// Evoke the chassis to move according to how it was set up using the
// constructor, returns true if movement is complete
bool DiffChassis::execute(DiffChassisCommand cmd, double max) {
return std::visit(
overload{
[this](Stop&) -> bool {
this->set_brake_mode(this->brakeMode);
this->left_motors->brake();
this->right_motors->brake();

return true;
},
[this, max](diff_commands::Voltages& v) -> bool {
double v_max = std::max(fabs(v.left), fabs(v.right));
if (v_max > max) {
v.left = v.left * max / v_max;
v.right = v.right * max / v_max;
}

v.left = slew(v.left, true);
v.right = slew(v.right, false);

this->left_motors->move_voltage(120 * v.left);
this->right_motors->move_voltage(120 * v.right);

this->prev_voltages = v;

return false;
},
// Logic allowing for individual movements within a chain of
// movements to be registered at completed even though robot may
// still be moving
[this, max](diff_commands::Chained& v) -> bool {
double v_max = std::max(fabs(v.left), fabs(v.right));
if (v_max > max) {
v.left = v.left * max / v_max;
v.right = v.right * max / v_max;
}

v.left = slew(v.left, true);
v.right = slew(v.right, false);

this->left_motors->move_voltage(120 * v.left);
this->right_motors->move_voltage(120 * v.right);

this->prev_voltages = {v.left, v.right};

return true;
},
// Logic to brake one side of the drive alloing for a turn around
// the side of the robot and returning true when the turn is
// finished
[this, max](diff_commands::Swing& v) {
double v_max = std::max(fabs(v.left), fabs(v.right));
if (v.right == 0) {
this->right_motors->set_brake_mode(pros::MotorBrake::hold);
this->right_motors->brake();
if (v_max > max) {
v.left = v.left * max / v_max;
}
v.left = slew(v.left, true);
this->left_motors->move_voltage(120 * v.left);
this->prev_voltages = {v.left, 0.0};

} else if (v.left == 0) {
this->left_motors->set_brake_mode(pros::MotorBrake::hold);
this->left_motors->brake();
if (v_max > max) {
v.right = v.right * max / v_max;
}
v.right = slew(v.right, false);

this->right_motors->move_voltage(120 * v.right);
this->prev_voltages = {0.0, v.right};
}

return false;
}},
overload{[this](Stop&) -> bool {
this->set_brake_mode(this->brakeMode);
this->left_motors->brake();
this->right_motors->brake();

return true;
},
[this, max](diff_commands::Voltages& v) -> bool {
double v_max = std::max(fabs(v.left), fabs(v.right));
if (v_max > max) {
v.left = v.left * max / v_max;
v.right = v.right * max / v_max;
}

v.left = slew(v.left, true);
v.right = slew(v.right, false);

this->left_motors->move_voltage(120 * v.left);
this->right_motors->move_voltage(120 * v.right);

this->prev_voltages = v;

return false;
},
// Logic allowing for individual movements within a chain of
// movements to be registered at completed even though robot
// may still be moving
[this, max](diff_commands::Chained& v) -> bool {
double v_max = std::max(fabs(v.left), fabs(v.right));
if (v_max > max) {
v.left = v.left * max / v_max;
v.right = v.right * max / v_max;
}

v.left = slew(v.left, true);
v.right = slew(v.right, false);

this->left_motors->move_voltage(120 * v.left);
this->right_motors->move_voltage(120 * v.right);

this->prev_voltages = {v.left, v.right};

return true;
},
// Logic to brake one side of the drive alloing for a turn
// around the side of the robot and returning true when the
// turn is finished
[this, max](diff_commands::Swing& v) {
double v_max = std::max(fabs(v.left), fabs(v.right));
if (v.right == 0) {
this->right_motors->set_brake_mode_all(
pros::MotorBrake::hold);
this->right_motors->brake();
if (v_max > max) {
v.left = v.left * max / v_max;
}
v.left = slew(v.left, true);
this->left_motors->move_voltage(120 * v.left);
this->prev_voltages = {v.left, 0.0};

} else if (v.left == 0) {
this->left_motors->set_brake_mode_all(
pros::MotorBrake::hold);
this->left_motors->brake();
if (v_max > max) {
v.right = v.right * max / v_max;
}
v.right = slew(v.right, false);

this->right_motors->move_voltage(120 * v.right);
this->prev_voltages = {0.0, v.right};
}

return false;
}},
cmd);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ auto ec = voss::controller::ExitConditions::new_conditions()
return master.get_digital(pros::E_CONTROLLER_DIGITAL_UP);
});

auto chassis = voss::chassis::DiffChassis(LEFT_MOTORS, RIGHT_MOTORS, pid, ec,
auto chassis = voss::chassis::DiffChassis(LEFT_MOTORS, RIGHT_MOTORS, pid, ec, 8,
pros::E_MOTOR_BRAKE_COAST);

pros::IMU imu(16);
Expand Down

0 comments on commit d960b35

Please sign in to comment.