This program is for an autonomous robot for the competition at the Hochschule Luzern. http://cruisingcrepe.wordpress.com/ We are one of the 32 teams. http://cruisingcrepe.wordpress.com/ The postition control is based on this Documentation: Control of Wheeled Mobile Robots: An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli. For more information see here: http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf

Dependencies:   mbed

Fork of autonomous Robot Android by Christian Burri

Committer:
chrigelburri
Date:
Fri Apr 05 10:58:42 2013 +0000
Revision:
11:775ebb69d5e1
Parent:
6:48eeb41188dd
Child:
12:235e318a414f
doku soweit gut ohne android

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chrigelburri 0:31f7be68e52d 1 #ifndef _ROBOT_CONTROL_H_
chrigelburri 0:31f7be68e52d 2 #define _ROBOT_CONTROL_H_
chrigelburri 0:31f7be68e52d 3
chrigelburri 0:31f7be68e52d 4 #include "MaxonESCON.h"
chrigelburri 0:31f7be68e52d 5 #include "MotionState.h"
chrigelburri 0:31f7be68e52d 6 #include "Task.h"
chrigelburri 0:31f7be68e52d 7 #include "defines.h"
chrigelburri 0:31f7be68e52d 8
chrigelburri 0:31f7be68e52d 9 /**
chrigelburri 0:31f7be68e52d 10 * @author Christian Burri
chrigelburri 0:31f7be68e52d 11 *
chrigelburri 11:775ebb69d5e1 12 * @copyright Copyright © 2013 HSLU Pren Team #1 Cruising Crêpe
chrigelburri 0:31f7be68e52d 13 * All rights reserved.
chrigelburri 0:31f7be68e52d 14 *
chrigelburri 11:775ebb69d5e1 15 * @brief
chrigelburri 0:31f7be68e52d 16 *
chrigelburri 3:92ba0254af87 17 * This class controls the position of the robot. It has
chrigelburri 0:31f7be68e52d 18 * a run loop that is called periodically. This run loop reads the actual
chrigelburri 0:31f7be68e52d 19 * positions of the wheels, calculates the actual position and orientation
chrigelburri 3:92ba0254af87 20 * of the robot, calculates to move the robot
chrigelburri 0:31f7be68e52d 21 * and writes these velocity values to the motor servo drives.
chrigelburri 0:31f7be68e52d 22 * This class offers methods to enable or disable the controller, and to set
chrigelburri 3:92ba0254af87 23 * the desired x- and y-postion and the θ values of the robot.
chrigelburri 0:31f7be68e52d 24 */
chrigelburri 0:31f7be68e52d 25
chrigelburri 0:31f7be68e52d 26 class RobotControl : public Task
chrigelburri 0:31f7be68e52d 27 {
chrigelburri 0:31f7be68e52d 28
chrigelburri 0:31f7be68e52d 29 private:
chrigelburri 0:31f7be68e52d 30
chrigelburri 0:31f7be68e52d 31 MaxonESCON* motorControllerLeft;
chrigelburri 0:31f7be68e52d 32 MaxonESCON* motorControllerRight;
chrigelburri 0:31f7be68e52d 33 MotionState Desired;
chrigelburri 0:31f7be68e52d 34 MotionState Actual;
chrigelburri 0:31f7be68e52d 35 MotionState stateLeft;
chrigelburri 0:31f7be68e52d 36 MotionState stateRight;
chrigelburri 0:31f7be68e52d 37 float period;
chrigelburri 0:31f7be68e52d 38 float speed;
chrigelburri 0:31f7be68e52d 39 float omega;
chrigelburri 1:6cd533a712c6 40
chrigelburri 6:48eeb41188dd 41 /**
chrigelburri 11:775ebb69d5e1 42 * @brief Add ±2π when the range of
chrigelburri 6:48eeb41188dd 43 * the radian is over +π or under -π.
chrigelburri 6:48eeb41188dd 44 * @param theta to check the value
chrigelburri 6:48eeb41188dd 45 * @return the value in the range from -π to +π
chrigelburri 6:48eeb41188dd 46 */
chrigelburri 6:48eeb41188dd 47 float PiRange(float theta);
chrigelburri 6:48eeb41188dd 48
chrigelburri 0:31f7be68e52d 49 public:
chrigelburri 0:31f7be68e52d 50
chrigelburri 0:31f7be68e52d 51 /**
chrigelburri 11:775ebb69d5e1 52 * @brief Creates a <code>Robot Control</code> object and
chrigelburri 6:48eeb41188dd 53 * initializes all private state variables.
chrigelburri 6:48eeb41188dd 54 * @param motorControllerLeft a reference to the servo
chrigelburri 6:48eeb41188dd 55 * drive for the left motor
chrigelburri 6:48eeb41188dd 56 * @param motorControllerRight a reference to the servo
chrigelburri 6:48eeb41188dd 57 * drive for the right motor
chrigelburri 11:775ebb69d5e1 58 * @param period the sampling period of the run loop of
chrigelburri 6:48eeb41188dd 59 * this controller, given in [s]
chrigelburri 0:31f7be68e52d 60 */
chrigelburri 6:48eeb41188dd 61 RobotControl(MaxonESCON* motorControllerLeft,
chrigelburri 11:775ebb69d5e1 62 MaxonESCON* motorControllerRight,
chrigelburri 6:48eeb41188dd 63 float period);
chrigelburri 0:31f7be68e52d 64
chrigelburri 0:31f7be68e52d 65 /**
chrigelburri 11:775ebb69d5e1 66 * @brief Destructor of the Object to destroy the Object.
chrigelburri 6:48eeb41188dd 67 **/
chrigelburri 0:31f7be68e52d 68 virtual ~RobotControl();
chrigelburri 0:31f7be68e52d 69
chrigelburri 0:31f7be68e52d 70 /**
chrigelburri 11:775ebb69d5e1 71 * @brief Enables or disables the servo drives of the motors.
chrigelburri 6:48eeb41188dd 72 * @param enable if <code>true</code> enables the drives,
chrigelburri 6:48eeb41188dd 73 * <code>false</code> otherwise
chrigelburri 6:48eeb41188dd 74 * the servo drives are shut down.
chrigelburri 6:48eeb41188dd 75 */
chrigelburri 0:31f7be68e52d 76 void setEnable(bool enable);
chrigelburri 0:31f7be68e52d 77
chrigelburri 0:31f7be68e52d 78 /**
chrigelburri 11:775ebb69d5e1 79 * @brief Tests if the servo drives of the motors are enabled.
chrigelburri 6:48eeb41188dd 80 * @return <code>true</code> if the drives are enabled,
chrigelburri 6:48eeb41188dd 81 * <code>false</code> otherwise
chrigelburri 6:48eeb41188dd 82 */
chrigelburri 0:31f7be68e52d 83 bool isEnabled();
chrigelburri 0:31f7be68e52d 84
chrigelburri 0:31f7be68e52d 85 /**
chrigelburri 11:775ebb69d5e1 86 * @brief Sets the maximum acceleration value.
chrigelburri 6:48eeb41188dd 87 * @param acceleration the maximum acceleration value to use
chrigelburri 6:48eeb41188dd 88 * for the calculation of the motion trajectory, given in [m/s<SUP>2</SUP>]
chrigelburri 6:48eeb41188dd 89 */
chrigelburri 1:6cd533a712c6 90 void setAcceleration(float acceleration);
chrigelburri 0:31f7be68e52d 91
chrigelburri 0:31f7be68e52d 92 /**
chrigelburri 11:775ebb69d5e1 93 * @brief Sets the maximum acceleration value of rotation.
chrigelburri 6:48eeb41188dd 94 * @param acceleration the maximum acceleration value
chrigelburri 6:48eeb41188dd 95 * to use for the calculation of the motion trajectory,
chrigelburri 6:48eeb41188dd 96 * given in [rad/s<SUP>2</SUP>]
chrigelburri 6:48eeb41188dd 97 */
chrigelburri 1:6cd533a712c6 98 void setThetaAcceleration(float acceleration);
chrigelburri 0:31f7be68e52d 99
chrigelburri 0:31f7be68e52d 100 /**
chrigelburri 11:775ebb69d5e1 101 * @brief Sets the desired translational speed of the robot.
chrigelburri 6:48eeb41188dd 102 * @param speed the desired speed, given in [m/s]
chrigelburri 6:48eeb41188dd 103 */
chrigelburri 0:31f7be68e52d 104 void setDesiredSpeed(float speed);
chrigelburri 0:31f7be68e52d 105
chrigelburri 0:31f7be68e52d 106 /**
chrigelburri 11:775ebb69d5e1 107 * @brief Sets the desired rotational speed of the robot.
chrigelburri 6:48eeb41188dd 108 * @param omega the desired rotational speed, given in [rad/s]
chrigelburri 6:48eeb41188dd 109 */
chrigelburri 0:31f7be68e52d 110 void setDesiredOmega(float omega);
chrigelburri 0:31f7be68e52d 111
chrigelburri 0:31f7be68e52d 112 /**
chrigelburri 11:775ebb69d5e1 113 * @brief Sets the desired X-position of the robot.
chrigelburri 6:48eeb41188dd 114 * @param xposition the desired position, given in [m]
chrigelburri 6:48eeb41188dd 115 */
chrigelburri 5:48a258f6335e 116 void setDesiredxPosition(float xposition);
chrigelburri 0:31f7be68e52d 117
chrigelburri 0:31f7be68e52d 118 /**
chrigelburri 11:775ebb69d5e1 119 * @brief Sets the desired Y-position of the robot.
chrigelburri 6:48eeb41188dd 120 * @param yposition the desired position, given in [m]
chrigelburri 6:48eeb41188dd 121 */
chrigelburri 5:48a258f6335e 122 void setDesiredyPosition(float yposition);
chrigelburri 0:31f7be68e52d 123
chrigelburri 0:31f7be68e52d 124 /**
chrigelburri 11:775ebb69d5e1 125 * @brief Sets the desired &theta; of the robot.
chrigelburri 6:48eeb41188dd 126 * @param theta the desired &theta;, given in [rad]
chrigelburri 6:48eeb41188dd 127 */
chrigelburri 5:48a258f6335e 128 void setDesiredTheta(float theta);
chrigelburri 6:48eeb41188dd 129
chrigelburri 6:48eeb41188dd 130 /**
chrigelburri 11:775ebb69d5e1 131 * @brief Get the desired X-position of the robot.
chrigelburri 6:48eeb41188dd 132 * @return xposition the desired position, given in [m]
chrigelburri 6:48eeb41188dd 133 */
chrigelburri 5:48a258f6335e 134 float getDesiredxPosition();
chrigelburri 5:48a258f6335e 135
chrigelburri 5:48a258f6335e 136 /**
chrigelburri 11:775ebb69d5e1 137 * @brief Get the desired Y-position of the robot.
chrigelburri 6:48eeb41188dd 138 * @return yposition the desired position, given in [m]
chrigelburri 6:48eeb41188dd 139 */
chrigelburri 5:48a258f6335e 140 float getDesiredyPosition();
chrigelburri 5:48a258f6335e 141
chrigelburri 5:48a258f6335e 142 /**
chrigelburri 11:775ebb69d5e1 143 * @brief Get the desired &theta; of the robot.
chrigelburri 6:48eeb41188dd 144 * @return theta the desired &theta;, given in [rad]
chrigelburri 6:48eeb41188dd 145 */
chrigelburri 5:48a258f6335e 146 float getDesiredTheta();
chrigelburri 3:92ba0254af87 147
chrigelburri 1:6cd533a712c6 148 /**
chrigelburri 11:775ebb69d5e1 149 * @brief Sets the desired Position and &theta;.
chrigelburri 6:48eeb41188dd 150 * @param xposition the desired position, given in [m]
chrigelburri 6:48eeb41188dd 151 * @param yposition the desired position, given in [m]
chrigelburri 6:48eeb41188dd 152 * @param theta the desired &theta;, given in [rad]
chrigelburri 6:48eeb41188dd 153 */
chrigelburri 6:48eeb41188dd 154 void setDesiredPositionAndAngle(float xposition,
chrigelburri 6:48eeb41188dd 155 float yposition,
chrigelburri 6:48eeb41188dd 156 float theta);
chrigelburri 2:d8e1613dc38b 157
chrigelburri 2:d8e1613dc38b 158 /**
chrigelburri 11:775ebb69d5e1 159 * @brief Gets the desired &theta; of the goal point.
chrigelburri 3:92ba0254af87 160 * @return the desired &theta;, given in [rad]
chrigelburri 1:6cd533a712c6 161 */
chrigelburri 1:6cd533a712c6 162 float getTheta();
chrigelburri 0:31f7be68e52d 163
chrigelburri 0:31f7be68e52d 164 /**
chrigelburri 11:775ebb69d5e1 165 * @brief Gets the desired translational speed of the robot.
chrigelburri 3:92ba0254af87 166 * @return the desired speed, given in [m/s]
chrigelburri 0:31f7be68e52d 167 */
chrigelburri 0:31f7be68e52d 168 float getDesiredSpeed();
chrigelburri 0:31f7be68e52d 169
chrigelburri 0:31f7be68e52d 170 /**
chrigelburri 11:775ebb69d5e1 171 * @brief Gets the actual translational speed of the robot.
chrigelburri 3:92ba0254af87 172 * @return the desired speed, given in [m/s]
chrigelburri 0:31f7be68e52d 173 */
chrigelburri 0:31f7be68e52d 174 float getActualSpeed();
chrigelburri 0:31f7be68e52d 175
chrigelburri 0:31f7be68e52d 176 /**
chrigelburri 11:775ebb69d5e1 177 * @brief Gets the desired rotational speed of the robot.
chrigelburri 6:48eeb41188dd 178 * @return the desired speed, given in [rad/s]
chrigelburri 6:48eeb41188dd 179 */
chrigelburri 0:31f7be68e52d 180 float getDesiredOmega();
chrigelburri 0:31f7be68e52d 181
chrigelburri 0:31f7be68e52d 182 /**
chrigelburri 11:775ebb69d5e1 183 * @brief Gets the actual rotational speed of the robot.
chrigelburri 6:48eeb41188dd 184 * @return the desired speed, given in [rad/s]
chrigelburri 6:48eeb41188dd 185 */
chrigelburri 0:31f7be68e52d 186 float getActualOmega();
chrigelburri 0:31f7be68e52d 187
chrigelburri 0:31f7be68e52d 188 /**
chrigelburri 11:775ebb69d5e1 189 * @brief Gets the actual translational X-position of the robot.
chrigelburri 6:48eeb41188dd 190 * @return the actual position, given in [m]
chrigelburri 6:48eeb41188dd 191 */
chrigelburri 0:31f7be68e52d 192 float getxActualPosition();
chrigelburri 0:31f7be68e52d 193
chrigelburri 0:31f7be68e52d 194 /**
chrigelburri 11:775ebb69d5e1 195 * @brief Gets the X-position following error of the robot.
chrigelburri 6:48eeb41188dd 196 * @return the position following error, given in [m]
chrigelburri 6:48eeb41188dd 197 */
chrigelburri 0:31f7be68e52d 198 float getxPositionError();
chrigelburri 0:31f7be68e52d 199
chrigelburri 0:31f7be68e52d 200 /**
chrigelburri 11:775ebb69d5e1 201 * @brief Gets the actual translational Y-position of the robot.
chrigelburri 6:48eeb41188dd 202 * @return the actual position, given in [m]
chrigelburri 6:48eeb41188dd 203 */
chrigelburri 0:31f7be68e52d 204 float getyActualPosition();
chrigelburri 0:31f7be68e52d 205
chrigelburri 0:31f7be68e52d 206 /**
chrigelburri 11:775ebb69d5e1 207 * @brief Gets the Y-position following error of the robot.
chrigelburri 6:48eeb41188dd 208 * @return the position following error, given in [m]
chrigelburri 6:48eeb41188dd 209 */
chrigelburri 0:31f7be68e52d 210 float getyPositionError();
chrigelburri 0:31f7be68e52d 211
chrigelburri 0:31f7be68e52d 212 /**
chrigelburri 11:775ebb69d5e1 213 * @brief Gets the actual orientation of the robot.
chrigelburri 6:48eeb41188dd 214 * @return the orientation, given in [rad]
chrigelburri 6:48eeb41188dd 215 */
chrigelburri 0:31f7be68e52d 216 float getActualTheta();
chrigelburri 0:31f7be68e52d 217
chrigelburri 0:31f7be68e52d 218 /**
chrigelburri 11:775ebb69d5e1 219 * @brief Gets the orientation following error of the robot.
chrigelburri 6:48eeb41188dd 220 * @return the orientation following error, given in [rad]
chrigelburri 6:48eeb41188dd 221 */
chrigelburri 0:31f7be68e52d 222 float getThetaError();
chrigelburri 3:92ba0254af87 223
chrigelburri 1:6cd533a712c6 224 /**
chrigelburri 11:775ebb69d5e1 225 * @brief Gets the distance to disired point. Calculate with pythagoras.
chrigelburri 6:48eeb41188dd 226 * @return distance to goal, given in [m]
chrigelburri 6:48eeb41188dd 227 */
chrigelburri 1:6cd533a712c6 228 float getDistanceError();
chrigelburri 3:92ba0254af87 229
chrigelburri 1:6cd533a712c6 230 /**
chrigelburri 11:775ebb69d5e1 231 * @brief Gets the &theta; ot the pointing vector to the goal right
chrigelburri 6:48eeb41188dd 232 * the unicycle axis from actual point.
chrigelburri 6:48eeb41188dd 233 * @return theta to goal, given in [rad]
chrigelburri 6:48eeb41188dd 234 */
chrigelburri 1:6cd533a712c6 235 float getThetaErrorToGoal();
chrigelburri 3:92ba0254af87 236
chrigelburri 1:6cd533a712c6 237 /**
chrigelburri 11:775ebb69d5e1 238 * @brief Gets the &theta; ot the pointing vector to the goal right the unicycle main axis.
chrigelburri 6:48eeb41188dd 239 * @return theta from the goal, given in [rad]
chrigelburri 6:48eeb41188dd 240 */
chrigelburri 1:6cd533a712c6 241 float getThetaGoal();
chrigelburri 1:6cd533a712c6 242
chrigelburri 0:31f7be68e52d 243 /**
chrigelburri 11:775ebb69d5e1 244 * @brief Set all state to zero, except the X-position, y-position and &theta;.
chrigelburri 6:48eeb41188dd 245 * @param xZeroPos Sets the start X-position, given in [m]
chrigelburri 6:48eeb41188dd 246 * @param yZeroPos Sets the start y-position, given in [m]
chrigelburri 6:48eeb41188dd 247 * @param theta Sets the start &theta;, given in [rad]
chrigelburri 6:48eeb41188dd 248 */
chrigelburri 6:48eeb41188dd 249 void setAllToZero(float xZeroPos,
chrigelburri 6:48eeb41188dd 250 float yZeroPos,
chrigelburri 6:48eeb41188dd 251 float theta);
chrigelburri 0:31f7be68e52d 252
chrigelburri 11:775ebb69d5e1 253 /**
chrigelburri 11:775ebb69d5e1 254 * @brief Run method actualize every period.
chrigelburri 11:775ebb69d5e1 255 */
chrigelburri 0:31f7be68e52d 256 void run();
chrigelburri 0:31f7be68e52d 257 };
chrigelburri 0:31f7be68e52d 258
chrigelburri 0:31f7be68e52d 259 #endif