Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

clodbuster.h

Go to the documentation of this file.
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2000  
00004  *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
00005  *                      
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 /*
00024  * $Id: clodbuster.h,v 1.3 2004/11/11 01:39:33 gerkey Exp $
00025  *
00026  *   the clodbuster device.   there's a thread here that
00027  *   actually interacts with grasp board via the serial line.  the other
00028  *   "devices" communicate with this thread by putting into and getting
00029  *   data out of shared buffers.
00030  */
00031 #ifndef _CLODBUSTERDEVICE_H
00032 #define _CLODBUSTERDEVICE_H
00033 
00034 #include <pthread.h>
00035 #include <sys/time.h>
00036 
00037 #include <driver.h>
00038 #include <drivertable.h>
00039 #include <packet.h>
00040 #include <player.h>
00041 //#include <robot_params.h>
00042 /*  
00043 #define P2OS_MOTORS_REQUEST_ON 0
00044 #define P2OS_MOTORS_ON 1
00045 #define P2OS_MOTORS_REQUEST_OFF 2
00046 #define P2OS_MOTORS_OFF 3
00047 */
00048 /* data for the clodbuster */
00049 #define CLODBUSTER_CYCLETIME_USEC 50000
00050 
00051 /* Grasp Board Command numbers */
00052 #define SYNC 255
00053 
00054 #define SET_SERVO_THROTTLE 0
00055 #define SET_SERVO_FRONTSTEER 1
00056 #define SET_SERVO_BACKSTEER 2
00057 #define SET_SERVO_PAN 3
00058 
00059 #define ECHO_SERVO_VALUES 64 // 0x40
00060 #define ECHO_MAX_SERVO_LIMITS 65 //0x41
00061 #define ECHO_MIN_SERVO_LIMITS 66 //0x42
00062 #define ECHO_CEN_SERVO_LIMITS 67 //0x43
00063 
00064 #define ECHO_ENCODER_COUNTS 112 // 0x70
00065 #define ECHO_ENCODER_COUNTS_TS 113 // 0x71
00066 #define ECHO_ADC 128 //0x80
00067 #define READ_ID 97
00068 
00069 #define SET_SLEEP_MODE 144 // 0x90
00070 #define ECHO_SLEEP_MODE 145 // 0x91
00071 
00072 #define SLEEP_MODE_ON 1
00073 #define SLEEP_MODE_OFF 0
00074 
00075 #define SERVO_CHANNELS 8
00076 
00077 // I think this might be useful.. so leaving it in for the time being
00078 /* Argument types */
00079 #define ARGINT          0x3B    // Positive int (LSB, MSB)
00080 #define ARGNINT         0x1B    // Negative int (LSB, MSB)
00081 #define ARGSTR          0x2B    // String (Note: 1st byte is length!!)
00082 
00083 #define CLODBUSTER_CONFIG_BUFFER_SIZE 256
00084 
00085 #define DEFAULT_CLODBUSTER_PORT "/dev/ttyUSB0" // This has to be USB - serial port.
00086 
00087 typedef struct clodbuster_encoder_data
00088 { 
00089   uint32_t time_count;
00090   int32_t left,right;
00091 } __attribute__ ((packed)) clodbuster_encoder_data_t;
00092 
00093 class PIDGains
00094 {
00095  private:
00096      float kp, ki, kd, freq, k1, k2, k3;
00097      void findK()
00098           {
00099                float T=1.0/freq;
00100                k1 = kp + .5*T*ki + kd/T;
00101                k2 = -kp - 2.0*kd/T + .5*ki*T;
00102                k3 = kd/T;
00103                printf("Gain constants set to K1 = %f, K2 = %f, K3 = %f\n",k1,k2,k3);
00104           };
00105  public:
00106      PIDGains(float kp_, float ki_, float kd_, float freq_)
00107           :kp(kp_), ki(ki_), kd(kd_),freq(freq_)
00108           {
00109                findK();
00110           };
00111      //~PIDGains();
00112      void SetKp(float k)
00113           {
00114                kp=k;
00115                findK();
00116           };
00117      void SetKi(float k)
00118           {
00119                ki=k;
00120                findK();
00121           };
00122      void SetKd(float k)
00123           {
00124                kd=k;
00125                findK();
00126           };
00127      void SetFreq(float f)
00128           {
00129                freq=f;
00130                findK();
00131           };
00132      float K1(){return(k1);};
00133      float K2(){return(k2);};
00134      float K3(){return(k3);};
00135 };
00136 
00137 class ClodBuster:public Driver 
00138 {
00139   private:
00140     player_position_data_t position_data;
00141     void ResetRawPositions();
00142     clodbuster_encoder_data_t ReadEncoders();
00143 
00144     int clodbuster_fd;               // clodbuster device file descriptor
00145     
00146     // device used to communicate with GRASP IO Board
00147     char clodbuster_serial_port[MAX_FILENAME_SIZE]; 
00148    
00149     int kp,ki,kd;
00150 
00151     // did we initialize the common data segments yet?
00152     bool initdone;
00153     clodbuster_encoder_data_t encoder_offset;
00154     clodbuster_encoder_data_t encoder_measurement;
00155     clodbuster_encoder_data_t old_encoder_measurement;
00156     float EncV, EncOmega, EncVleft, EncVright;
00157 
00158     bool direct_command_control;
00159     unsigned char max_limits[SERVO_CHANNELS],center_limits[SERVO_CHANNELS],min_limits[SERVO_CHANNELS];
00160     void GetGraspBoardParams();
00161 
00162     // CB geometry parameters
00163     float WheelRadius;
00164     float WheelBase;
00165     float WheelSeparation;
00166     unsigned int CountsPerRev;
00167     float Kenc; // counts --> distance traveled
00168 
00169     // control parameters
00170     float LoopFreq;
00171     PIDGains *Kv, *Kw;
00172 
00173     void IntegrateEncoders();
00174     void DifferenceEncoders();
00175 
00176  protected:
00177 
00178     // Max motor speeds
00179     int motor_max_speed;
00180     int motor_max_turnspeed;
00181     
00182     // Bound the command velocities
00183     bool use_vel_band; 
00184         
00185 
00186   public:
00187 
00188     ClodBuster( ConfigFile* cf, int section);
00189     virtual ~ClodBuster();
00190 
00191     /* the main thread */
00192     virtual void Main();
00193 
00194     virtual int Setup();
00195     virtual int Shutdown();
00196 
00197     unsigned char SetServo(unsigned char chan, int value);
00198     void SetServo(unsigned char chan, unsigned char cmd);
00199     /*
00200     void CMUcamReset();
00201     void CMUcamTrack(int rmin=0, int rmax=0, int gmin=0,
00202                           int gmax=0, int bmin=0, int bmax=0);
00203     void CMUcamStopTracking();
00204 
00205     */ // don't want to have this right now.. but maybe eventually.
00206 };
00207 
00208 
00209 #endif

Generated on Tue May 3 14:15:33 2005 for Player by doxygen 1.3.6