diff --git a/include/VOSS/chassis/AbstractChassis.hpp b/include/VOSS/chassis/AbstractChassis.hpp index b0b54d5..3711f8e 100644 --- a/include/VOSS/chassis/AbstractChassis.hpp +++ b/include/VOSS/chassis/AbstractChassis.hpp @@ -12,30 +12,32 @@ namespace voss::chassis { +using controller_ptr = std::shared_ptr; + class AbstractChassis { protected: pros::Mutex m; - controller::AbstractController* default_controller; + controller_ptr default_controller; - void move_task(controller::AbstractController* controller, double max, + void move_task(controller_ptr controller, double max, voss::Flags flags, double exitTime); - void turn_task(controller::AbstractController* controller, double max, + void turn_task(controller_ptr controller, double max, voss::Flags flags, double exitTime); public: - AbstractChassis(controller::AbstractController& default_controller); + AbstractChassis(controller_ptr default_controller); virtual void tank(double left_speed, double right_speed) = 0; virtual void arcade(double forward_speed, double turn_speed) = 0; virtual bool execute(ChassisCommand cmd, double max) = 0; - void move(Point target, controller::AbstractController* controller, + void move(Point target, controller_ptr controller, double max = 100.0, voss::Flags flags = voss::Flags::NONE, double exitTime = 22500); - void move(Pose target, controller::AbstractController* controller, + void move(Pose target, controller_ptr controller, double max = 100.0, voss::Flags flags = voss::Flags::NONE, double exitTime = 22500); void move(Point target, double max = 100.0, @@ -43,12 +45,12 @@ class AbstractChassis { void move(Pose target, double max = 100.0, voss::Flags flags = voss::Flags::NONE, double exitTime = 22500); - void turn(double target, controller::AbstractController* controller, + void turn(double target, controller_ptr controller, 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, double exitTime = 22500); - void turn_to(Point target, controller::AbstractController* controller, + void turn_to(Point target, controller_ptr controller, double max = 100.0, voss::Flags flags = voss::Flags::NONE, double exitTime = 22500); void turn_to(Point target, double max = 100.0, diff --git a/include/VOSS/chassis/DiffChassis.hpp b/include/VOSS/chassis/DiffChassis.hpp index c6822d7..2e832ce 100644 --- a/include/VOSS/chassis/DiffChassis.hpp +++ b/include/VOSS/chassis/DiffChassis.hpp @@ -22,7 +22,7 @@ class DiffChassis : public AbstractChassis { public: DiffChassis(std::initializer_list left_motors, std::initializer_list right_motors, - controller::AbstractController& default_controller, + controller_ptr default_controller, double slew_step = 8); void tank(double left_speed, double right_speed); diff --git a/include/VOSS/controller/ArcPIDControllerBuilder.hpp b/include/VOSS/controller/ArcPIDControllerBuilder.hpp index 5dd844c..668eba3 100644 --- a/include/VOSS/controller/ArcPIDControllerBuilder.hpp +++ b/include/VOSS/controller/ArcPIDControllerBuilder.hpp @@ -27,7 +27,7 @@ class ArcPIDControllerBuilder { ArcPIDControllerBuilder& with_settle_time(double time); ArcPIDControllerBuilder& with_slew(double slew); - ArcPIDController build(); + std::shared_ptr build(); }; } // namespace voss::controller \ No newline at end of file diff --git a/include/VOSS/controller/BoomerangControllerBuilder.hpp b/include/VOSS/controller/BoomerangControllerBuilder.hpp index 142088c..ef00a07 100644 --- a/include/VOSS/controller/BoomerangControllerBuilder.hpp +++ b/include/VOSS/controller/BoomerangControllerBuilder.hpp @@ -25,7 +25,7 @@ class BoomerangControllerBuilder { BoomerangControllerBuilder& with_lead_pct(double lead_pct); BoomerangControllerBuilder& with_settle_time(double time); - BoomerangController build(); + std::shared_ptr build(); }; } // namespace voss::controller \ No newline at end of file diff --git a/include/VOSS/controller/PIDControllerBuilder.hpp b/include/VOSS/controller/PIDControllerBuilder.hpp index 16942b2..c4152cf 100644 --- a/include/VOSS/controller/PIDControllerBuilder.hpp +++ b/include/VOSS/controller/PIDControllerBuilder.hpp @@ -24,7 +24,7 @@ class PIDControllerBuilder { PIDControllerBuilder& with_min_error(double error); PIDControllerBuilder& with_settle_time(double time); - PIDController build(); + std::shared_ptr build(); }; } // namespace voss::controller \ No newline at end of file diff --git a/include/VOSS/controller/SwingControllerBuilder.hpp b/include/VOSS/controller/SwingControllerBuilder.hpp index 5a66c86..2f0d65a 100644 --- a/include/VOSS/controller/SwingControllerBuilder.hpp +++ b/include/VOSS/controller/SwingControllerBuilder.hpp @@ -22,7 +22,7 @@ class SwingControllerBuilder { SwingControllerBuilder& with_settle_time(double time); // SwingControllerBuilder& with_slew(double slew); - SwingController build(); + std::shared_ptr build(); }; } // namespace voss::controller \ No newline at end of file diff --git a/src/VOSS/chassis/AbstractChassis.cpp b/src/VOSS/chassis/AbstractChassis.cpp index f97b092..8fdcdf6 100644 --- a/src/VOSS/chassis/AbstractChassis.cpp +++ b/src/VOSS/chassis/AbstractChassis.cpp @@ -5,11 +5,11 @@ namespace voss::chassis { AbstractChassis::AbstractChassis( - controller::AbstractController& default_controller) { - this->default_controller = &default_controller; + controller_ptr default_controller) { + this->default_controller = default_controller; } -void AbstractChassis::move_task(controller::AbstractController* controller, +void AbstractChassis::move_task(controller_ptr controller, double max, voss::Flags flags, double exitTime) { int t = 0; @@ -42,7 +42,7 @@ void AbstractChassis::move_task(controller::AbstractController* controller, // this->m.give(); } -void AbstractChassis::turn_task(controller::AbstractController* controller, +void AbstractChassis::turn_task(controller_ptr controller, double max, voss::Flags flags, double exitTime) { int t = 0; @@ -83,14 +83,14 @@ void AbstractChassis::move(Pose target, double max, voss::Flags flags, } void AbstractChassis::move(Point target, - controller::AbstractController* controller, + controller_ptr controller, double max, voss::Flags flags, double exitTime) { Pose pose_target = Pose{target.x, target.y, 361}; this->move(pose_target, controller, max, flags, exitTime); } void AbstractChassis::move(Pose target, - controller::AbstractController* controller, + controller_ptr controller, double max, voss::Flags flags, double exitTime) { // this->m.take(); @@ -105,7 +105,7 @@ void AbstractChassis::turn(double target, double max, voss::Flags flags, } void AbstractChassis::turn(double target, - controller::AbstractController* controller, + controller_ptr controller, double max, voss::Flags flags, double exitTime) { // this->m.take(); @@ -121,7 +121,7 @@ void AbstractChassis::turn_to(Point target, double max, voss::Flags flags, } void AbstractChassis::turn_to(Point target, - controller::AbstractController* controller, + controller_ptr controller, double max, voss::Flags flags, double exitTime) { // this->m.take(); diff --git a/src/VOSS/chassis/DiffChassis.cpp b/src/VOSS/chassis/DiffChassis.cpp index 2f32041..610861a 100644 --- a/src/VOSS/chassis/DiffChassis.cpp +++ b/src/VOSS/chassis/DiffChassis.cpp @@ -24,7 +24,7 @@ double DiffChassis::slew(double target, bool is_left) { DiffChassis::DiffChassis(std::initializer_list left_motors, std::initializer_list right_motors, - controller::AbstractController& default_controller, + controller_ptr default_controller, double slew_step) : AbstractChassis(default_controller) { this->left_motors = std::make_unique(left_motors); diff --git a/src/VOSS/controller/ArcPIDControllerBuilder.cpp b/src/VOSS/controller/ArcPIDControllerBuilder.cpp index c12775a..fb24e41 100644 --- a/src/VOSS/controller/ArcPIDControllerBuilder.cpp +++ b/src/VOSS/controller/ArcPIDControllerBuilder.cpp @@ -50,8 +50,8 @@ ArcPIDControllerBuilder& ArcPIDControllerBuilder::with_slew(double slew) { return *this; } -ArcPIDController ArcPIDControllerBuilder::build() { - return this->ctrl; +std::shared_ptr ArcPIDControllerBuilder::build() { + return std::make_shared(this->ctrl); } } // namespace voss::controller \ No newline at end of file diff --git a/src/VOSS/controller/BoomerangControllerBuilder.cpp b/src/VOSS/controller/BoomerangControllerBuilder.cpp index 7700619..4f31ce4 100644 --- a/src/VOSS/controller/BoomerangControllerBuilder.cpp +++ b/src/VOSS/controller/BoomerangControllerBuilder.cpp @@ -70,8 +70,8 @@ BoomerangControllerBuilder::with_settle_time(double time) { return *this; } -BoomerangController BoomerangControllerBuilder::build() { - return this->ctrl; +std::shared_ptr BoomerangControllerBuilder::build() { + return std::make_shared(this->ctrl); } } // namespace voss::controller \ No newline at end of file diff --git a/src/VOSS/controller/PIDControllerBuilder.cpp b/src/VOSS/controller/PIDControllerBuilder.cpp index a876abd..9690ea5 100644 --- a/src/VOSS/controller/PIDControllerBuilder.cpp +++ b/src/VOSS/controller/PIDControllerBuilder.cpp @@ -58,8 +58,8 @@ PIDControllerBuilder& PIDControllerBuilder::with_settle_time(double time) { return *this; } -PIDController PIDControllerBuilder::build() { - return this->ctrl; +std::shared_ptr PIDControllerBuilder::build() { + return std::make_shared(this->ctrl); } } // namespace voss::controller \ No newline at end of file diff --git a/src/VOSS/controller/SwingControllerBuilder.cpp b/src/VOSS/controller/SwingControllerBuilder.cpp index d85b08e..d982164 100644 --- a/src/VOSS/controller/SwingControllerBuilder.cpp +++ b/src/VOSS/controller/SwingControllerBuilder.cpp @@ -36,8 +36,8 @@ SwingControllerBuilder& SwingControllerBuilder::with_settle_time(double time) { return *this; } -SwingController SwingControllerBuilder::build() { - return this->ctrl; +std::shared_ptr SwingControllerBuilder::build() { + return std::make_shared(this->ctrl); } } // namespace voss::controller \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 22bfa64..28f0ca6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -108,6 +108,7 @@ void opcontrol() { if (master.get_digital_new_press(DIGITAL_Y)) { odom->set_pose(voss::Pose{0.0, 0.0, 0}); chassis.turn(180, 100, voss::Flags::NONE, 10000); + chassis.turn(0, swing); } pros::lcd::clear_line(1);