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