00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 class REB : public Driver
00104 {
00105 public:
00106
00107 REB(ConfigFile *cf, int section);
00108
00109
00110 virtual void Main();
00111
00112
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
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
00135
00136 void ConfigAD(int, int);
00137 unsigned short ReadAD(int);
00138 void ReadAllIR(uint16_t * ir);
00139
00140
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;
00168 int reb_fd;
00169
00170 struct timeval last_position;
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;
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
00193 char reb_serial_port[MAX_FILENAME_SIZE];
00194
00195 struct pollfd write_pfd, read_pfd;
00196 };
00197
00198
00199 #endif