From d36ca7f83ac23bf454829b3acf5d9a57650ade6c Mon Sep 17 00:00:00 2001 From: acki Date: Sat, 20 Sep 2025 20:34:36 +0200 Subject: [PATCH] refactoring --- Core/Inc/modelec.h | 6 ++---- Core/Inc/pid.h | 3 ++- Core/Inc/point.h | 38 ++++++++------------------------- Core/Src/modelec.cpp | 14 +++---------- Core/Src/point.cpp | 50 +------------------------------------------- Core/Src/setup.cpp | 2 +- 6 files changed, 18 insertions(+), 95 deletions(-) diff --git a/Core/Inc/modelec.h b/Core/Inc/modelec.h index 506544f..c246324 100644 --- a/Core/Inc/modelec.h +++ b/Core/Inc/modelec.h @@ -30,10 +30,10 @@ extern TIM_HandleTypeDef htim2; class DiffBot { public: - Point target; + Point pose; + Point targets[10]; uint8_t index = 0; - Point pose; Motor motor; @@ -64,8 +64,6 @@ public: void setup(); - void setTarget(Point new_target); - void update(float dt); void addTarget(int id, int type, float x, float y, float theta); diff --git a/Core/Inc/pid.h b/Core/Inc/pid.h index 95b6895..7b2d0ee 100644 --- a/Core/Inc/pid.h +++ b/Core/Inc/pid.h @@ -7,7 +7,8 @@ #ifndef INC_PID_H_ #define INC_PID_H_ -#include "point.h" + +#include class PID { protected: diff --git a/Core/Inc/point.h b/Core/Inc/point.h index 184f5ab..b8d86fc 100644 --- a/Core/Inc/point.h +++ b/Core/Inc/point.h @@ -2,50 +2,30 @@ * point.h * * Created on: Mar 24, 2025 - * Author: CHAUVEAU Maxime + * Author: Modelec */ #ifndef INC_POINT_H_ #define INC_POINT_H_ -#include #include -typedef enum StatePoint { - INTERMEDIAIRE, - FINAL, - NONDETERMINE -}StatePoint; +enum StatePoint { + INTERMEDIAIRE = 0, + FINAL = 1, + NONDETERMINE = 2 +}; class Point { -private: - uint32_t id; +public: + uint8_t id; StatePoint state; -public: float x; float y; float theta; - // Constructeur - Point(float x = 0.0, float y = 0.0, float theta = 0.0, StatePoint state = StatePoint::INTERMEDIAIRE); - - // Setters - void setX(float x); - void setY(float y); - void setTheta(float theta); - void setState(StatePoint s); - void setID(uint32_t id); - - // Getters - float getX(); - float getY(); - float getTheta(); - std::array getPoint(); - StatePoint getState(); - uint32_t getID(); + Point(uint8_t id = 0, StatePoint state = StatePoint::INTERMEDIAIRE, float x = 0.0, float y = 0.0, float theta = 0.0); }; - - #endif /* INC_POINT_H_ */ diff --git a/Core/Src/modelec.cpp b/Core/Src/modelec.cpp index af8f01d..b12b5a1 100644 --- a/Core/Src/modelec.cpp +++ b/Core/Src/modelec.cpp @@ -47,10 +47,6 @@ void DiffBot::setup() { pidTheta = PID(0.5, 0.0, 0.01, -M_PI_2, M_PI_2); } -void DiffBot::setTarget(Point new_target) { - target = new_target; -} - void DiffBot::stop(bool stop) { odo_active = !stop; motor.stop(stop); @@ -78,7 +74,7 @@ void DiffBot::update(float dt) { while (angleError > M_PI) angleError -= 2*M_PI; while (angleError < -M_PI) angleError += 2*M_PI; - switch (targets[index].getState()) { + switch (targets[index].state) { case StatePoint::FINAL: if (fabs(dx) < 0.005 && fabs(dy) < 0.005 && fabs(angleError) < 0.08 /* 5deg */) { @@ -135,13 +131,9 @@ DiffBot::DiffBot(Point pose, float dt) : pose(pose), dt(dt) { }; void DiffBot::addTarget(int id, int type, float x, float y, float theta) { - targets[id].setX(x); - targets[id].setY(y); - targets[id].setTheta(theta); - targets[id].setID(id); - targets[id].setState(type == 1 ? StatePoint::FINAL : StatePoint::INTERMEDIAIRE); - // if (type == StatePoint::FINAL) index = 0; + targets[id] = Point(id, static_cast(type), x, y, theta); + if (id <= index) index = 0; arrive = false; diff --git a/Core/Src/point.cpp b/Core/Src/point.cpp index 77870b2..2730b91 100644 --- a/Core/Src/point.cpp +++ b/Core/Src/point.cpp @@ -2,54 +2,6 @@ #include "point.h" -Point::Point(float x, float y, float theta, StatePoint state){ - this->x = x; - this->y = y; - this->theta = theta; - this->state = state; -} +Point::Point(uint8_t id, StatePoint state, float x, float y, float theta) : id(id), state(state), x(x), y(y), theta(theta) { -void Point::setX(float x){ - this->x = x; -} - -void Point::setY(float y){ - this->y = y; -} - -void Point::setTheta(float theta){ - this->theta = theta; -} - -void Point::setState(StatePoint s){ - this->state = s; -} - -void Point::setID(uint32_t id){ - this->id = id; -} - - -float Point::getX(){ - return x; -} - -float Point::getY(){ - return y; -} - -float Point::getTheta(){ - return theta; -} - -std::array Point::getPoint(){ - return {this->x, this->y, this->theta}; -} - -StatePoint Point::getState(){ - return state; -} - -uint32_t Point::getID(){ - return id; } diff --git a/Core/Src/setup.cpp b/Core/Src/setup.cpp index 8c87c41..2ca4aa3 100644 --- a/Core/Src/setup.cpp +++ b/Core/Src/setup.cpp @@ -12,7 +12,7 @@ extern "C" { #endif -DiffBot bot(Point(0.0f,0.0f,0.0f), 0.01f); +DiffBot bot(Point(), 0.01f); void ModelecOdometrySetup() { bot.setup();