diff --git a/simulation/qtcreator-files/paprikaSimulateur/paprikaSimulateur.pro b/simulation/qtcreator-files/paprikaSimulateur/paprikaSimulateur.pro index 4e8f07aed9c6d41b9e223bb8129f4331bc9d8e00..830c14544c60d110c5154414ae68fef05309e7b4 100644 --- a/simulation/qtcreator-files/paprikaSimulateur/paprikaSimulateur.pro +++ b/simulation/qtcreator-files/paprikaSimulateur/paprikaSimulateur.pro @@ -108,7 +108,7 @@ HEADERS += \ ../../include/strategie/benne.h \ ../../include/actionneurs/fishingNet.h \ ../../include/actionneurs/parasol.h \ - ../../include/strategie/benne.h \ + ../../include/actionneurs/benne.h \ ../../include/strategie/cubeDebut.h \ ../../include/clock.h @@ -188,7 +188,7 @@ SOURCES += \ ../../src/strategie/krabijunior2016.cpp \ ../../src/strategie/krabi2016.cpp \ ../../src/strategie/cabine.cpp \ - ../../src/strategie/benne.cpp \ + ../../src/actionneurs/benne.cpp \ ../../src/strategie/zoneConstruction.cpp \ ../../src/strategie/cubeDebut.cpp \ ../../src/actionneurs/fishingNet.cpp \ diff --git a/stm32/include/actionneurs/benne.h b/stm32/include/actionneurs/benne.h new file mode 100644 index 0000000000000000000000000000000000000000..b12c6e8c4a92d790b504dff71588bcd6aed0c023 --- /dev/null +++ b/stm32/include/actionneurs/benne.h @@ -0,0 +1,64 @@ +#ifndef BENNE_H +#define BENNE_H + +class MicroSwitch; + +class Benne +{ + /** + * The ID of the AX12 used to drive the belts + */ + static const int SERVO_ID = 0; // To update + + static const int FORWARD_SPEED = 1023; + static const int BACKWARD_SPEED = 2046; + + public: + struct Status + { + enum Enum + { + UNKNOWN, + OPEN, + CLOSED, + OPENING, + CLOSING + }; + }; + + static Benne* getInstance(); + + ~Benne(); + + void update(); + + void setBenneEmpty(); + void setBenneFull(); + + bool getIsBenneEmpty() const; + bool getIsBenneFull() const; + + void empty(); + void open(); + + void stop(); + + bool isFrontSwitchActive() const; + bool isBackSwitchActive() const; + + Benne::Status::Enum getStatus() const; + + private: + Benne(); + + void setStatus(Status::Enum status); + + bool isBenneEmpty; + + Status::Enum m_status; + + MicroSwitch* m_backSwitch; + MicroSwitch* m_frontSwitch; +}; + +#endif // BENNE_H diff --git a/stm32/include/actionneurs/fishingNet.h b/stm32/include/actionneurs/fishingNet.h index dcda6bb109c769ae48a3b922d048364c915378a0..5aa44d8b61eba7509734453e642b7234a9fd7b22 100644 --- a/stm32/include/actionneurs/fishingNet.h +++ b/stm32/include/actionneurs/fishingNet.h @@ -10,7 +10,7 @@ class FishingNet /** * The ID of the innermost AX12 (i.e. for rotation) */ - static const int SERVO_INT_ID = 42; // To update + static const int SERVO_INT_ID = 42; /** * The ID of the outermost AX12 (i.e. for folding/unfolding) */ diff --git a/stm32/include/strategie/benne.h b/stm32/include/strategie/benne.h deleted file mode 100644 index eb55620bee659ea21e1c736e242eb13644294713..0000000000000000000000000000000000000000 --- a/stm32/include/strategie/benne.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef BENNE_H -#define BENNE_H - -class Benne -{ -public: - Benne(); - - ~Benne(); - - void setBenneEmpty(); - void setBenneFull(); - - bool getIsBenneEmpty(); - bool getIsBenneFull(); - -protected: - bool isBenneEmpty; -}; - -#endif // BENNE_H diff --git a/stm32/paprika_krabi_h107.cbp b/stm32/paprika_krabi_h107.cbp index 5b534ddc3c8b53c1801f7ce84a895a43ec02cf4f..174f59d1451a48d666ecd4a2176e4e84cd96d952 100644 --- a/stm32/paprika_krabi_h107.cbp +++ b/stm32/paprika_krabi_h107.cbp @@ -73,6 +73,7 @@ + @@ -120,12 +121,10 @@ - - @@ -147,6 +146,7 @@ + @@ -199,7 +199,6 @@ - diff --git a/stm32/src/actionneurs/benne.cpp b/stm32/src/actionneurs/benne.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f9831299ad061fac027b944643cd513423acf1cc --- /dev/null +++ b/stm32/src/actionneurs/benne.cpp @@ -0,0 +1,136 @@ +#include "benne.h" + +#ifdef ROBOTHW + #include "interfaceServosNumeriques.h" +#else + #include +#endif + +#include "hardware/microSwitch.h" + +Benne* Benne::getInstance() +{ + static Benne* instance = 0; + if(!instance) + instance = new Benne(); + return instance; +} + +Benne::Benne() +{ + #ifdef ROBOTHW + m_backSwitch = new MicroSwitch(GPIOE, GPIO_Pin_3); + m_frontSwitch = new MicroSwitch(GPIOE, GPIO_Pin_2); + #else + m_backSwitch = new MicroSwitch(); + m_frontSwitch = new MicroSwitch(); + #endif + + isBenneEmpty = true; + + m_status = Status::UNKNOWN; + + #ifdef ROBOTHW + ServosNumeriques::changeContinuousRotationMode(SERVO_ID, true); + #endif +} + +Benne::~Benne() +{ + delete m_backSwitch; + delete m_frontSwitch; +} + +void Benne::setBenneEmpty() { + isBenneEmpty = true; +} + +void Benne::setBenneFull() { + isBenneEmpty = false; +} + +bool Benne::getIsBenneEmpty() const +{ + return isBenneEmpty; +} + +bool Benne::getIsBenneFull() const +{ + return !isBenneEmpty; +} + +Benne::Status::Enum Benne::getStatus() const +{ + return m_status; +} + +void Benne::setStatus(Status::Enum status) +{ + m_status = status; +} + +void Benne::empty() +{ + if(getStatus() != Status::CLOSED && getStatus() != Status::CLOSING) + { + #ifdef ROBOTHW + ServosNumeriques::moveAtSpeed(FORWARD_SPEED, SERVO_ID); + #else + qDebug() << "Bin is closing"; + #endif + setStatus(Status::CLOSING); + } +} + +void Benne::open() +{ + if(getStatus() != Status::OPEN && getStatus() != Status::OPENING) + { + #ifdef ROBOTHW + ServosNumeriques::moveAtSpeed(BACKWARD_SPEED, SERVO_ID); + #else + qDebug() << "Bin is opening"; + #endif + setStatus(Status::OPENING); + } +} + +void Benne::update() +{ + if(getStatus() == Status::CLOSING && isFrontSwitchActive()) + { + stop(); + setStatus(Status::CLOSED); + setBenneEmpty(); + + #ifndef ROBOTHW + qDebug() << "Bin is closed"; + #endif + } + else if(getStatus() == Status::OPENING && isBackSwitchActive()) + { + stop(); + setStatus(Status::OPEN); + + #ifndef ROBOTHW + qDebug() << "Bin is open"; + #endif + } +} + +void Benne::stop() +{ + #ifdef ROBOTHW + ServosNumeriques::moveAtSpeed(0, SERVO_ID); + #endif +} + +bool Benne::isFrontSwitchActive() const +{ + return m_frontSwitch->ferme(); +} + +bool Benne::isBackSwitchActive() const +{ + return m_backSwitch->ferme(); +} diff --git a/stm32/src/clock.cpp b/stm32/src/clock.cpp index 9c8c79ddd13599bcf1ed13abd9eb62bf48d01f73..84429d0dadcce5fbdf1dc31e4a3de43f6a3be474 100755 --- a/stm32/src/clock.cpp +++ b/stm32/src/clock.cpp @@ -1,12 +1,14 @@ #include "clock.h" + #include "asservissement/odometrie.h" #include "asservissement/asservissement.h" #include "hardware/tourelle.h" -#include "hardware/leds.h" +#include "actionneurs/benne.h" #ifdef ROBOTHW #include "hardware/remote.h" + #include "hardware/leds.h" #else #include #endif @@ -29,6 +31,7 @@ void Clock::every5ms() Odometrie::odometrie->update(); Asservissement::asservissement->update(); Tourelle::getSingleton()->update(); + Benne::getInstance()->update(); //StrategieV2::update(); #endif #endif diff --git a/stm32/src/initkrabi.cpp b/stm32/src/initkrabi.cpp index 39dfee0b9122365dad9e41a2939ca2233e6a6527..f90c44b0366f5a8590aaff93a070eaba5752fd28 100644 --- a/stm32/src/initkrabi.cpp +++ b/stm32/src/initkrabi.cpp @@ -1,22 +1,23 @@ #include "initkrabi.h" +#include "actionneurs/benne.h" + #ifdef ROBOTHW -InitKrabi::InitKrabi() : Initialisation(PositionPlusAngle(Position(194, 900), 0)) -{ -} + InitKrabi::InitKrabi() : Initialisation(PositionPlusAngle(Position(194, 900), 0)) + {} #else -#include -InitKrabi::InitKrabi(bool yellow, Robot* robot) : Initialisation(PositionPlusAngle(Position(194, 900), 0), yellow, robot) -{ - qDebug() << "InitKrabi " << robot; -} + #include + InitKrabi::InitKrabi(bool yellow, Robot* robot) : Initialisation(PositionPlusAngle(Position(194, 900), 0), yellow, robot) + { + qDebug() << "InitKrabi " << robot; + } #endif #ifdef ROBOTHW -void InitKrabi::setYellow() -{ - yellow = GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_4) == Bit_RESET; -} + void InitKrabi::setYellow() + { + yellow = GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_4) == Bit_RESET; + } #endif /** Initialisation roues codeuses **/ @@ -177,5 +178,7 @@ void InitKrabi::initActionneurs() Sensors* sensors = Sensors::getSingleton(); ServosNumeriques::setLedState(1, 12); + + Benne::getInstance(); #endif } diff --git a/stm32/src/simul/robot.cpp b/stm32/src/simul/robot.cpp index ff50771a785892ac688b4c0f41d5c1708567f507..08f76fd4be8127519ad3d048e7aedaee1211982a 100644 --- a/stm32/src/simul/robot.cpp +++ b/stm32/src/simul/robot.cpp @@ -7,6 +7,7 @@ #include "strategieV2.h" #include "sensors.h" #include "hardware/tourelle.h" +#include "actionneurs/benne.h" #include #include @@ -348,6 +349,7 @@ void Robot::paint(QPainter &p, int dt) } else { + Benne::getInstance()->update(); Odometrie::odometrie->update(); Tourelle::getSingleton()->update(); StrategieV2::update(); diff --git a/stm32/src/strategie/benne.cpp b/stm32/src/strategie/benne.cpp deleted file mode 100644 index 0f77f7a493786ca341b48108c6a8447e0ce23425..0000000000000000000000000000000000000000 --- a/stm32/src/strategie/benne.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "benne.h" - -Benne::Benne() -{ - isBenneEmpty = true; -} - -void Benne::setBenneEmpty() { - isBenneEmpty = true; -} - -void Benne::setBenneFull() { - isBenneEmpty = false; -} - -bool Benne::getIsBenneEmpty() { - return isBenneEmpty; -} - -bool Benne::getIsBenneFull() { - return !isBenneEmpty; -} diff --git a/stm32/src/strategie/krabi2016.cpp b/stm32/src/strategie/krabi2016.cpp index af82e0df76ee1f5f92f9839a0c99ef790b4b44f3..4e2f6aea8f2f8f37cb5887c5943aeb05cdae59d8 100644 --- a/stm32/src/strategie/krabi2016.cpp +++ b/stm32/src/strategie/krabi2016.cpp @@ -10,7 +10,7 @@ Krabi2016::Krabi2016(bool isYellow) : StrategieV3(isYellow) { // Création de la benne - benne = new Benne(); + benne = Benne::getInstance(); // NB: Tu pourrais utiliser getInstance partout et te passer de l'attribut //Initialisation des tableaux d'étapes this->numeroEtapeGarage = ETAPE_GARAGE;