Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

khepera.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 /* Copyright (C) 2004
00024  *   Toby Collett, University of Auckland Robotics Group
00025  *
00026  * Header for the khepera robot.  The
00027  * architecture is similar to the P2OS device, in that the position, IR and
00028  * power services all need to go through a single serial port and
00029  * base device class.  So this code was copied from p2osdevice and
00030  * modified to taste.
00031  * 
00032  */
00033 
00034 #ifndef _KHEPERADEVICE_H
00035 #define _KHEPERADEVICE_H
00036 
00037 #include <pthread.h>
00038 #include <sys/time.h>
00039 #include <errno.h>
00040 
00041 // for poll
00042 #include <replace.h>
00043 //#include <sys/poll.h>
00044 
00045 #include <driver.h>
00046 #include <playercommon.h>
00047 #include <player.h>
00048 #include <drivertable.h>
00049 //#include <khepera_params.h>
00050 #include <khepera_serial.h>
00051 
00052 #define KHEPERA_CONFIG_BUFFER_SIZE 1024
00053 #define KHEPERA_BAUDRATE B38400
00054 #define KHEPERA_DEFAULT_SERIAL_PORT "/dev/ttyUSB0"
00055 #define KHEPERA_DEFAULT_SCALE 10
00056 #define KHEPERA_DEFAULT_ENCODER_RES (1.0/12.0) 
00057 #define KHEPERA_DEFAULT_IR_CALIB_A (64.158)
00058 #define KHEPERA_DEFAULT_IR_CALIB_B (-0.1238)
00059 
00060 #define KHEPERA_MOTOR_LEFT 0
00061 #define KHEPERA_MOTOR_RIGHT 1
00062 
00063 #define KHEPERA_FIXED_FACTOR 10000
00064 
00065 #define CRLF "\r\n"
00066 #define KHEPERA_COMMAND_PROMPT "\r\n"
00067 
00068 #ifndef ABS
00069 #define ABS(x) ((x) < 0 ? -(x) : (x))
00070 #endif
00071 
00072 #ifndef SGN
00073 #define SGN(x) ((x) < 0 ? -1 : 1)
00074 #endif
00075 
00076 /*
00077 typedef struct {
00078   player_position_data_t position;
00079   player_ir_data_t ir;
00080 } __attribute__ ((packed)) player_khepera_data_t;
00081 */
00082 
00083 /*
00084 typedef struct {
00085   player_position_cmd_t position;
00086 } __attribute__ ((packed)) player_khepera_cmd_t;
00087 */
00088 
00089 typedef struct player_khepera_geom
00090 {
00091         char * PortName;
00092         double scale;
00093         player_ir_pose_t ir;
00094         double * ir_calib_a;
00095         double * ir_calib_b;
00096         player_position_geom_t position;
00097         double encoder_res;
00098 } __attribute__ ((packed)) player_khepera_geom_t;
00099         
00100 
00101 class Khepera : public Driver 
00102 {
00103 public:
00104   
00105   Khepera(ConfigFile *cf, int section);
00106 
00107   /* the main thread */
00108   virtual void Main();
00109 
00110   virtual int Subscribe(player_device_id_t id);
00111   virtual int Unsubscribe(player_device_id_t id);
00112   
00113   virtual int Setup();
00114   virtual int Shutdown();
00115   
00116   //  void Restart();
00117 
00118   short khtons(short in);
00119   short ntokhs(short in);
00120 
00121   void ReadConfig();
00122 
00123   int ResetOdometry();
00124   
00125   // handle IR
00126   void SetIRState(int);
00127 
00128   void UpdateData(void);
00129 
00130   void UpdateIRData(player_ir_data_t *);
00131   void UpdatePosData(player_position_data_t *);
00132 
00133   // the following are all interface functions to the REB
00134   // this handles the A/D device which deals with IR for us
00135   //void ConfigAD(int, int);
00136   unsigned short ReadAD(int);
00137   int ReadAllIR(player_ir_data_t *);
00138 
00139   // this handles motor control
00140   int SetSpeed(int, int);
00141   int ReadSpeed(int*, int*);
00142 
00143   int SetPos(int, int);
00144   
00145   int SetPosCounter(int, int);
00146   int ReadPos(int *, int*);
00147   
00148   //unsigned char ReadStatus(int, int *, int *);
00149 
00150 private:
00151   player_device_id_t ir_id;
00152   player_device_id_t position_id;
00153   int position_subscriptions;
00154   int ir_subscriptions;
00155 
00156   KheperaSerial * Serial;
00157 
00158 
00159   /*  int write_serial(char *, int);
00160       int read_serial_until(char *, int, char *, int);
00161       int write_command(char *buf, int len, int maxsize);*/
00162 
00163   player_khepera_geom_t* geometry;
00164 
00165   int param_index;  // index in the RobotParams table for this robot
00166   int khepera_fd;               // khepera device file descriptor
00167   
00168   struct timeval last_position; // last position update
00169   bool refresh_last_position;
00170   int last_lpos, last_rpos;
00171   double x,y,yaw;
00172   int last_x_f, last_y_f;
00173   double last_theta;
00174 
00175   struct timeval last_pos_update; // time of last pos update
00176   struct timeval last_ir_update;
00177 
00178   int pos_update_period;
00179 
00180   short desired_heading;
00181 
00182   int ir_sequence;
00183   struct timeval last_ir;
00184 
00185   bool motors_enabled;
00186   bool velocity_mode;
00187   bool direct_velocity_control;
00188 
00189   // device used to communicate with reb
00190   char khepera_serial_port[MAX_FILENAME_SIZE]; 
00191 
00192   struct pollfd write_pfd, read_pfd;
00193 };
00194 
00195 
00196 #endif

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