diff --git a/stm32/include/asservissement.h b/stm32/include/asservissement.h index f84184262e79862e908a4569a17868ebe56ab753..9edb002a93a2ad39795ff7d70cad56b6fb7148a1 100755 --- a/stm32/include/asservissement.h +++ b/stm32/include/asservissement.h @@ -34,7 +34,18 @@ class Asservissement{ short toto; Odometrie* odometrie; Command* command; - Asservissement(Odometrie* _odemetrie, class Command* command); + Asservissement(Odometrie* _odometrie); + + float getLinearSpeed() + { + return command->getLinearSpeed(); + } + + Angle getAngularSpeed() + { + return command->getAngularSpeed(); + } + static Asservissement * asservissement; static const uint16_t nb_ms_between_updates; void update(void); diff --git a/stm32/include/command.h b/stm32/include/command.h index 7f5d5e170072c8478f09b080cab725ae1dc2c044..467dab1777f14dd8862e4997416279b9af55a33d 100644 --- a/stm32/include/command.h +++ b/stm32/include/command.h @@ -1,10 +1,13 @@ +#ifndef COMMAND_H_INCLUDED +#define COMMAND_H_INCLUDED + #include "Angle.h" #include "PositionPlusAngle.h" - class Command { public: + Command(); virtual void update(PositionPlusAngle positionPlusAngleActuelle, Angle vitesse_angulaire_atteinte, float vitesse_lineaire_atteinte) = 0; virtual float getLinearSpeed() = 0; @@ -49,3 +52,5 @@ public: }; +#endif //COMMAND_H_INCLUDED + diff --git a/stm32/include/simul/robot.h b/stm32/include/simul/robot.h index 95a086dcbc564473d09105f04b29bac23533b863..d02e09f2ec1008f8de07eb256c2ce21de362cf80 100644 --- a/stm32/include/simul/robot.h +++ b/stm32/include/simul/robot.h @@ -17,7 +17,7 @@ public: PositionPlusAngle pos; PositionPlusAngle deriv; boost::circular_buffer<PositionPlusAngle> olds; - class TrapezoidalCommand* command; + class Asservissement* asservissement; class OdoRobot* odometrie; class Strategie* strategie; diff --git a/stm32/include/strategie.h b/stm32/include/strategie.h index 3e2640dec6d21da3a8a608b9ee705a8facb78d8e..6df93bb59e4168a3358b826d1e4b688977642ec0 100755 --- a/stm32/include/strategie.h +++ b/stm32/include/strategie.h @@ -7,13 +7,11 @@ #include <stdint.h> -class TrapezoidalCommand; class Odometrie; class Strategie { private: bool is_blue; - TrapezoidalCommand* command; void doNext(); int instruction_nb; bool collision_detected; @@ -21,7 +19,7 @@ class Strategie { public: void collisionDetected(); - Strategie(bool is_blue, TrapezoidalCommand* command, Odometrie* odometrie); + Strategie(bool is_blue, Odometrie* odometrie); void foundOtherRobot(); void done(); void doNthInstruction(uint16_t n); diff --git a/stm32/src/asservissement.cpp b/stm32/src/asservissement.cpp index bd7a90c3030c5eb1419def238811a912eb688d55..3c2b7938a58376a77034a936af7fa18b11e73eca 100755 --- a/stm32/src/asservissement.cpp +++ b/stm32/src/asservissement.cpp @@ -9,7 +9,6 @@ #include "asservissement.h" #include "strategie.h" #include <math.h> -//#include <stdlib.h> #define STK_CTRL_ADDR 0xe000e010 #define STK_LOAD_ADDR (STK_CTRL_ADDR+0x04) @@ -38,13 +37,13 @@ float angle[DBG_SIZE]; Asservissement * Asservissement::asservissement = NULL; const uint16_t Asservissement::nb_ms_between_updates = 10; uint32_t dbgInc = 0; -Asservissement::Asservissement(Odometrie* _odometrie, Command* command) : +Asservissement::Asservissement(Odometrie* _odometrie) : seuil_collision(3.5), buffer_collision(0xffffffff), nb_echantillons_buffer_collision(10) { odometrie = _odometrie; - this->command = command; + command = NULL; toto = 0; linearDutySent = 0; angularDutySent = 0; diff --git a/stm32/src/command.cpp b/stm32/src/command.cpp index 8f301f0559d1b44539afe5164188fa6b54c5c26f..915773bd2c93ac87659b55e1dc33ff7f6afa5369 100644 --- a/stm32/src/command.cpp +++ b/stm32/src/command.cpp @@ -1,4 +1,5 @@ #include "command.h" +#include "asservissement.h" #include <math.h> template<class T> T min(T a, T b) @@ -11,6 +12,14 @@ template<class T> T max(T a, T b) return a > b ? a : b; } +Command::Command() +{ + Command* & c = Asservissement::asservissement->command; + if(c) + delete c; + c = this; +} + TrapezoidalCommand::TrapezoidalCommand() : vitesse_lineaire_a_atteindre(0), vitesse_angulaire_a_atteindre(0), diff --git a/stm32/src/simul/robot.cpp b/stm32/src/simul/robot.cpp index be62c536734d9eb695504707846b8f2f0764bd81..0b2e0e9bd63f95a5e13e469189ee72cfd3bf5bfd 100644 --- a/stm32/src/simul/robot.cpp +++ b/stm32/src/simul/robot.cpp @@ -51,9 +51,8 @@ Robot::Robot(b2World & world) : world(world), olds(10000) level = 0; odometrie = new OdoRobot(this); - command = new TrapezoidalCommand; - Asservissement* asservissement = new Asservissement(odometrie, command); - strategie = new Strategie(true, command, odometrie); + asservissement = new Asservissement(odometrie); + strategie = new Strategie(true, odometrie); asservissement->strategie = strategie; pos = odometrie->getPos(); @@ -173,9 +172,9 @@ void Robot::paint(QPainter &p, int dt) else { Asservissement::asservissement->update(); - deriv.position.x = command->getLinearSpeed(); + deriv.position.x = asservissement->getLinearSpeed(); deriv.position.y = 0; - deriv.angle = command->getAngularSpeed(); + deriv.angle = asservissement->getAngularSpeed(); } } diff --git a/stm32/src/strategie.cpp b/stm32/src/strategie.cpp index c8d51763ca85b2e5ceede8b71b1f2330bd93837e..6ec9ab1360b62b7c7d8fde7055410bb36e215c4d 100755 --- a/stm32/src/strategie.cpp +++ b/stm32/src/strategie.cpp @@ -12,11 +12,11 @@ #define INSTRUCTION_COLLISION 128 -Strategie::Strategie(bool is_blue, TrapezoidalCommand* command, Odometrie* odometrie) : +Strategie::Strategie(bool is_blue, Odometrie* odometrie) : collision_detected(false) { this->is_blue = is_blue; -#ifdef NOBODY +#ifdef NOBODY //FIXME: Ce code est-il encore vraiment utile ? roueCodeuseDroite = new QuadratureCoderHandler(TIM2); roueCodeuseGauche = new QuadratureCoderHandler(TIM1); #endif @@ -30,7 +30,6 @@ collision_detected(false) positionDeDepart.y = positionDeDepart.y*(is_blue ? 1:-1); angleDeDepart = angleDeDepart*(is_blue ? 1:-1); //command = new Asservissement(PositionPlusAngle(Position(335, 400), Angle(M_PI_2)), roueCodeuseGauche, roueCodeuseDroite); - this->command = command; odometrie->setPos(PositionPlusAngle(positionDeDepart,angleDeDepart)); //command = new Asservissement(PositionPlusAngle(positionDeDepart, angleDeDepart), roueCodeuseGauche, roueCodeuseDroite); //command = new Asservissement(PositionPlusAngle(Position(0, 0), Angle(0)), roueCodeuseGauche, roueCodeuseDroite); @@ -66,14 +65,14 @@ void Strategie::doNthInstruction(uint16_t n){ int cote = (is_blue ? 1:-1); if(n==1) - command->goTo(Position(1500, 1000)); + (new TrapezoidalCommand)->goTo(Position(1500, 1000)); return; //rouleau.recracheBoule(); //return; #ifdef DONTUSE switch(n) { case 1: - command->goTo(Position(780, cote*780), false); + command->goTo(Position(780, cote*780), false); break; case 2: rouleau.avaleBoule(); @@ -116,6 +115,7 @@ void Strategie::doNthInstruction(uint16_t n){ } #endif +#if (0) switch(n) { case 1: //rouleau.avaleBoule(); @@ -150,6 +150,7 @@ void Strategie::doNthInstruction(uint16_t n){ break; } +#endif /* if(n==0) {