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 Feb 07 17:43:19 2013 +0000
Revision:
0:31f7be68e52d
Child:
1:6cd533a712c6
first steps

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 <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 0:31f7be68e52d 18 * Copyright (c) 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 0:31f7be68e52d 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 0:31f7be68e52d 48
chrigelburri 0:31f7be68e52d 49 float rho; /* Distance to goal [m]*/
chrigelburri 0:31f7be68e52d 50 float gamma; /* Angle of the start position to goal position [rad]*/
chrigelburri 0:31f7be68e52d 51
chrigelburri 0:31f7be68e52d 52
chrigelburri 0:31f7be68e52d 53
chrigelburri 0:31f7be68e52d 54 public:
chrigelburri 0:31f7be68e52d 55
chrigelburri 0:31f7be68e52d 56 /**
chrigelburri 0:31f7be68e52d 57 * Creates a robot control object and initializes all private
chrigelburri 0:31f7be68e52d 58 * state variables.
chrigelburri 0:31f7be68e52d 59 * @param motorControllerLeft a reference to the servo drive for the left motor.
chrigelburri 0:31f7be68e52d 60 * @param motorControllerRight a reference to the servo drive for the right motor.
chrigelburri 0:31f7be68e52d 61 * @param compass Modul HMC5883L
chrigelburri 0:31f7be68e52d 62 * @param period the sampling period of the run loop of this controller, given in [s].
chrigelburri 0:31f7be68e52d 63 */
chrigelburri 0:31f7be68e52d 64 RobotControl(MaxonESCON* motorControllerLeft, MaxonESCON* motorControllerRight, HMC6352* compass, float period);
chrigelburri 0:31f7be68e52d 65
chrigelburri 0:31f7be68e52d 66 /**
chrigelburri 0:31f7be68e52d 67 * Destructor of the Object to destroy the Object.
chrigelburri 0:31f7be68e52d 68 **/
chrigelburri 0:31f7be68e52d 69 virtual ~RobotControl();
chrigelburri 0:31f7be68e52d 70
chrigelburri 0:31f7be68e52d 71 /**
chrigelburri 0:31f7be68e52d 72 * Enables or disables the servo drives of the motors.
chrigelburri 0:31f7be68e52d 73 * @param enable if <code>true</code> enables the drives, <code>false</code> otherwise
chrigelburri 0:31f7be68e52d 74 * the servo drives are shut down.
chrigelburri 0:31f7be68e52d 75 */
chrigelburri 0:31f7be68e52d 76 void setEnable(bool enable);
chrigelburri 0:31f7be68e52d 77
chrigelburri 0:31f7be68e52d 78 /**
chrigelburri 0:31f7be68e52d 79 * Tests if the servo drives of the motors are enabled.
chrigelburri 0:31f7be68e52d 80 * @return <code>true</code> if the drives are enabled, <code>false</code> otherwise.
chrigelburri 0:31f7be68e52d 81 */
chrigelburri 0:31f7be68e52d 82 bool isEnabled();
chrigelburri 0:31f7be68e52d 83
chrigelburri 0:31f7be68e52d 84 /**
chrigelburri 0:31f7be68e52d 85 * Sets the maximum acceleration value.
chrigelburri 0:31f7be68e52d 86 * @param acceleration the maximum acceleration value to use for the calculation
chrigelburri 0:31f7be68e52d 87 * of the motion trajectory, given in [m/s&sup2;].
chrigelburri 0:31f7be68e52d 88 */
chrigelburri 0:31f7be68e52d 89 void setAcceleration(float acc);
chrigelburri 0:31f7be68e52d 90
chrigelburri 0:31f7be68e52d 91 /**
chrigelburri 0:31f7be68e52d 92 * Sets the maximum acceleration value of rotation.
chrigelburri 0:31f7be68e52d 93 * @param acceleration the maximum acceleration value to use for the calculation
chrigelburri 0:31f7be68e52d 94 * of the motion trajectory, given in [rad/s&sup2;].
chrigelburri 0:31f7be68e52d 95 */
chrigelburri 0:31f7be68e52d 96 void setThetaAcceleration(float acc);
chrigelburri 0:31f7be68e52d 97
chrigelburri 0:31f7be68e52d 98 /**
chrigelburri 0:31f7be68e52d 99 * Sets the desired translational speed of the robot.
chrigelburri 0:31f7be68e52d 100 * @param speed the desired speed, given in [m/s].
chrigelburri 0:31f7be68e52d 101 */
chrigelburri 0:31f7be68e52d 102 void setDesiredSpeed(float speed);
chrigelburri 0:31f7be68e52d 103
chrigelburri 0:31f7be68e52d 104 /**
chrigelburri 0:31f7be68e52d 105 * Sets the desired rotational speed of the robot.
chrigelburri 0:31f7be68e52d 106 * @param speed the desired speed, given in [rad/s].
chrigelburri 0:31f7be68e52d 107 */
chrigelburri 0:31f7be68e52d 108 void setDesiredOmega(float omega);
chrigelburri 0:31f7be68e52d 109
chrigelburri 0:31f7be68e52d 110 /**
chrigelburri 0:31f7be68e52d 111 * Sets the desired X- position of the robot.
chrigelburri 0:31f7be68e52d 112 * @param xpostion the desired position, given in [m].
chrigelburri 0:31f7be68e52d 113 */
chrigelburri 0:31f7be68e52d 114 void setxPosition(float position);
chrigelburri 0:31f7be68e52d 115
chrigelburri 0:31f7be68e52d 116 /**
chrigelburri 0:31f7be68e52d 117 * Sets the desired Y-position of the robot.
chrigelburri 0:31f7be68e52d 118 * @param ypostion the desired position, given in [m].
chrigelburri 0:31f7be68e52d 119 */
chrigelburri 0:31f7be68e52d 120 void setyPosition(float position);
chrigelburri 0:31f7be68e52d 121
chrigelburri 0:31f7be68e52d 122 /**
chrigelburri 0:31f7be68e52d 123 * Sets the angle of the robot.
chrigelburri 0:31f7be68e52d 124 * @param theta the desired angle, given in [rad].
chrigelburri 0:31f7be68e52d 125 */
chrigelburri 0:31f7be68e52d 126 void setTheta(float theta);
chrigelburri 0:31f7be68e52d 127
chrigelburri 0:31f7be68e52d 128 /**
chrigelburri 0:31f7be68e52d 129 * Gets the desired translational speed of the robot.
chrigelburri 0:31f7be68e52d 130 * @return the desired speed, given in [m/s].
chrigelburri 0:31f7be68e52d 131 */
chrigelburri 0:31f7be68e52d 132 float getDesiredSpeed();
chrigelburri 0:31f7be68e52d 133
chrigelburri 0:31f7be68e52d 134 /**
chrigelburri 0:31f7be68e52d 135 * Gets the actual translational speed of the robot.
chrigelburri 0:31f7be68e52d 136 * @return the desired speed, given in [m/s].
chrigelburri 0:31f7be68e52d 137 */
chrigelburri 0:31f7be68e52d 138 float getActualSpeed();
chrigelburri 0:31f7be68e52d 139
chrigelburri 0:31f7be68e52d 140 /**
chrigelburri 0:31f7be68e52d 141 * Gets the desired rotational speed of the robot.
chrigelburri 0:31f7be68e52d 142 * @return the desired speed, given in [rad/s].
chrigelburri 0:31f7be68e52d 143 */
chrigelburri 0:31f7be68e52d 144 float getDesiredOmega();
chrigelburri 0:31f7be68e52d 145
chrigelburri 0:31f7be68e52d 146 /**
chrigelburri 0:31f7be68e52d 147 * Gets the actual rotational speed of the robot.
chrigelburri 0:31f7be68e52d 148 * @return the desired speed, given in [rad/s].
chrigelburri 0:31f7be68e52d 149 */
chrigelburri 0:31f7be68e52d 150 float getActualOmega();
chrigelburri 0:31f7be68e52d 151
chrigelburri 0:31f7be68e52d 152 /**
chrigelburri 0:31f7be68e52d 153 * Gets the actual translational X-position of the robot.
chrigelburri 0:31f7be68e52d 154 * @return the actual position, given in [m].
chrigelburri 0:31f7be68e52d 155 */
chrigelburri 0:31f7be68e52d 156 float getxActualPosition();
chrigelburri 0:31f7be68e52d 157
chrigelburri 0:31f7be68e52d 158 /**
chrigelburri 0:31f7be68e52d 159 * Gets the X-position following error of the robot.
chrigelburri 0:31f7be68e52d 160 * @return the position following error, given in [m].
chrigelburri 0:31f7be68e52d 161 */
chrigelburri 0:31f7be68e52d 162 float getxPositionError();
chrigelburri 0:31f7be68e52d 163
chrigelburri 0:31f7be68e52d 164 /**
chrigelburri 0:31f7be68e52d 165 * Gets the actual translational Y-position of the robot.
chrigelburri 0:31f7be68e52d 166 * @return the actual position, given in [m].
chrigelburri 0:31f7be68e52d 167 */
chrigelburri 0:31f7be68e52d 168 float getyActualPosition();
chrigelburri 0:31f7be68e52d 169
chrigelburri 0:31f7be68e52d 170 /**
chrigelburri 0:31f7be68e52d 171 * Gets the Y-position following error of the robot.
chrigelburri 0:31f7be68e52d 172 * @return the position following error, given in [m].
chrigelburri 0:31f7be68e52d 173 */
chrigelburri 0:31f7be68e52d 174 float getyPositionError();
chrigelburri 0:31f7be68e52d 175
chrigelburri 0:31f7be68e52d 176 /**
chrigelburri 0:31f7be68e52d 177 * Gets the actual orientation of the robot.
chrigelburri 0:31f7be68e52d 178 * @return the orientation, given in [rad].
chrigelburri 0:31f7be68e52d 179 */
chrigelburri 0:31f7be68e52d 180 float getActualTheta();
chrigelburri 0:31f7be68e52d 181
chrigelburri 0:31f7be68e52d 182 /**
chrigelburri 0:31f7be68e52d 183 * Gets the orientation following error of the robot.
chrigelburri 0:31f7be68e52d 184 * @return the orientation following error, given in [rad].
chrigelburri 0:31f7be68e52d 185 */
chrigelburri 0:31f7be68e52d 186 float getThetaError();
chrigelburri 0:31f7be68e52d 187
chrigelburri 0:31f7be68e52d 188 /**
chrigelburri 0:31f7be68e52d 189 * Set all state to zero
chrigelburri 0:31f7be68e52d 190 * @param Sets the start X-position [m].
chrigelburri 0:31f7be68e52d 191 * @param Sets the start y-position [m].
chrigelburri 0:31f7be68e52d 192 */
chrigelburri 0:31f7be68e52d 193 void setAllToZero(float xZeroPos, float xZeroPos);
chrigelburri 0:31f7be68e52d 194
chrigelburri 0:31f7be68e52d 195 void run();
chrigelburri 0:31f7be68e52d 196 };
chrigelburri 0:31f7be68e52d 197
chrigelburri 0:31f7be68e52d 198 #endif