|
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
rflex.hGo 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 * 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 <driver.h> 00039 #include <drivertable.h> 00040 #include <player.h> 00041 00042 #include "rflex_commands.h" 00043 #include "rflex-io.h" 00044 00045 #include "rflex_configs.h" 00046 00047 #define RFLEX_MOTORS_REQUEST_ON 0 00048 #define RFLEX_MOTORS_ON 1 00049 #define RFLEX_MOTORS_REQUEST_OFF 2 00050 #define RFLEX_MOTORS_OFF 3 00051 00052 #define RFLEX_CONFIG_BUFFER_SIZE 256 00053 00054 #define DEFAULT_RFLEX_PORT "/dev/ttyS0" 00055 00056 #define DEFAULT_RFLEX_BUMPER_ADDRESS 0x40 00057 #define RFLEX_BUMPER_STYLE_BIT "bit" 00058 #define RFLEX_BUMPER_STYLE_ADDR "addr" 00059 #define DEFAULT_RFLEX_BUMPER_STYLE RFLEX_BUMPER_STYLE_ADDR 00060 00061 enum 00062 { 00063 BUMPER_BIT, 00064 BUMPER_ADDR 00065 }; 00066 00067 #define DEFAULT_RFLEX_POWER_OFFSET 0 00068 00069 #define MAX_NUM_LOOPS 30 00070 #define B_STX 0x02 00071 #define B_ETX 0x03 00072 #define B_ESC 0x1b 00073 00074 typedef struct player_rflex_data 00075 { 00076 player_position_data_t position; 00077 player_sonar_data_t sonar; 00078 player_sonar_data_t sonar2; 00079 player_gripper_data_t gripper; 00080 player_power_data_t power; 00081 player_bumper_data_t bumper; 00082 player_dio_data_t dio; 00083 player_aio_data_t aio; 00084 player_ir_data ir; 00085 } __attribute__ ((packed)) player_rflex_data_t; 00086 00087 /* 00088 typedef struct 00089 { 00090 player_position_cmd_t position; 00091 player_gripper_cmd_t gripper; 00092 player_sound_cmd_t sound; 00093 } __attribute__ ((packed)) player_rflex_cmd_t; 00094 */ 00095 00096 // this is here because we need the above typedef's before including it. 00097 00098 class RFLEX : public Driver 00099 { 00100 private: 00101 player_device_id_t position_id; 00102 player_device_id_t sonar_id; 00103 player_device_id_t sonar_id_2; 00104 player_device_id_t ir_id; 00105 player_device_id_t bumper_id; 00106 player_device_id_t power_id; 00107 player_device_id_t aio_id; 00108 player_device_id_t dio_id; 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 mm_odo_x; 00120 double mm_odo_y; 00121 double rad_odo_theta; 00122 00123 void ResetRawPositions(); 00124 int initialize_robot(); 00125 void reset_odometry(); 00126 void set_odometry(long,long,short); 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 00134 //override this in subclass, and fill with code to load options from 00135 //config file, default is just an empty dummy 00136 virtual void GetOptions(ConfigFile* cf,int section,rflex_config_t *rflex_configs); 00137 00138 /* the main thread */ 00139 virtual void Main(); 00140 00141 // we override these, because we will maintain our own subscription count 00142 virtual int Subscribe(player_device_id_t id); 00143 virtual int Unsubscribe(player_device_id_t id); 00144 00145 virtual int Setup(); 00146 virtual int Shutdown(); 00147 00148 static int joy_control; 00149 }; 00150 00151 00152 #endif Generated on Tue May 3 14:15:36 2005 for Player by 1.3.6 |