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

Implement chained(thru) boomerang motion #36

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion include/VOSS/chassis/ChassisCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ struct Voltages {
double left;
double right;
};
struct Chained {
double left;
double right;
};

using ChassisCommand = std::variant<Stop, Voltages>;
using ChassisCommand = std::variant<Stop, Voltages, Chained>;

template <class... Ts> struct overload : Ts... {
using Ts::operator()...;
Expand Down
20 changes: 19 additions & 1 deletion src/VOSS/chassis/DiffChassis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,25 @@ bool DiffChassis::execute(ChassisCommand cmd, double max) {
this->prev_voltages = v;

return false;
}},
},
[this, max](Chained& v){
if (fabs(v.left) > max) {
v.left = max * ((v.left < 0) ? -1 : 1);
}
if (fabs(v.right) > max) {
v.right = max * ((v.right < 0) ? -1 : 1);
}

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;
}},
cmd);
}

Expand Down
37 changes: 22 additions & 15 deletions src/VOSS/controller/PIDController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PIDController::PIDController(std::shared_ptr<localizer::AbstractLocalizer> l)

chassis::ChassisCommand PIDController::get_command(bool reverse, bool thru) {
Point current_pos = this->l->get_position();

bool chainedExecutable = false;
bool noPose = this->target.theta == 361;

double dx = target.x - current_pos.x;
Expand All @@ -29,23 +29,26 @@ chassis::ChassisCommand PIDController::get_command(bool reverse, bool thru) {

angle_error = voss::norm_delta(angle_error);

if (distance_error <= exit_error || (distance_error < min_error && fabs(cos(angle_error)) <= 0.1)) {
total_lin_err = 0;
close += 10;
} else {
close = 0;
}
double lin_speed;



if (distance_error <= exit_error || (distance_error < min_error && fabs(cos(angle_error)) <= 0.1)) {
if(thru) {
chainedExecutable = true;
} else {
total_lin_err = 0;
close += 10;
}
} else {
close = 0;
}

if (close > settle_time) {
return chassis::ChassisCommand{chassis::Stop{}};
}

double lin_speed;
if (thru) {
lin_speed = 100;
} else {
lin_speed = linear_pid(distance_error) * (reverse ? -1 : 1);
}
lin_speed = thru ? 100.0 : (linear_pid(distance_error) * (reverse ? -1 : 1));

double ang_speed;
if (distance_error < min_error) {
Expand Down Expand Up @@ -74,9 +77,13 @@ chassis::ChassisCommand PIDController::get_command(bool reverse, bool thru) {

ang_speed = angular_pid(angle_error);
}
if(chainedExecutable){
return chassis::ChassisCommand{
chassis::Chained{100.0 - ang_speed, 100.0 + ang_speed}};
}

return chassis::ChassisCommand{
chassis::Voltages{lin_speed - ang_speed, lin_speed + ang_speed}};
return chassis::ChassisCommand{
chassis::Voltages{lin_speed - ang_speed, lin_speed + ang_speed}};
}

chassis::ChassisCommand PIDController::get_angular_command(bool reverse,
Expand Down