rflex.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2000
4  * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 /*
24  * this file was adapted from the P2OS device for the RWI RFLEX robots
25  *
26  * the RFLEX device. it's the parent device for all the RFLEX 'sub-devices',
27  * like, position, sonar, etc. there's a thread here that
28  * actually interacts with RFLEX via the serial line. the other
29  * "devices" communicate with this thread by putting into and getting
30  * data out of shared buffers.
31  */
32 #ifndef _RFLEXDEVICE_H
33 #define _RFLEXDEVICE_H
34 
35 #include <pthread.h>
36 #include <sys/time.h>
37 
38 #include <libplayercore/playercore.h>
39 
40 #include "rflex_commands.h"
41 #include "rflex-io.h"
42 
43 #include "rflex_configs.h"
44 
45 #define RFLEX_MOTORS_REQUEST_ON 0
46 #define RFLEX_MOTORS_ON 1
47 #define RFLEX_MOTORS_REQUEST_OFF 2
48 #define RFLEX_MOTORS_OFF 3
49 
50 #define RFLEX_CONFIG_BUFFER_SIZE 256
51 
52 #define DEFAULT_RFLEX_PORT "/dev/ttyS0"
53 
54 #define DEFAULT_RFLEX_BUMPER_ADDRESS 0x40
55 #define RFLEX_BUMPER_STYLE_BIT "bit"
56 #define RFLEX_BUMPER_STYLE_ADDR "addr"
57 #define DEFAULT_RFLEX_BUMPER_STYLE RFLEX_BUMPER_STYLE_ADDR
58 
59 enum
60 {
61  BUMPER_BIT,
62  BUMPER_ADDR
63 };
64 
65 #define DEFAULT_RFLEX_POWER_OFFSET 0
66 
67 #define MAX_NUM_LOOPS 30
68 #define B_STX 0x02
69 #define B_ETX 0x03
70 #define B_ESC 0x1b
71 
72 typedef struct player_rflex_data
73 {
74  player_position2d_data_t position;
75  player_sonar_data_t sonar;
76  player_sonar_data_t sonar2;
77  player_gripper_data_t gripper;
78  player_power_data_t power;
79  player_bumper_data_t bumper;
82  player_ir_data ir;
83 } __attribute__ ((packed)) player_rflex_data_t;
84 
85 /*
86 typedef struct
87 {
88  player_position_cmd_t position;
89  player_gripper_cmd_t gripper;
90  player_sound_cmd_t sound;
91 } __attribute__ ((packed)) player_rflex_cmd_t;
92 */
93 
94 // this is here because we need the above typedef's before including it.
95 
96 class RFLEX : public ThreadedDriver
97 {
98  private:
99  player_devaddr_t position_id;
100  player_devaddr_t sonar_id;
101  player_devaddr_t sonar_id_2;
102  player_devaddr_t ir_id;
103  player_devaddr_t bumper_id;
104  player_devaddr_t power_id;
105  player_devaddr_t aio_id;
106  player_devaddr_t dio_id;
108  int command_type;
109 
110  int position_subscriptions;
111  int sonar_subscriptions;
112  int ir_subscriptions;
113  int bumper_subscriptions;
114 
115  int rflex_fd; // rflex device file descriptor
116 
117  // device used to communicate with rflex
118  char rflex_serial_port[MAX_FILENAME_SIZE];
119  double m_odo_x;
120  double m_odo_y;
121  double rad_odo_theta;
122 
123  void ResetRawPositions();
124  int initialize_robot();
125  void reset_odometry();
126  void set_odometry(float,float,float);
127  void update_everything(player_rflex_data_t* d);
128 
129  void set_config_defaults();
130 
131  public:
132  RFLEX(ConfigFile* cf, int section);
133  ~RFLEX();
134 
135  /* the main thread */
136  virtual void Main();
137 
138  // we override these, because we will maintain our own subscription count
139  virtual int Subscribe(player_devaddr_t addr);
140  virtual int Unsubscribe(player_devaddr_t addr);
141 
142  virtual void MainQuit();
143 
144  static int joy_control;
145 
146  // MessageHandler
147  int ProcessMessage(QueuePointer & resp_queue, player_msghdr * hdr,
148  void * data);
149 };
150 
151 
152 #endif
Class for loading configuration file information.
Definition: configfile.h:196
position 2d velocity command
Definition: player_interfaces.h:617
Generic message header.
Definition: player.h:161
A device address.
Definition: player.h:145
Base class for drivers which oeprate with a thread.
Definition: driver.h:552
Messages between wsn and a robot.
Definition: er.h:86
Data: voltage (PLAYER_POWER_DATA_STATE)
Definition: player_interfaces.h:291
An autopointer for the message queue.
Definition: message.h:73
Data: state (PLAYER_BUMPER_DATA_GEOM)
Definition: player_interfaces.h:1922
Data: ranges (PLAYER_IR_DATA_RANGES)
Definition: player_interfaces.h:2115
Data: state (PLAYER_GRIPPER_DATA_STATE)
Definition: player_interfaces.h:418
Definition: rflex.h:72
position2d data
Definition: player_interfaces.h:606
Data: input values (PLAYER_DIO_DATA_VALUES)
Definition: player_interfaces.h:1994
Data: state (PLAYER_AIO_DATA_STATE)
Definition: player_interfaces.h:2053
Definition: rflex.h:96
Data: ranges (PLAYER_SONAR_DATA_RANGES)
Definition: player_interfaces.h:771