From d960b35b25b78f15103bbd592bf8ef5c75f03405 Mon Sep 17 00:00:00 2001 From: THERocky <101498190+Rocky14683@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:00:53 +0800 Subject: [PATCH] set brake mode bug fix (#106) * change set_brake_mode to set_brake_mode_all --- src/VOSS/chassis/DiffChassis.cpp | 157 ++++++++++++++++--------------- src/main.cpp | 2 +- 2 files changed, 80 insertions(+), 79 deletions(-) diff --git a/src/VOSS/chassis/DiffChassis.cpp b/src/VOSS/chassis/DiffChassis.cpp index ba7a1057..7c424957 100644 --- a/src/VOSS/chassis/DiffChassis.cpp +++ b/src/VOSS/chassis/DiffChassis.cpp @@ -35,8 +35,8 @@ DiffChassis::DiffChassis(std::initializer_list 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}; } @@ -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); } diff --git a/src/main.cpp b/src/main.cpp index eb97a14b..32bb1917 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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);