epuckDriver.hpp
Go to the documentation of this file.
1 /* Copyright 2008 Renato Florentino Garcia <fgar.renato@gmail.com>
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2, as
5  * published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef EPUCK_DRIVER2_1_HPP
17 #define EPUCK_DRIVER2_1_HPP
18 
19 #include <libplayercore/playercore.h>
20 #include <string>
21 #include <memory>
22 #include "serialPort.hpp"
23 #include "epuckPosition2d.hpp"
24 #include "epuckIR.hpp"
25 #include "epuckCamera.hpp"
26 #include "epuckLEDs.hpp"
27 
42 {
43 public:
44 
45  EpuckDriver(ConfigFile* cf, int section);
46 
47  ~EpuckDriver();
48 
49  virtual int MainSetup();
50 
51  virtual void MainQuit();
52 
53  virtual int ProcessMessage(QueuePointer &resp_queue,
54  player_msghdr* hdr, void* data);
55 
56  virtual int Subscribe(player_devaddr_t addr);
57 
58  virtual int Unsubscribe(player_devaddr_t addr);
59 
60  static Driver* EpuckDriver_Init(ConfigFile* cf, int section);
61 
62 private:
63 
64  const unsigned EXPECTED_EPUCK_SIDE_VERSION;
65 
66  virtual void Main();
67 
68  player_devaddr_t position2dAddr;
69  player_position2d_data_t posData;
70  std::auto_ptr<EpuckPosition2d> epuckPosition2d;
71 
72  player_devaddr_t irAddr;
73  player_ir_data_t irData;
74  std::auto_ptr<EpuckIR> epuckIR;
75 
76  player_devaddr_t cameraAddr;
77  player_camera_data_t cameraData;
78  std::auto_ptr<EpuckCamera> epuckCamera;
79 
81  player_blinkenlight_data_t ringLEDsData[EpuckLEDs::RING_LEDS_NUM];
82  player_devaddr_t frontLEDAddr;
83  player_blinkenlight_data_t frontLEDData;
84  player_devaddr_t bodyLEDAddr;
85  player_blinkenlight_data_t bodyLEDData;
86  std::auto_ptr<EpuckLEDs> epuckLEDs;
87 
88  SerialPort* serialPort;
89 };
90 
91 #endif
This class controls the turn on and turn off of e-puck LEDs.
Definition: epuckLEDs.hpp:32
#define PLAYER_MSG1(level, msg, a)
Error message macros.
Definition: error.h:106
virtual int Subscribe(player_devaddr_t addr)
Subscribe to this driver.
virtual void Publish(player_devaddr_t addr, QueuePointer &queue, uint8_t type, uint8_t subtype, void *src=NULL, size_t deprecated=0, double *timestamp=NULL, bool copy=true)
Publish a message via one of this driver's interfaces.
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:159
float x
x component.
Definition: epuckInterface.hpp:40
double px
X [m].
Definition: player.h:231
Struct which represents the pose and velocity of e-puck.
Definition: epuckPosition2d.hpp:46
Generic message header.
Definition: player.h:162
virtual int MainSetup()
Sets up the resources needed by the driver thread.
Definition: epuckDriver.cpp:222
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
@ RGB_565_MODE
RGB color mode, with 16 bits per pixel.
Definition: epuckCamera.hpp:83
virtual void Main()
Main method for driver thread.
Definition: epuckDriver.cpp:456
float height
Height of e-puck body.
Definition: epuckPosition2d.hpp:41
EpuckCamera(const SerialPort *const serialPort, unsigned sensor_x1, unsigned sensor_y1, unsigned sensor_width, unsigned sensor_height, unsigned zoom_fact_width, unsigned zoom_fact_height, ColorModes color_mode)
The EpuckCamera class constructor.
Definition: epuckCamera.cpp:43
ColorModes
Possible color modes for e-puck camera.
Definition: epuckCamera.hpp:81
int ReadInt(int section, const char *name, int value)
Read an integer value.
void ProcessMessages(void)
Process pending messages.
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
QueuePointer InQueue
Queue for all incoming messages for this driver.
Definition: driver.h:285
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:112
Plug-in driver for the e-puck robot, in conformity with Player version 2.1.
Definition: epuckDriver.hpp:42
unsigned recvUnsigned() const
Receive an unsigned interger from e-puck.
Definition: serialPort.cpp:115
std::vector< float > voltages
The raw IR readings.
Definition: epuckIR.hpp:41
Struct which represents the geometry of e-puck body.
Definition: epuckPosition2d.hpp:39
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
Triple velocity
E-puck velocity in a 2D surface.
Definition: epuckPosition2d.hpp:48
void sendInt(int message) const
Send an integer to e-puck.
Definition: serialPort.cpp:172
Send and receive messages from e-puck.
Definition: serialPort.hpp:41
const SerialPort *const serialPort
A SerialPort class instance shared among the device interfaces.
Definition: epuckInterface.hpp:59
static const unsigned RING_LEDS_NUM
The quantity of LEDs in e-puck ring LEDs.
Definition: epuckLEDs.hpp:36
Class for to get data from e-puck IR sensors.
Definition: epuckIR.hpp:32
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
std::vector< float > ranges
The equivalent obstacle distance.
Definition: epuckIR.hpp:42
float y
y component.
Definition: epuckInterface.hpp:41
Class for loading configuration file information.
Definition: configfile.h:197
A device address.
Definition: player.h:146
@ GREY_SCALE_MODE
Grey color mode, with 8 bits per pixel.
Definition: epuckCamera.hpp:82
An autopointer for the message queue.
Definition: message.h:74
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
Definition: epuckDriver.cpp:290
int initialize()
Open the serial port device and set the configurations for it.
Definition: serialPort.cpp:39
#define PLAYER_ERROR1(msg, a)
Error message macros.
Definition: error.h:82
bool Empty()
Check whether a queue is empty.
Definition: message.h:345
A pose in space.
Definition: player.h:229
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:81
Base class for drivers which oeprate with a thread.
Definition: driver.h:553
virtual void MainQuit()
Cleanup method for driver thread (called when main exits)
Definition: epuckDriver.cpp:257
float width
Width of e-puck body.
Definition: epuckPosition2d.hpp:40
virtual int Unsubscribe(player_devaddr_t addr)
Unsubscribe from this driver.
Definition: epuckDriver.cpp:274
virtual int Subscribe(player_devaddr_t addr)
Subscribe to this driver.
Definition: epuckDriver.cpp:263
std::string getError() const
Return the last error.
Definition: serialPort.hpp:60
#define PLAYER_WARN(msg)
Warning message macros.
Definition: error.h:89
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:99
@ YUV_MODE
YUV color mode, with 16 bits per pixel.
Definition: epuckCamera.hpp:84
Base class for all drivers.
Definition: driver.h:109
Struct which represents a triple (x,y,theta).
Definition: epuckInterface.hpp:39
It controls the e-puck velocity and odometry.
Definition: epuckPosition2d.hpp:34
float theta
theta component.
Definition: epuckInterface.hpp:42
Represents the data got from e-puck IR sensors.
Definition: epuckIR.hpp:40
Triple pose
E-puck pose in a 2D surface.
Definition: epuckPosition2d.hpp:47
virtual int Unsubscribe(player_devaddr_t addr)
Unsubscribe from this driver.
uint16_t interf
The interface provided by the device; must be one of PLAYER_*_CODE.
Definition: player.h:153
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76