This program is for an autonomous robot for the competition at the Hochschule Luzern. We are one of the 32 teams. <a href="http://cruisingcrepe.wordpress.com/">http://cruisingcrepe.wordpress.com/</a> 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: <a href="http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf">http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf</a>
Fork of autonomousRobotAndroid by
RobotControl/RobotControl.h@3:92ba0254af87, 2013-03-07 (annotated)
- Committer:
- chrigelburri
- Date:
- Thu Mar 07 09:47:07 2013 +0000
- Revision:
- 3:92ba0254af87
- Parent:
- 2:d8e1613dc38b
- Child:
- 5:48a258f6335e
bitte kommentare korriegieren;
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:6cd533a712c6 | 106 | void setxPosition(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 | 1:6cd533a712c6 | 112 | void setyPosition(float yposition); |
chrigelburri | 0:31f7be68e52d | 113 | |
chrigelburri | 0:31f7be68e52d | 114 | /** |
chrigelburri | 3:92ba0254af87 | 115 | * Sets the desired θ of the robot. |
chrigelburri | 3:92ba0254af87 | 116 | * @param theta the desired θ, given in [rad] |
chrigelburri | 0:31f7be68e52d | 117 | */ |
chrigelburri | 0:31f7be68e52d | 118 | void setTheta(float theta); |
chrigelburri | 3:92ba0254af87 | 119 | |
chrigelburri | 1:6cd533a712c6 | 120 | /** |
chrigelburri | 3:92ba0254af87 | 121 | * Sets the desired Position and θ. |
chrigelburri | 3:92ba0254af87 | 122 | * @param xposition the desired position, given in [m] |
chrigelburri | 3:92ba0254af87 | 123 | * @param yposition the desired position, given in [m] |
chrigelburri | 3:92ba0254af87 | 124 | * @param theta the desired θ, given in [rad] |
chrigelburri | 2:d8e1613dc38b | 125 | */ |
chrigelburri | 2:d8e1613dc38b | 126 | void setPositionAngle(float xposition, float yposition, float theta); |
chrigelburri | 2:d8e1613dc38b | 127 | |
chrigelburri | 2:d8e1613dc38b | 128 | /** |
chrigelburri | 3:92ba0254af87 | 129 | * Gets the desired θ of the goal point. |
chrigelburri | 3:92ba0254af87 | 130 | * @return the desired θ, given in [rad] |
chrigelburri | 1:6cd533a712c6 | 131 | */ |
chrigelburri | 1:6cd533a712c6 | 132 | float getTheta(); |
chrigelburri | 0:31f7be68e52d | 133 | |
chrigelburri | 0:31f7be68e52d | 134 | /** |
chrigelburri | 0:31f7be68e52d | 135 | * Gets the desired translational speed of the robot. |
chrigelburri | 3:92ba0254af87 | 136 | * @return the desired speed, given in [m/s] |
chrigelburri | 0:31f7be68e52d | 137 | */ |
chrigelburri | 0:31f7be68e52d | 138 | float getDesiredSpeed(); |
chrigelburri | 0:31f7be68e52d | 139 | |
chrigelburri | 0:31f7be68e52d | 140 | /** |
chrigelburri | 0:31f7be68e52d | 141 | * Gets the actual translational speed of the robot. |
chrigelburri | 3:92ba0254af87 | 142 | * @return the desired speed, given in [m/s] |
chrigelburri | 0:31f7be68e52d | 143 | */ |
chrigelburri | 0:31f7be68e52d | 144 | float getActualSpeed(); |
chrigelburri | 0:31f7be68e52d | 145 | |
chrigelburri | 0:31f7be68e52d | 146 | /** |
chrigelburri | 0:31f7be68e52d | 147 | * Gets the desired rotational speed of the robot. |
chrigelburri | 3:92ba0254af87 | 148 | * @return the desired speed, given in [rad/s] |
chrigelburri | 0:31f7be68e52d | 149 | */ |
chrigelburri | 0:31f7be68e52d | 150 | float getDesiredOmega(); |
chrigelburri | 0:31f7be68e52d | 151 | |
chrigelburri | 0:31f7be68e52d | 152 | /** |
chrigelburri | 0:31f7be68e52d | 153 | * Gets the actual rotational speed of the robot. |
chrigelburri | 3:92ba0254af87 | 154 | * @return the desired speed, given in [rad/s] |
chrigelburri | 0:31f7be68e52d | 155 | */ |
chrigelburri | 0:31f7be68e52d | 156 | float getActualOmega(); |
chrigelburri | 0:31f7be68e52d | 157 | |
chrigelburri | 0:31f7be68e52d | 158 | /** |
chrigelburri | 0:31f7be68e52d | 159 | * Gets the actual translational X-position of the robot. |
chrigelburri | 3:92ba0254af87 | 160 | * @return the actual position, given in [m] |
chrigelburri | 0:31f7be68e52d | 161 | */ |
chrigelburri | 0:31f7be68e52d | 162 | float getxActualPosition(); |
chrigelburri | 0:31f7be68e52d | 163 | |
chrigelburri | 0:31f7be68e52d | 164 | /** |
chrigelburri | 0:31f7be68e52d | 165 | * Gets the X-position following error of the robot. |
chrigelburri | 3:92ba0254af87 | 166 | * @return the position following error, given in [m] |
chrigelburri | 0:31f7be68e52d | 167 | */ |
chrigelburri | 0:31f7be68e52d | 168 | float getxPositionError(); |
chrigelburri | 0:31f7be68e52d | 169 | |
chrigelburri | 0:31f7be68e52d | 170 | /** |
chrigelburri | 0:31f7be68e52d | 171 | * Gets the actual translational Y-position of the robot. |
chrigelburri | 3:92ba0254af87 | 172 | * @return the actual position, given in [m] |
chrigelburri | 0:31f7be68e52d | 173 | */ |
chrigelburri | 0:31f7be68e52d | 174 | float getyActualPosition(); |
chrigelburri | 0:31f7be68e52d | 175 | |
chrigelburri | 0:31f7be68e52d | 176 | /** |
chrigelburri | 0:31f7be68e52d | 177 | * Gets the Y-position following error of the robot. |
chrigelburri | 3:92ba0254af87 | 178 | * @return the position following error, given in [m] |
chrigelburri | 0:31f7be68e52d | 179 | */ |
chrigelburri | 0:31f7be68e52d | 180 | float getyPositionError(); |
chrigelburri | 0:31f7be68e52d | 181 | |
chrigelburri | 0:31f7be68e52d | 182 | /** |
chrigelburri | 0:31f7be68e52d | 183 | * Gets the actual orientation of the robot. |
chrigelburri | 3:92ba0254af87 | 184 | * @return the orientation, given in [rad] |
chrigelburri | 0:31f7be68e52d | 185 | */ |
chrigelburri | 0:31f7be68e52d | 186 | float getActualTheta(); |
chrigelburri | 0:31f7be68e52d | 187 | |
chrigelburri | 0:31f7be68e52d | 188 | /** |
chrigelburri | 0:31f7be68e52d | 189 | * Gets the orientation following error of the robot. |
chrigelburri | 3:92ba0254af87 | 190 | * @return the orientation following error, given in [rad] |
chrigelburri | 0:31f7be68e52d | 191 | */ |
chrigelburri | 0:31f7be68e52d | 192 | float getThetaError(); |
chrigelburri | 3:92ba0254af87 | 193 | |
chrigelburri | 1:6cd533a712c6 | 194 | /** |
chrigelburri | 3:92ba0254af87 | 195 | * Gets the distance to disired point. Calculate with pythagoras. |
chrigelburri | 3:92ba0254af87 | 196 | * @return distance to goal, given in [m] |
chrigelburri | 1:6cd533a712c6 | 197 | */ |
chrigelburri | 1:6cd533a712c6 | 198 | float getDistanceError(); |
chrigelburri | 3:92ba0254af87 | 199 | |
chrigelburri | 1:6cd533a712c6 | 200 | /** |
chrigelburri | 3:92ba0254af87 | 201 | * Gets the θ ot the pointing vector to the goal right the unicycle axis from actual point. |
chrigelburri | 3:92ba0254af87 | 202 | * @return theta to goal, given in [rad] |
chrigelburri | 1:6cd533a712c6 | 203 | */ |
chrigelburri | 1:6cd533a712c6 | 204 | float getThetaErrorToGoal(); |
chrigelburri | 3:92ba0254af87 | 205 | |
chrigelburri | 1:6cd533a712c6 | 206 | /** |
chrigelburri | 3:92ba0254af87 | 207 | * Gets the θ ot the pointing vector to the goal right the unicycle main axis. |
chrigelburri | 3:92ba0254af87 | 208 | * @return theta from the goal, given in [rad] |
chrigelburri | 1:6cd533a712c6 | 209 | */ |
chrigelburri | 1:6cd533a712c6 | 210 | float getThetaGoal(); |
chrigelburri | 1:6cd533a712c6 | 211 | |
chrigelburri | 0:31f7be68e52d | 212 | /** |
chrigelburri | 3:92ba0254af87 | 213 | * Set all state to zero, except the X-position, y-position and θ. |
chrigelburri | 3:92ba0254af87 | 214 | * @param xZeroPos Sets the start X-position, given in [m] |
chrigelburri | 3:92ba0254af87 | 215 | * @param yZeroPos Sets the start y-position, given in [m] |
chrigelburri | 3:92ba0254af87 | 216 | * @param theta Sets the start θ, given in [rad] |
chrigelburri | 0:31f7be68e52d | 217 | */ |
chrigelburri | 1:6cd533a712c6 | 218 | void setAllToZero(float xZeroPos, float yZeroPos, float theta); |
chrigelburri | 0:31f7be68e52d | 219 | |
chrigelburri | 3:92ba0254af87 | 220 | /** |
chrigelburri | 3:92ba0254af87 | 221 | * Add ±2π when the range of the radian is over +π or under -π. |
chrigelburri | 3:92ba0254af87 | 222 | * @param theta to check the value |
chrigelburri | 3:92ba0254af87 | 223 | * @return the value in the range from -π to +π |
chrigelburri | 3:92ba0254af87 | 224 | */ |
chrigelburri | 3:92ba0254af87 | 225 | float PiRange(float theta); |
chrigelburri | 3:92ba0254af87 | 226 | |
chrigelburri | 0:31f7be68e52d | 227 | void run(); |
chrigelburri | 0:31f7be68e52d | 228 | }; |
chrigelburri | 0:31f7be68e52d | 229 | |
chrigelburri | 0:31f7be68e52d | 230 | #endif |