Skip to content

Commit

Permalink
added exit time condition (#51)
Browse files Browse the repository at this point in the history
* added exit time condition

* changed timer to early return

* add timer example

* Committing clang-format changes

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Brandon-Liu and github-actions[bot] authored Feb 13, 2024
1 parent cc4405e commit 6fbacfd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 30 deletions.
25 changes: 15 additions & 10 deletions include/VOSS/chassis/AbstractChassis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class AbstractChassis {
controller::AbstractController* default_controller;

void move_task(controller::AbstractController* controller, double max,
voss::Flags flags);
voss::Flags flags, double exitTime);

void turn_task(controller::AbstractController* controller, double max,
voss::Flags flags);
voss::Flags flags, double exitTime);

public:
AbstractChassis(controller::AbstractController& default_controller);
Expand All @@ -33,22 +33,27 @@ class AbstractChassis {
virtual bool execute(ChassisCommand cmd, double max) = 0;

void move(Point target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
double max = 100.0, voss::Flags flags = voss::Flags::NONE,
double exitTime = 22500);
void move(Pose target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
double max = 100.0, voss::Flags flags = voss::Flags::NONE,
double exitTime = 22500);
void move(Point target, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);
voss::Flags flags = voss::Flags::NONE, double exitTime = 22500);
void move(Pose target, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);
voss::Flags flags = voss::Flags::NONE, double exitTime = 22500);

void turn(double target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
double max = 100.0, voss::Flags flags = voss::Flags::NONE,
double exitTime = 22500);
void turn(double target, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);
voss::Flags flags = voss::Flags::NONE, double exitTime = 22500);
void turn_to(Point target, controller::AbstractController* controller,
double max = 100.0, voss::Flags flags = voss::Flags::NONE);
double max = 100.0, voss::Flags flags = voss::Flags::NONE,
double exitTime = 22500);
void turn_to(Point target, double max = 100.0,
voss::Flags flags = voss::Flags::NONE);
voss::Flags flags = voss::Flags::NONE,
double exitTime = 22500);
};

} // namespace voss::chassis
56 changes: 37 additions & 19 deletions src/VOSS/chassis/AbstractChassis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ AbstractChassis::AbstractChassis(
}

void AbstractChassis::move_task(controller::AbstractController* controller,
double max, voss::Flags flags) {

double max, voss::Flags flags,
double exitTime) {
int t = 0;
pros::Task running_t([&, controller]() {
controller->reset();
while (
Expand All @@ -21,6 +22,11 @@ void AbstractChassis::move_task(controller::AbstractController* controller,
if (pros::competition::is_disabled()) {
return;
}
if (t > exitTime) {
return;
}

t += 10;
pros::delay(10);
}
// this->m.give();
Expand All @@ -37,7 +43,9 @@ void AbstractChassis::move_task(controller::AbstractController* controller,
}

void AbstractChassis::turn_task(controller::AbstractController* controller,
double max, voss::Flags flags) {
double max, voss::Flags flags,
double exitTime) {
int t = 0;
pros::Task running_t([&, controller]() {
controller->reset();
while (!this->execute(
Expand All @@ -47,6 +55,12 @@ void AbstractChassis::turn_task(controller::AbstractController* controller,
if (pros::competition::is_disabled()) {
return;
}

if (t > exitTime) {
return;
}

t += 10;
pros::delay(10);
}
});
Expand All @@ -58,59 +72,63 @@ void AbstractChassis::turn_task(controller::AbstractController* controller,
running_t.join();
}

void AbstractChassis::move(Point target, double max, voss::Flags flags) {
this->move(target, this->default_controller, max, flags);
void AbstractChassis::move(Point target, double max, voss::Flags flags,
double exitTime) {
this->move(target, this->default_controller, max, flags, exitTime);
}

void AbstractChassis::move(Pose target, double max, voss::Flags flags) {
this->move(target, this->default_controller, max, flags);
void AbstractChassis::move(Pose target, double max, voss::Flags flags,
double exitTime) {
this->move(target, this->default_controller, max, flags, exitTime);
}

void AbstractChassis::move(Point target,
controller::AbstractController* controller,
double max, voss::Flags flags) {
double max, voss::Flags flags, double exitTime) {
Pose pose_target = Pose{target.x, target.y, 361};
this->move(pose_target, controller, max, flags);
this->move(pose_target, controller, max, flags, exitTime);
}

void AbstractChassis::move(Pose target,
controller::AbstractController* controller,
double max, voss::Flags flags) {
double max, voss::Flags flags, double exitTime) {
// this->m.take();

controller->set_target(target, flags & voss::Flags::RELATIVE);

this->move_task(controller, max, flags);
this->move_task(controller, max, flags, exitTime);
}

void AbstractChassis::turn(double target, double max, voss::Flags flags) {
this->turn(target, this->default_controller, max, flags);
void AbstractChassis::turn(double target, double max, voss::Flags flags,
double exitTime) {
this->turn(target, this->default_controller, max, flags, exitTime);
}

void AbstractChassis::turn(double target,
controller::AbstractController* controller,
double max, voss::Flags flags) {
double max, voss::Flags flags, double exitTime) {
// this->m.take();

controller->set_target({0, 0, 0}, false);
controller->set_angular_target(target, flags & voss::Flags::RELATIVE);

this->turn_task(controller, max, flags);
this->turn_task(controller, max, flags, exitTime);
}

void AbstractChassis::turn_to(Point target, double max, voss::Flags flags) {
this->turn_to(target, this->default_controller, max, flags);
void AbstractChassis::turn_to(Point target, double max, voss::Flags flags,
double exitTime) {
this->turn_to(target, this->default_controller, max, flags, exitTime);
}

void AbstractChassis::turn_to(Point target,
controller::AbstractController* controller,
double max, voss::Flags flags) {
double max, voss::Flags flags, double exitTime) {
// this->m.take();

controller->set_target({target.x, target.y, 361},
flags & voss::Flags::RELATIVE);

this->turn_task(controller, max, flags);
this->turn_task(controller, max, flags, exitTime);
}

} // namespace voss::chassis
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void opcontrol() {

if (master.get_digital_new_press(DIGITAL_Y)) {
odom->set_pose(voss::Pose{0.0, 0.0, 0});
chassis.turn(90, &swing, 100, voss::Flags::RELATIVE);
chassis.turn(180, 100, voss::Flags::NONE, 10000);
}

pros::lcd::clear_line(1);
Expand Down

0 comments on commit 6fbacfd

Please sign in to comment.