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:
Sun Apr 07 08:31:51 2013 +0000
Revision:
12:235e318a414f
Parent:
11:775ebb69d5e1
Child:
38:d76e488e725f
Kommentare nochmals verbessert android fehlt noch

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