miniQ.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 *
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2012, ISR University of Coimbra.
00006 *  All rights reserved.
00007 *
00008 *  Redistribution and use in source and binary forms, with or without
00009 *  modification, are permitted provided that the following conditions
00010 *  are met:
00011 *
00012 *   * Redistributions of source code must retain the above copyright
00013 *     notice, this list of conditions and the following disclaimer.
00014 *   * Redistributions in binary form must reproduce the above
00015 *     copyright notice, this list of conditions and the following
00016 *     disclaimer in the documentation and/or other materials provided
00017 *     with the distribution.
00018 *   * Neither the name of the ISR University of Coimbra nor the names of its
00019 *     contributors may be used to endorse or promote products derived
00020 *     from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 *  POSSIBILITY OF SUCH DAMAGE.
00034 *
00035 * Author: Gonçalo Cabrita on 20/08/2012
00036 *********************************************************************/
00037 
00038 #include <cereal_port/CerealPort.h>
00039 
00040 #define MSG_LENGTH 64
00041 
00042 #define MINIQ_RATE 3.0
00043 
00044 class miniQ
00045 {
00046 public:
00047     
00049     typedef enum _miniQaction {
00050         
00051         // Get version
00052         MQ_ACTION_GET_VERSION = 1,
00053         // Actuate the robot
00054         MQ_ACTION_DRIVE = 2,
00055         MQ_ACTION_DRIVE_DIRECT = 3,
00056         // Get robot sensors
00057         MQ_ACTION_GET_ODOMETRY = 4,
00058         MQ_ACTION_GET_ENCODER_PULSES = 5,
00059         MQ_ACTION_GET_WHEEL_VELOCITIES = 6,
00060         MQ_ACTION_GET_GAS_SENSOR = 7,
00061         MQ_ACTION_GET_IR_BUMPER = 8,
00062         MQ_ACTION_GET_LINE_SENSOR = 9,
00063         MQ_ACTION_GET_BATTERY = 10,
00064         // Debug mode
00065         MQ_ACTION_GET_DEBUG = 11,
00066         MQ_ACTION_SET_DEBUG = 12,
00067         // Configuration
00068         MQ_ACTION_SET_PID_GAINS = 13,
00069         MQ_ACTION_GET_PID_GAINS = 14,
00070         MQ_ACTION_SET_ODOMETRY_CALIBRATION = 15,
00071         MQ_ACTION_GET_ODOMETRY_CALIBRATION = 16,
00072         MQ_ACTION_SET_ID = 17,
00073         MQ_ACTION_GET_ID = 18,
00074         MQ_ACTION_SET_MODE = 19,
00075         MQ_ACTION_GET_MODE = 20,
00076         MQ_ACTION_SET_GAS_CALIBRATION = 21,
00077         MQ_ACTION_GET_GAS_CALIBRATION = 22,
00078         MQ_ACTION_SET_BATTERY_TYPE = 23,
00079         MQ_ACTION_GET_BATTERY_TYPE = 24,
00080         MQ_ACTION_SET_TIMEOUT = 25,
00081         MQ_ACTION_GET_TIMEOUT = 26,
00082         // Group messages
00083         // Group 1 - Odometry, gas sensor
00084         MQ_ACTION_GET_GROUP_1 = 27,
00085         // Group 2 - Odometry, gas sensor, IR bumper
00086         MQ_ACTION_GET_GROUP_2 = 28,
00087         MQ_ACTION_COUNT = 29
00088         
00089     } miniQaction;
00090 
00091     typedef enum _miniQPID
00092     {
00093         LeftStartingPID = 0,
00094         LeftRunningPID = 1,
00095         RightStartingPID = 2,   
00096         RightRunningPID = 3
00097 
00098     } miniQPID;
00099     
00100     miniQ();
00101     ~miniQ();
00102     
00112     static bool openPort(char * port, int baudrate);
00113     
00121     bool checkVersion();
00122     
00131     void setVelocities(double linear_velocity, double angular_velocity);
00132     
00140     bool update();
00141     
00149     bool updateVelocities();
00150     
00158     double getX(){ return x_; }
00166     double getY(){ return y_; }
00174     double getYaw(){ return yaw_; }
00182     double getLinearVelocity(){ return linear_velocity_; }
00190     double getAngularVelocity(){ return angular_velocity_; }
00198     double getLeftWheelVelocity(){ return left_wheel_velocity_; }
00206     double getRightWheelVelocity(){ return right_wheel_velocity_; }
00214     double getGas(){ return gas_; }
00222     double getRawGas(){ return gas_raw_; }
00223 
00224     static int scanForId(int id);
00225 
00226     void setId(int id);
00227     int getID(){ return id_; };
00228 
00229     bool setMode(int mode);
00230     bool setBatteryType(int battery_type);
00231     bool setPIDGains(int kp, int ki, int kd, miniQPID pid);
00232     bool setOdometryCallibration(double odometry_d, double odometry_yaw);
00233     bool setGasSensorCallibration(double a, double b);
00234     bool setTimeout(double timeout);
00235 
00236     void setPWM(int left_pwm, int left_dir, int right_pwm, int right_dir);
00237 
00238     bool updateWheelVelocities();
00239     
00240 private:
00241     
00242     // RobChair variables
00244     double x_;
00246     double y_;
00248     double yaw_;
00250     double linear_velocity_;
00252     double angular_velocity_;
00254     double left_wheel_velocity_;
00256     double right_wheel_velocity_;
00257 
00259     double gas_;
00261     double gas_raw_;
00262 
00264     int id_;
00265     
00266     static cereal::CerealPort serial_port;
00267 };
00268 
00269 // EOF


lse_miniq_driver
Author(s): Gonçalo Cabrita
autogenerated on Mon Jan 6 2014 11:25:52