Skip to content

Commit

Permalink
Relative move (#71)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Rocky14683 and github-actions[bot] authored Mar 19, 2024
1 parent 89a77d1 commit 1bb7f5e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
9 changes: 9 additions & 0 deletions include/VOSS/chassis/AbstractChassis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ class AbstractChassis {
virtual bool execute(DiffChassisCommand cmd, double max) = 0;
virtual void set_brake_mode(pros::motor_brake_mode_e mode) = 0;

void move(double distance, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);

void move(double distance, controller_ptr controller, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);

void move(double distance, controller_ptr controller, ec_ptr ec,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);

void move(Pose target, controller_ptr controller, ec_ptr ec,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);

Expand Down
8 changes: 7 additions & 1 deletion include/VOSS/utils/flags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,11 @@ auto inline operator&(Flags flag1, Flags flag2) {
static_cast<uint8_t>(flag2));
}

enum class AngularDirection { AUTO, COUNTERCLOCKWISE, CLOCKWISE };
enum class AngularDirection {
AUTO,
COUNTERCLOCKWISE,
CCW = COUNTERCLOCKWISE,
CLOCKWISE,
CW = CLOCKWISE
};
} // namespace voss
17 changes: 17 additions & 0 deletions src/VOSS/chassis/AbstractChassis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ void AbstractChassis::turn_task(controller_ptr controller, ec_ptr ec,
this->task->join();
}

void AbstractChassis::move(double distance, double max, voss::Flags flags) {
this->move({distance, 0}, this->default_controller, this->default_ec, max,
flags | voss::Flags::RELATIVE);
}

void AbstractChassis::move(double distance, controller_ptr controller,
double max, voss::Flags flags) {
this->move({distance, 0}, std::move(controller), this->default_ec, max,
flags | voss::Flags::RELATIVE);
}

void AbstractChassis::move(double distance, controller_ptr controller,
ec_ptr ec, double max, voss::Flags flags) {
this->move({distance, 0}, std::move(controller), std::move(ec), max,
flags | Flags::RELATIVE);
}

void AbstractChassis::move(Pose target, double max, voss::Flags flags) {
this->move(target, this->default_controller, this->default_ec, max, flags);
}
Expand Down
2 changes: 2 additions & 0 deletions src/VOSS/chassis/DiffChassis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +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->prev_voltages = {0, 0};
}

Expand Down
1 change: 1 addition & 0 deletions src/VOSS/controller/BoomerangController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ BoomerangController::get_command(bool reverse, bool thru,
} else {
// turn to face the finale pose angle if executing a pose movement
double poseError = target.theta.value() - current_angle;

while (fabs(poseError) > M_PI)
poseError -= 2 * M_PI * poseError / fabs(poseError);
ang_speed = angular_pid(poseError);
Expand Down
1 change: 1 addition & 0 deletions src/VOSS/controller/PIDController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ PIDController::get_command(bool reverse, bool thru,
} else {
// turn to face the finale pose angle if executing a pose movement
double poseError = target.theta.value() - current_angle;

while (fabs(poseError) > M_PI)
poseError -= 2 * M_PI * poseError / fabs(poseError);
ang_speed = angular_pid(poseError);
Expand Down
1 change: 0 additions & 1 deletion src/VOSS/localizer/AbstractLocalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Pose AbstractLocalizer::get_pose() {
std::unique_lock<pros::Mutex> lock(this->mtx);
Pose ret = {this->pose.x.load(), this->pose.y.load(),
this->pose.theta.load()};

return ret;
}

Expand Down

0 comments on commit 1bb7f5e

Please sign in to comment.