diff --git a/include/VOSS/chassis/AbstractChassis.hpp b/include/VOSS/chassis/AbstractChassis.hpp index 22c43818..94c46f57 100644 --- a/include/VOSS/chassis/AbstractChassis.hpp +++ b/include/VOSS/chassis/AbstractChassis.hpp @@ -21,7 +21,7 @@ class AbstractChassis { controller_ptr default_controller; ec_ptr default_ec; std::unique_ptr task = nullptr; - bool task_running = false; + std::atomic_bool task_running = false; pros::motor_brake_mode_e brakeMode; void move_task(controller_ptr controller, ec_ptr ec, double max, @@ -39,6 +39,9 @@ class AbstractChassis { virtual bool execute(DiffChassisCommand cmd, double max) = 0; virtual void set_brake_mode(pros::motor_brake_mode_e mode) = 0; + void wait_until_settled() const; + bool is_settled() const; + void move(double distance, double max = 100.0, voss::Flags flags = voss::Flags::NONE); diff --git a/src/VOSS/chassis/AbstractChassis.cpp b/src/VOSS/chassis/AbstractChassis.cpp index 6774622a..5bf971ad 100644 --- a/src/VOSS/chassis/AbstractChassis.cpp +++ b/src/VOSS/chassis/AbstractChassis.cpp @@ -154,7 +154,7 @@ void AbstractChassis::turn_to(Point target, controller_ptr controller, ec_ptr ec, double max, voss::Flags flags, voss::AngularDirection direction) { while (this->task_running) { - pros::delay(10); + pros::delay(constants::MOTOR_UPDATE_DELAY); } this->task_running = true; @@ -165,4 +165,14 @@ void AbstractChassis::turn_to(Point target, controller_ptr controller, direction); } +void AbstractChassis::wait_until_settled() const { + while (this->task_running) { + pros::delay(constants::MOTOR_UPDATE_DELAY); + } +} + +bool AbstractChassis::is_settled() const { + return this->task_running; +} + } // namespace voss::chassis \ No newline at end of file