mirror of
https://github.com/modelec/odo_STM32.git
synced 2026-01-18 16:27:25 +01:00
refactoring
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
#ifndef INC_PID_H_
|
||||
#define INC_PID_H_
|
||||
#include "point.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
class PID {
|
||||
protected:
|
||||
|
||||
@@ -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 <array>
|
||||
#include <cstdint>
|
||||
|
||||
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<float, 3> 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_ */
|
||||
|
||||
@@ -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<StatePoint>(type), x, y, theta);
|
||||
|
||||
if (id <= index) index = 0;
|
||||
|
||||
arrive = false;
|
||||
|
||||
@@ -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<float, 3> Point::getPoint(){
|
||||
return {this->x, this->y, this->theta};
|
||||
}
|
||||
|
||||
StatePoint Point::getState(){
|
||||
return state;
|
||||
}
|
||||
|
||||
uint32_t Point::getID(){
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user