Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

reb.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) 2002
00024  *   John Sweeney, UMASS, Amherst, Laboratory for Perceptual Robotics
00025  *
00026  * $Id: reb.h,v 1.4 2004/09/07 23:38:33 inspectorg Exp $
00027  *
00028  * Header for the REB device.  This is the K-Team Robotics Extension
00029  * Board attached to their Kameleon 376BC.  We connect to it via
00030  * the serial port of our ADS Bitsy (StrongARM based).  SO the
00031  * architecture is similar to the P2OS device, in that the position, IR and
00032  * power services all need to go through a single serial port and
00033  * base device class.  So this code was copied from p2osdevice and
00034  * modified to taste.
00035  * 
00036  */
00037 
00038 #ifndef _REBDEVICE_H
00039 #define _REBDEVICE_H
00040 
00041 #include <pthread.h>
00042 #include <sys/time.h>
00043 #include <errno.h>
00044 
00045 // for poll
00046 #include <replace.h>
00047 
00048 #include <driver.h>
00049 #include <playercommon.h>
00050 #include <player.h>
00051 #include <drivertable.h>
00052 #include <reb_params.h>
00053 
00054 
00055 #define REB_CONFIG_BUFFER_SIZE 1024
00056 #define REB_BAUDRATE B38400
00057 #define REB_DEFAULT_SERIAL_PORT "/dev/ttySA1"
00058 
00059 #define REB_MOTOR_RIGHT 0
00060 #define REB_MOTOR_LEFT 2
00061 
00062 #define REB_BATTERY_CHANNEL 15
00063 
00064 #define REB_AD_OFF 0
00065 #define REB_AD_ON 1
00066 
00067 #define REB_FIXED_FACTOR 10000
00068 
00069 #define REB_MAX_ACC 100
00070 #define REB_MIN_ACC 10
00071 
00072 #define REB_POS_MODE_STRAIGHT 0
00073 #define REB_POS_MODE_ROTATION 1
00074 
00075 #define REB_IR_START 1
00076 #define REB_IR_STOP 0
00077 
00078 #define CRLF "\r\n"
00079 #define REB_RESTART_COMMAND "restart\r\n"
00080 #define REB_COMMAND_PROMPT ":\r\n"
00081 
00082 #ifndef ABS
00083 #define ABS(x) ((x) < 0 ? -(x) : (x))
00084 #endif
00085 
00086 #ifndef SGN
00087 #define SGN(x) ((x) < 0 ? -1 : 1)
00088 #endif
00089 
00090 /*
00091 typedef struct {
00092   player_position_data_t position;
00093   player_ir_data_t ir;
00094   player_power_data_t power;
00095 } __attribute__ ((packed)) player_reb_data_t;
00096 
00097 typedef struct {
00098   player_position_cmd_t position;
00099 } __attribute__ ((packed)) player_reb_cmd_t;
00100 */
00101 
00102 
00103 class REB : public Driver 
00104 {
00105 public:
00106   
00107   REB(ConfigFile *cf, int section);
00108 
00109   /* the main thread */
00110   virtual void Main();
00111   
00112   // we override these, because we will maintain our own subscription count
00113   virtual int Subscribe(player_device_id_t id);
00114   virtual int Unsubscribe(player_device_id_t id);
00115   
00116   virtual int Setup();
00117   virtual int Shutdown();
00118 
00119   void Restart();
00120 
00121   void ReadConfig();
00122 
00123   void SetOdometry(int, int, short);
00124   
00125   // handle IR
00126   void SetIRState(int);
00127 
00128   void UpdateData(void);
00129 
00130   void UpdateIRData(player_ir_data_t *);
00131   void UpdatePowerData(player_power_data_t *);
00132   void UpdatePosData(player_position_data_t *);
00133 
00134   // the following are all interface functions to the REB
00135   // this handles the A/D device which deals with IR for us
00136   void ConfigAD(int, int);
00137   unsigned short ReadAD(int);
00138   void ReadAllIR(uint16_t * ir);
00139 
00140   // this handles motor control
00141   void SetSpeed(int, int );
00142   int ReadSpeed(int);
00143 
00144   void SetPos(int, int);
00145   
00146   void SetPosCounter(int, int);
00147   int ReadPos(int);
00148   
00149   unsigned char ReadStatus(int, int *, int *);
00150   void ConfigPosPID(int, int, int, int);
00151   void ConfigSpeedPID(int, int, int, int);
00152   void ConfigSpeedProfile(int, int, int);
00153 
00154 private:
00155 
00156   int write_serial(char *, int);
00157   int read_serial_until(char *, int, char *, int);
00158   int write_command(char *buf, int len, int maxsize);
00159 
00160   player_device_id_t ir_id;
00161   player_device_id_t position_id;
00162   player_device_id_t power_id;
00163   
00164   int ir_subscriptions;
00165   int position_subscriptions;
00166   
00167   int param_index;  // index in the RobotParams table for this robot
00168   int reb_fd;               // reb device file descriptor
00169   
00170   struct timeval last_position; // last position update
00171   bool refresh_last_position;
00172   int last_lpos, last_rpos;
00173   int last_x_f, last_y_f;
00174   double last_theta;
00175 
00176   struct timeval last_pos_update; // time of last pos update
00177   struct timeval last_power_update;
00178   struct timeval last_ir_update;
00179 
00180   int pos_update_period;
00181 
00182   int current_heading;
00183   short desired_heading;
00184 
00185   int ir_sequence;
00186   struct timeval last_ir;
00187 
00188   bool motors_enabled;
00189   bool velocity_mode;
00190   bool direct_velocity_control;
00191 
00192   // device used to communicate with reb
00193   char reb_serial_port[MAX_FILENAME_SIZE]; 
00194 
00195   struct pollfd write_pfd, read_pfd;
00196 };
00197 
00198 
00199 #endif

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