From 7749594d916b8bb9b541f937970448481f04a523 Mon Sep 17 00:00:00 2001 From: Arnaud Cadot Date: Fri, 18 Mar 2016 13:21:10 +0100 Subject: [PATCH] - Fixed warnings in robot.cpp - Updated FishingNet class - Added doc du FishingNet class --- .../paprikaSimulateur/paprikaSimulateur.pro | 2 +- stm32/include/actionneurs/fishingNet.h | 65 ++++++++++++++++++- stm32/src/actionneurs/fishingNet.cpp | 15 +++++ stm32/src/simul/robot.cpp | 4 +- 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/simulation/qtcreator-files/paprikaSimulateur/paprikaSimulateur.pro b/simulation/qtcreator-files/paprikaSimulateur/paprikaSimulateur.pro index 0fe5aa40..f724fbb1 100644 --- a/simulation/qtcreator-files/paprikaSimulateur/paprikaSimulateur.pro +++ b/simulation/qtcreator-files/paprikaSimulateur/paprikaSimulateur.pro @@ -105,7 +105,7 @@ HEADERS += \ ../../include/vector.h \ ../../include/strategie/krabijunior2016.h \ ../../include/strategie/krabi2016.h \ - ../../stm32/include/actionneurs/fishingNet.h + ../../include/actionneurs/fishingNet.h SOURCES += \ diff --git a/stm32/include/actionneurs/fishingNet.h b/stm32/include/actionneurs/fishingNet.h index 62cf10cb..fdf10041 100644 --- a/stm32/include/actionneurs/fishingNet.h +++ b/stm32/include/actionneurs/fishingNet.h @@ -1,11 +1,24 @@ #ifndef FICHINGNET_H #define FICHINGNET_H +/** + * @brief This singleton class handles the fishing net actuator. + * @see getSingleton + */ class FishingNet { + /** + * The ID of the innermost AX12 (i.e. for rotation) + */ static const int SERVO_INT_ID = 0; // To update + /** + * The ID of the outermost AX12 (i.e. for folding/unfolding) + */ static const int SERVO_EXT_ID = 1; + /** + * Those constantes are angles sent to the relevant servos for the relevant action (names are pretty explicit) + */ static const int SERVO_EXT_CLOSED_POS = 0x00; static const int SERVO_EXT_DEPLOYED_POS = 0x00; static const int SERVO_EXT_RAISED_POS = 0x00; @@ -13,9 +26,7 @@ class FishingNet static const int SERVO_INT_RAISED_POS = 0x00; static const int SERVO_INT_LOWERED_POS = 0x00; - public: - FishingNet(); - + public: enum NET_STATE { CLOSED, @@ -24,21 +35,69 @@ class FishingNet NET_LOWERED }; + /** + * @brief FishingNet is a singleton. This static method will return the only possible instance of FishingNet (and create it if deemed necessary) + */ static FishingNet* getSingleton(); + /** + * @brief Closes the arm (folds it against the robot) + */ void close(); + + /** + * @brief Deploys the arm and gets the net ready to fish + */ void deploy(); + /** + * @brief Lower the net (start to fish) + */ void lowerNet(); + /** + * @brief Raise the net (finnish fishing) + */ void raiseNet(); + /** + * @brief Raise the net's arm (to avoid hitting the tank's sides) + */ void raiseArm(); + /** + * @brief Returns the current software state of the device. Note it may not reflect the actual positions of the servos. + * @see NET_STATE + */ + NET_STATE getCurrentState() const; + private: + /** + * @brief Constructor + * @see getSingleton + */ + FishingNet(); + + /** + * @brief Move (i.e. lower or raise) the arm to a set angle + * @param destAngle The angle (as used by the AX12) + */ void moveArm(int destAngle); + + /** + * @brief Rotate (i.e. turn on itself) the arm to a set angle + * @param destAngle The angle (as used by the AX12) + */ void rotateArm(int destAngle); + /** + * @brief The software state of this device may not reflect its hardware state (servo locked, etc.). + * + * This function will NOT move the servos, do not call it directly. + * @param The new software state of the device + */ + void setCurrentState(NET_STATE state); + NET_STATE m_currentState; }; diff --git a/stm32/src/actionneurs/fishingNet.cpp b/stm32/src/actionneurs/fishingNet.cpp index 01ae42a2..88d91201 100644 --- a/stm32/src/actionneurs/fishingNet.cpp +++ b/stm32/src/actionneurs/fishingNet.cpp @@ -36,25 +36,40 @@ void FishingNet::close() { rotateArm(SERVO_INT_RAISED_POS); moveArm(SERVO_EXT_CLOSED_POS); + setCurrentState(CLOSED); } void FishingNet::deploy() { moveArm(SERVO_EXT_DEPLOYED_POS); rotateArm(SERVO_INT_RAISED_POS); + setCurrentState(OPENED); } void FishingNet::lowerNet() { rotateArm(SERVO_INT_LOWERED_POS); + setCurrentState(NET_LOWERED); } void FishingNet::raiseNet() { rotateArm(SERVO_INT_RAISED_POS); + setCurrentState(OPENED); } void FishingNet::raiseArm() { moveArm(SERVO_EXT_RAISED_POS); + setCurrentState(RAISED); +} + +void FishingNet::setCurrentState(NET_STATE state) +{ + m_currentState = state; +} + +FishingNet::NET_STATE FishingNet::getCurrentState() const +{ + return m_currentState; } diff --git a/stm32/src/simul/robot.cpp b/stm32/src/simul/robot.cpp index d2c99783..ff50771a 100644 --- a/stm32/src/simul/robot.cpp +++ b/stm32/src/simul/robot.cpp @@ -12,7 +12,7 @@ #define ratio_qt_box2d 0.01 -Robot::Robot(b2World & world, bool manual, bool isYellow) : world(world), olds(10000), mRemoteMod(false), body(NULL) +Robot::Robot(b2World & world, bool manual, bool isYellow) : world(world), olds(10000), body(NULL), mRemoteMod(false) { this->manual = manual; level = 0; @@ -92,7 +92,7 @@ Robot::Robot(b2World & world, bool manual, bool isYellow) : world(world), olds(1 // 2dbox limite à 8 le nombre de vertex par polygone inc = 0; - for(int i = 0; i < robotPolygonPoints.size(); i += 1) + for(size_t i = 0; i < robotPolygonPoints.size(); i += 1) { v[0].Set(0., 0.); v[1].Set(robotPolygonPoints[i].x() * ratio_qt_box2d, robotPolygonPoints[i].y() * ratio_qt_box2d); -- GitLab