Christian Burri / Mbed 2 deprecated autonomousRobotAndroid

Dependencies:   mbed

Fork of autonomousRobotAndroid by Christian Burri

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RobotControl.h Source File

RobotControl.h

00001 #ifndef _ROBOT_CONTROL_H_
00002 #define _ROBOT_CONTROL_H_
00003 
00004 #include "MaxonESCON.h"
00005 #include "MotionState.h"
00006 #include "Task.h"
00007 #include "defines.h"
00008 
00009 /**
00010  * @author Christian Burri
00011  *
00012  * @copyright Copyright (c) 2013 HSLU Pren Team #1 Cruising Crêpe
00013  * All rights reserved.
00014  *
00015  * @brief
00016  *
00017  * This class controls the position of the robot. It has
00018  * a run loop that is called periodically. This run loop reads the actual
00019  * positions of the wheels, calculates the actual position and orientation
00020  * of the robot, calculates to move the robot
00021  * and writes these velocity values to the motor servo drives.
00022  * This class offers methods to enable or disable the controller, and to set
00023  * the desired x- and y-postion and the θ values of the robot.
00024  *
00025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
00026  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00030  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00031  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  */
00033 
00034 class RobotControl : public Task
00035 {
00036 
00037 private:
00038 
00039     MaxonESCON*         motorControllerLeft;
00040     MaxonESCON*         motorControllerRight;
00041     MotionState         Desired;
00042     MotionState         Actual;
00043     MotionState         stateLeft;
00044     MotionState         stateRight;
00045     float               period;
00046     float               speed;
00047     float               omega;
00048 
00049     /**
00050      * @brief Add ±2π when the range of
00051      * the radian is over +π or under -π.
00052      * @param theta to check the value
00053      * @return the value in the range from -π to +π
00054      */
00055     float        PiRange(float theta);
00056 
00057 public:
00058 
00059     /**
00060      * @brief Creates a <code>Robot Control</code> object and
00061      * initializes all private state variables.
00062      * @param motorControllerLeft a reference to the servo
00063      * drive for the left motor
00064      * @param motorControllerRight a reference to the servo
00065      *  drive for the right motor
00066      * @param period the sampling period of the run loop of
00067      * this controller, given in [s]
00068      */
00069     RobotControl(MaxonESCON* motorControllerLeft,
00070                  MaxonESCON* motorControllerRight,
00071                  float period);
00072 
00073     /**
00074      * @brief Destructor of the Object to destroy the Object.
00075      **/
00076     virtual     ~RobotControl();
00077 
00078     /**
00079      * @brief Enables or disables the servo drives of the motors.
00080      * @param enable if <code>true</code> enables the drives,
00081      * <code>false</code> otherwise
00082      * the servo drives are shut down.
00083      */
00084     void        setEnable(bool enable);
00085 
00086     /**
00087      * @brief Tests if the servo drives of the motors are enabled.
00088      * @return <code>true</code> if the drives are enabled,
00089      * <code>false</code> otherwise
00090      */
00091     bool        isEnabled();
00092 
00093     /**
00094      * @brief Sets the desired translational speed of the robot.
00095      * @param speed the desired speed, given in [m/s]
00096      */
00097     void        setDesiredSpeed(float speed);
00098 
00099     /**
00100      * @brief Sets the desired rotational speed of the robot.
00101      * @param omega the desired rotational speed, given in [rad/s]
00102      */
00103     void        setDesiredOmega(float omega);
00104 
00105     /**
00106      * @brief Sets the desired X-position of the robot.
00107      * @param xposition the desired position, given in [m]
00108      */
00109     void        setDesiredxPosition(float xposition);
00110 
00111     /**
00112      * @brief Sets the desired Y-position of the robot.
00113      * @param yposition the desired position, given in [m]
00114      */
00115     void        setDesiredyPosition(float yposition);
00116 
00117     /**
00118      * @brief Sets the desired &theta; of the robot.
00119      * @param theta the desired &theta;, given in [rad]
00120      */
00121     void        setDesiredTheta(float theta);
00122 
00123     /**
00124      * @brief Get the desired X-position of the robot.
00125      * @return xposition the desired position, given in [m]
00126      */
00127     float        getDesiredxPosition();
00128 
00129     /**
00130      * @brief Get the desired Y-position of the robot.
00131      * @return yposition the desired position, given in [m]
00132      */
00133     float        getDesiredyPosition();
00134 
00135     /**
00136      * @brief Get the desired &theta; of the robot.
00137      * @return theta the desired &theta;, given in [rad]
00138      */
00139     float        getDesiredTheta();
00140 
00141     /**
00142      * @brief Sets the desired Position and &theta;.
00143      * @param xposition the desired position, given in [m]
00144      * @param yposition the desired position, given in [m]
00145      * @param theta the desired &theta;, given in [rad]
00146      */
00147     void        setDesiredPositionAndAngle(float xposition,
00148                                            float yposition,
00149                                            float theta);
00150 
00151     /**
00152      * @brief Gets the desired &theta; of the goal point.
00153      * @return the desired &theta;, given in [rad]
00154      */
00155     float       getTheta();
00156 
00157     /**
00158      * @brief Gets the desired translational speed of the robot.
00159      * @return the desired speed, given in [m/s]
00160      */
00161     float       getDesiredSpeed();
00162 
00163     /**
00164      * @brief Gets the actual translational speed of the robot.
00165      * @return the desired speed, given in [m/s]
00166      */
00167     float       getActualSpeed();
00168 
00169     /**
00170      * @brief Gets the desired rotational speed of the robot.
00171      * @return the desired speed, given in [rad/s]
00172      */
00173     float       getDesiredOmega();
00174 
00175     /**
00176      * @brief Gets the actual rotational speed of the robot.
00177      * @return the desired speed, given in [rad/s]
00178      */
00179     float       getActualOmega();
00180 
00181     /**
00182      * @brief Gets the actual translational X-position of the robot.
00183      * @return the actual position, given in [m]
00184      */
00185     float       getxActualPosition();
00186 
00187     /**
00188      * @brief Gets the X-position following error of the robot.
00189      * @return the position following error, given in [m]
00190      */
00191     float       getxPositionError();
00192 
00193     /**
00194      * @brief Gets the actual translational Y-position of the robot.
00195      * @return the actual position, given in [m]
00196      */
00197     float       getyActualPosition();
00198 
00199     /**
00200      * @brief Gets the Y-position following error of the robot.
00201      * @return the position following error, given in [m]
00202      */
00203     float       getyPositionError();
00204 
00205     /**
00206      * @brief Gets the actual orientation of the robot.
00207      * @return the orientation, given in [rad]
00208      */
00209     float       getActualTheta();
00210 
00211     /**
00212      * @brief Gets the orientation following error of the robot.
00213      * @return the orientation following error, given in [rad]
00214      */
00215     float       getThetaError();
00216 
00217     /**
00218      * @brief Gets the distance to disired point. Calculate with pythagoras.
00219      * @return distance to goal, given in [m]
00220      */
00221     float       getDistanceError();
00222 
00223     /**
00224      * @brief Gets the &theta; ot the pointing vector to the goal right
00225      * the unicycle axis from actual point.
00226      * @return theta to goal, given in [rad]
00227      */
00228     float       getThetaErrorToGoal();
00229 
00230     /**
00231      * @brief Gets the &theta; ot the pointing vector to the goal right the unicycle main axis.
00232      * @return theta from the goal, given in [rad]
00233      */
00234     float       getThetaGoal();
00235 
00236     /**
00237      * @brief Set all state to zero, except the X-position, y-position and &theta;.
00238      * @param xZeroPos Sets the start X-position, given in [m]
00239      * @param yZeroPos Sets the start y-position, given in [m]
00240      * @param theta Sets the start &theta;, given in [rad]
00241      */
00242     void        setAllToZero(float xZeroPos,
00243                              float yZeroPos,
00244                              float theta);
00245 
00246     /**
00247      * @brief Run method actualize every period.
00248      */
00249     void        run();
00250 };
00251 
00252 #endif