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:
Thu Mar 21 08:56:53 2013 +0000
Revision:
5:48a258f6335e
Parent:
3:92ba0254af87
Child:
6:48eeb41188dd
vor dem Gr?nden m?nd?li;

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