rflex.h

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  *   this file was adapted from the P2OS device for the RWI RFLEX robots
00025  *
00026  *   the RFLEX device.  it's the parent device for all the RFLEX 'sub-devices',
00027  *   like, position, sonar, etc.  there's a thread here that
00028  *   actually interacts with RFLEX via the serial line.  the other
00029  *   "devices" communicate with this thread by putting into and getting
00030  *   data out of shared buffers.
00031  */
00032 #ifndef _RFLEXDEVICE_H
00033 #define _RFLEXDEVICE_H
00034 
00035 #include <pthread.h>
00036 #include <sys/time.h>
00037 
00038 #include <libplayercore/playercore.h>
00039    
00040 #include "rflex_commands.h"
00041 #include "rflex-io.h"
00042 
00043 #include "rflex_configs.h"
00044 
00045 #define RFLEX_MOTORS_REQUEST_ON 0
00046 #define RFLEX_MOTORS_ON 1
00047 #define RFLEX_MOTORS_REQUEST_OFF 2
00048 #define RFLEX_MOTORS_OFF 3
00049 
00050 #define RFLEX_CONFIG_BUFFER_SIZE 256
00051 
00052 #define DEFAULT_RFLEX_PORT "/dev/ttyS0"
00053 
00054 #define DEFAULT_RFLEX_BUMPER_ADDRESS 0x40
00055 #define RFLEX_BUMPER_STYLE_BIT "bit"
00056 #define RFLEX_BUMPER_STYLE_ADDR "addr"
00057 #define DEFAULT_RFLEX_BUMPER_STYLE RFLEX_BUMPER_STYLE_ADDR
00058 
00059 enum 
00060 {
00061    BUMPER_BIT,
00062    BUMPER_ADDR
00063 };
00064 
00065 #define DEFAULT_RFLEX_POWER_OFFSET 0
00066 
00067 #define MAX_NUM_LOOPS                 30
00068 #define B_STX                         0x02
00069 #define B_ETX                         0x03
00070 #define B_ESC                         0x1b
00071 
00072 typedef struct player_rflex_data
00073 {
00074   player_position2d_data_t position;
00075   player_sonar_data_t sonar;
00076   player_sonar_data_t sonar2;
00077   player_gripper_data_t gripper;
00078   player_power_data_t power;
00079   player_bumper_data_t bumper;
00080   player_dio_data_t dio;
00081   player_aio_data_t aio;
00082   player_ir_data ir;
00083 } __attribute__ ((packed)) player_rflex_data_t;
00084 
00085 /*
00086 typedef struct
00087 {
00088   player_position_cmd_t position;
00089   player_gripper_cmd_t gripper;
00090   player_sound_cmd_t sound;
00091 } __attribute__ ((packed)) player_rflex_cmd_t;
00092 */
00093 
00094 // this is here because we need the above typedef's before including it.
00095 
00096 class RFLEX : public Driver 
00097 {
00098   private:
00099     player_devaddr_t position_id;
00100     player_devaddr_t sonar_id;
00101     player_devaddr_t sonar_id_2;
00102     player_devaddr_t ir_id;
00103     player_devaddr_t bumper_id;
00104     player_devaddr_t power_id;
00105     player_devaddr_t aio_id;
00106     player_devaddr_t dio_id;
00107         player_position2d_cmd_vel_t command;
00108         int command_type;
00109 
00110     int position_subscriptions;
00111     int sonar_subscriptions;
00112     int ir_subscriptions;
00113     int bumper_subscriptions;
00114 
00115     int rflex_fd;               // rflex device file descriptor
00116     
00117     // device used to communicate with rflex
00118     char rflex_serial_port[MAX_FILENAME_SIZE]; 
00119     double m_odo_x;
00120     double m_odo_y;
00121     double rad_odo_theta;
00122 
00123     void ResetRawPositions();
00124     int initialize_robot();
00125     void reset_odometry();
00126     void set_odometry(float,float,float);
00127     void update_everything(player_rflex_data_t* d);
00128 
00129     void set_config_defaults();
00130 
00131   public:
00132     RFLEX(ConfigFile* cf, int section);
00133     ~RFLEX();
00134 
00135     /* the main thread */
00136     virtual void Main();
00137 
00138     // we override these, because we will maintain our own subscription count
00139     virtual int Subscribe(player_devaddr_t addr);
00140     virtual int Unsubscribe(player_devaddr_t addr);
00141 
00142     virtual int Setup();
00143     virtual int Shutdown();
00144 
00149     virtual void StartThread(void);
00150 
00155     virtual void StopThread(void);
00156 
00157     static int joy_control;
00158         
00159         // MessageHandler
00160         int ProcessMessage(QueuePointer & resp_queue, player_msghdr * hdr, 
00161                                void * data);
00162         
00163         bool ThreadAlive;
00164 };
00165 
00166 
00167 #endif

Last updated 12 September 2005 21:38:45