a

Dependencies:   mbed mbed-rtos

Committer:
alexpirciu
Date:
Thu Mar 28 07:44:42 2019 +0000
Revision:
1:ceee5a608e7c
assa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alexpirciu 1:ceee5a608e7c 1 /**
alexpirciu 1:ceee5a608e7c 2 ******************************************************************************
alexpirciu 1:ceee5a608e7c 3 * @file MotionController.hpp
alexpirciu 1:ceee5a608e7c 4 * @author RBRO/PJ-IU
alexpirciu 1:ceee5a608e7c 5 * @version V1.0.0
alexpirciu 1:ceee5a608e7c 6 * @date day-month-year
alexpirciu 1:ceee5a608e7c 7 * @brief This file contains the class declaration for the motion controller
alexpirciu 1:ceee5a608e7c 8 * functionality.
alexpirciu 1:ceee5a608e7c 9 ******************************************************************************
alexpirciu 1:ceee5a608e7c 10 */
alexpirciu 1:ceee5a608e7c 11
alexpirciu 1:ceee5a608e7c 12 #ifndef MOTION_CONTROLLER_HPP
alexpirciu 1:ceee5a608e7c 13 #define MOTION_CONTROLLER_HPP
alexpirciu 1:ceee5a608e7c 14
alexpirciu 1:ceee5a608e7c 15 /* The mbed library */
alexpirciu 1:ceee5a608e7c 16 #include <mbed.h>
alexpirciu 1:ceee5a608e7c 17 #include <TaskManager/taskmanager.hpp>
alexpirciu 1:ceee5a608e7c 18 #include <Move/move.hpp>
alexpirciu 1:ceee5a608e7c 19 #include <BezierMotionPlanner/bezierMotionplanner.hpp>
alexpirciu 1:ceee5a608e7c 20 #include <Controllers/controller.hpp>
alexpirciu 1:ceee5a608e7c 21 #include <SafetyStop/safetystopfunction.hpp>
alexpirciu 1:ceee5a608e7c 22
alexpirciu 1:ceee5a608e7c 23 #include <rtos.h>
alexpirciu 1:ceee5a608e7c 24
alexpirciu 1:ceee5a608e7c 25 /**
alexpirciu 1:ceee5a608e7c 26 * @brief Limit of the pwm command [percentage]
alexpirciu 1:ceee5a608e7c 27 *
alexpirciu 1:ceee5a608e7c 28 */
alexpirciu 1:ceee5a608e7c 29 #define MCTL_PWM_COMMAND_LIMIT 75
alexpirciu 1:ceee5a608e7c 30 /**
alexpirciu 1:ceee5a608e7c 31 * @brief Limit of the velocity command [Centimeter per second]
alexpirciu 1:ceee5a608e7c 32 *
alexpirciu 1:ceee5a608e7c 33 */
alexpirciu 1:ceee5a608e7c 34 #define MCTL_SPEED_COMMAND_LIMIT 100
alexpirciu 1:ceee5a608e7c 35
alexpirciu 1:ceee5a608e7c 36 //! CMotionController class.
alexpirciu 1:ceee5a608e7c 37 /*!
alexpirciu 1:ceee5a608e7c 38 * It inherits class task::CTask.
alexpirciu 1:ceee5a608e7c 39 * It is used for executing move commands.
alexpirciu 1:ceee5a608e7c 40 * */
alexpirciu 1:ceee5a608e7c 41 class CMotionController
alexpirciu 1:ceee5a608e7c 42 {
alexpirciu 1:ceee5a608e7c 43 public:
alexpirciu 1:ceee5a608e7c 44 CMotionController(
alexpirciu 1:ceee5a608e7c 45 float f_period_sec,
alexpirciu 1:ceee5a608e7c 46 Serial& f_serialPort,
alexpirciu 1:ceee5a608e7c 47 Move& f_car,
alexpirciu 1:ceee5a608e7c 48 CSafetyStopFunction* f_safetyStop,
alexpirciu 1:ceee5a608e7c 49 controllers::CControllerSiso* f_control = NULL);
alexpirciu 1:ceee5a608e7c 50 CMotionController(
alexpirciu 1:ceee5a608e7c 51 float f_period_sec,
alexpirciu 1:ceee5a608e7c 52 Serial& f_serialPort,
alexpirciu 1:ceee5a608e7c 53 Move& f_car,
alexpirciu 1:ceee5a608e7c 54 controllers::CControllerSiso* f_control = NULL);
alexpirciu 1:ceee5a608e7c 55
alexpirciu 1:ceee5a608e7c 56
alexpirciu 1:ceee5a608e7c 57 /* Serial callback method for Move command */
alexpirciu 1:ceee5a608e7c 58 static void staticSerialCallbackMove(void* obj,char const * a, char * b);
alexpirciu 1:ceee5a608e7c 59 /* Serial callback method for BRAKE command */
alexpirciu 1:ceee5a608e7c 60 static void staticSerialCallbackBrake(void* obj,char const * a, char * b);
alexpirciu 1:ceee5a608e7c 61 /* Serial callback method for hard BRAKE command */
alexpirciu 1:ceee5a608e7c 62 static void staticSerialCallbackHardBrake(void* obj,char const * a, char * b) ;
alexpirciu 1:ceee5a608e7c 63 /* Serial callback method for PID activation command */
alexpirciu 1:ceee5a608e7c 64 static void staticSerialCallbackPID(void* obj,char const * a, char * b);
alexpirciu 1:ceee5a608e7c 65 /* Static serial callback for spline command */
alexpirciu 1:ceee5a608e7c 66 static void staticSerialCallbackSpline(void* obj,char const * a,char * b );
alexpirciu 1:ceee5a608e7c 67 /* Static callback function for run method */
alexpirciu 1:ceee5a608e7c 68 static void staticCallbackRun(void* obj);
alexpirciu 1:ceee5a608e7c 69 /* Start the Rtos timer for applying run */
alexpirciu 1:ceee5a608e7c 70 void startRtosTimer();
alexpirciu 1:ceee5a608e7c 71
alexpirciu 1:ceee5a608e7c 72 /* Reset method */
alexpirciu 1:ceee5a608e7c 73 void reset();
alexpirciu 1:ceee5a608e7c 74 /* Get speed method */
alexpirciu 1:ceee5a608e7c 75 float getSpeed();
alexpirciu 1:ceee5a608e7c 76 /* Get angle method */
alexpirciu 1:ceee5a608e7c 77 float getAngle();
alexpirciu 1:ceee5a608e7c 78 /* BRAKE callback method */
alexpirciu 1:ceee5a608e7c 79 void BrakeCallback();
alexpirciu 1:ceee5a608e7c 80 /* Set state method */
alexpirciu 1:ceee5a608e7c 81 void setState(int f_state);
alexpirciu 1:ceee5a608e7c 82 private:
alexpirciu 1:ceee5a608e7c 83 /* Run method */
alexpirciu 1:ceee5a608e7c 84 virtual void _run();
alexpirciu 1:ceee5a608e7c 85 /* Serial callback implementation */
alexpirciu 1:ceee5a608e7c 86 void serialCallbackMove(char const * a, char * b);
alexpirciu 1:ceee5a608e7c 87 /* BRAKE serial callback */
alexpirciu 1:ceee5a608e7c 88 void serialCallbackBrake(char const * a, char * b);
alexpirciu 1:ceee5a608e7c 89 /* Hard BRAKE serial callback */
alexpirciu 1:ceee5a608e7c 90 void serialCallbackHardBrake(char const * a, char * b);
alexpirciu 1:ceee5a608e7c 91 /* PID serial callback */
alexpirciu 1:ceee5a608e7c 92 void serialCallbackPID(char const * a, char * b);
alexpirciu 1:ceee5a608e7c 93 /* Spline serial callback */
alexpirciu 1:ceee5a608e7c 94 void serialCallbackSpline(char const * a, char * b);
alexpirciu 1:ceee5a608e7c 95
alexpirciu 1:ceee5a608e7c 96
alexpirciu 1:ceee5a608e7c 97 /* Static function to convert from linear velocity ( centimeter per second ) of robot to angular velocity ( rotation per second ) of motor */
alexpirciu 1:ceee5a608e7c 98 static float Mps2Rps(float f_vel_cmps);
alexpirciu 1:ceee5a608e7c 99 // /* Velocity to PWM function */
alexpirciu 1:ceee5a608e7c 100 // static float VEL2PWM(float vel);
alexpirciu 1:ceee5a608e7c 101
alexpirciu 1:ceee5a608e7c 102 private:
alexpirciu 1:ceee5a608e7c 103 /* reference to Serial object */
alexpirciu 1:ceee5a608e7c 104 Serial& m_serialPort;
alexpirciu 1:ceee5a608e7c 105 /* reference to MOVE object */
alexpirciu 1:ceee5a608e7c 106 Move& m_car;
alexpirciu 1:ceee5a608e7c 107 /* Speed */
alexpirciu 1:ceee5a608e7c 108 float m_speed;
alexpirciu 1:ceee5a608e7c 109 /* Angle */
alexpirciu 1:ceee5a608e7c 110 float m_angle;
alexpirciu 1:ceee5a608e7c 111 /* PEriod i nseconds */
alexpirciu 1:ceee5a608e7c 112 float m_period_sec;
alexpirciu 1:ceee5a608e7c 113 /* Spline activation state */
alexpirciu 1:ceee5a608e7c 114 bool m_isSplineActivated;
alexpirciu 1:ceee5a608e7c 115 /* State machine state */
alexpirciu 1:ceee5a608e7c 116 uint8_t m_state;
alexpirciu 1:ceee5a608e7c 117 /* PID activation state */
alexpirciu 1:ceee5a608e7c 118 bool m_ispidActivated;
alexpirciu 1:ceee5a608e7c 119 // 0-none
alexpirciu 1:ceee5a608e7c 120 // 1-normal
alexpirciu 1:ceee5a608e7c 121 // 2-brake regeneration
alexpirciu 1:ceee5a608e7c 122
alexpirciu 1:ceee5a608e7c 123 /* motion planner object */
alexpirciu 1:ceee5a608e7c 124 planner::CBezierMotionPlanner m_motionPlanner;
alexpirciu 1:ceee5a608e7c 125 /* Timeout */
alexpirciu 1:ceee5a608e7c 126 Timeout m_hbTimeOut;
alexpirciu 1:ceee5a608e7c 127 /* Reference to control object */
alexpirciu 1:ceee5a608e7c 128 controllers::CControllerSiso* m_control;
alexpirciu 1:ceee5a608e7c 129 /* Reference to safety stop function */
alexpirciu 1:ceee5a608e7c 130 CSafetyStopFunction* m_safetyStop;
alexpirciu 1:ceee5a608e7c 131 /* Rtos timer for periodically applying */
alexpirciu 1:ceee5a608e7c 132 RtosTimer m_timer;
alexpirciu 1:ceee5a608e7c 133 };
alexpirciu 1:ceee5a608e7c 134
alexpirciu 1:ceee5a608e7c 135 #endif // MOTION_CONTROLLER_H
alexpirciu 1:ceee5a608e7c 136