maptransform.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2004 Brian Gerkey gerkey@stanford.edu
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  */
20 
21 /*
22  * $Id$
23  *
24  * Base class for map transform drivers, simply reimplement the transform method
25  * with your trasformation function. See MapScale for example
26  */
27 
28 #ifndef _MAPTRANSFORM_H_
29 #define _MAPTRANSFORM_H_
30 
31 #include <sys/types.h> // required by Darwin
32 #include <stdlib.h>
33 #include <string.h>
34 #include <math.h>
35 
36 #include <libplayercore/playercore.h>
37 
38 // compute linear index for given map coords
39 #define MAP_IDX(mf, i, j) ((mf.width) * (j) + (i))
40 
41 // check that given coords are valid (i.e., on the map)
42 #define MAP_VALID(mf, i, j) ((i >= 0) && (i < mf.width) && (j >= 0) && (j < mf.height))
43 
44 class MapTransform : public Driver
45 {
46  protected:
47  player_map_info_t source_map;
48  player_devaddr_t source_map_addr;
49  char* source_data;
50 
51  player_map_info_t new_map;
52  char* new_data;
53 
54  // get the map from the underlying map device
55  int GetMap();
56  // interpolate the map
57  virtual int Transform() = 0;
58 
59  public:
60  MapTransform(ConfigFile* cf, int section);
61  virtual ~MapTransform();
62 
63  // MessageHandler
64  public: virtual int ProcessMessage(QueuePointer &resp_queue,
65  player_msghdr * hdr,
66  void * data);
67 
68  int Setup();
69  int Shutdown();
70 };
71 
72 #endif
#define PLAYER_MSG1(level, msg, a)
Error message macros.
Definition: error.h:106
#define PLAYER_MSG3(level, msg, a, b, c)
Error message macros.
Definition: error.h:108
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
A pose in the plane.
Definition: player.h:218
double ReadTupleLength(int section, const char *name, int index, double value)
Read a length from a tuple (includes units conversion)
Generic message header.
Definition: player.h:162
int Subscribe(QueuePointer &sub_queue)
Subscribe the given queue to this device.
int Setup()
Initialize the driver.
Definition: maptransform.cc:54
Encapsulates a device (i.e., a driver bound to an interface)
Definition: device.h:75
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
double px
X [m].
Definition: player.h:220
const char * ReadFilename(int section, const char *name, const char *value)
Read a filename.
#define PLAYER_MSG4(level, msg, a, b, c, d)
Error message macros.
Definition: error.h:109
int ReadInt(int section, const char *name, int value)
Read an integer value.
double ReadLength(int section, const char *name, double value)
Read a length (includes unit conversion, if any).
void * GetPayload()
Get pointer to payload.
Definition: message.h:188
double py
Y [m].
Definition: player.h:222
int Shutdown()
Finalize the driver.
Definition: maptransform.cc:188
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:112
#define PLAYER_WARN2(msg, a, b)
Error message macros.
Definition: error.h:91
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
Class for loading configuration file information.
Definition: configfile.h:197
virtual int Setup()
Initialize the driver.
Definition: driver.h:386
#define PLAYER_CAPABILITIES_REQ
Capability request message type.
Definition: player.h:397
A device address.
Definition: player.h:146
An autopointer for the message queue.
Definition: message.h:74
#define PLAYER_ERROR1(msg, a)
Error message macros.
Definition: error.h:82
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:81
player_devaddr_t device_addr
Default device address (single-interface drivers)
Definition: driver.h:269
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
Definition: maptransform.cc:197
Reference-counted message objects.
Definition: message.h:133
Message * Request(QueuePointer &resp_queue, uint8_t type, uint8_t subtype, void *src, size_t deprecated, double *timestamp, bool threaded=true)
Make a request of another device.
#define PLAYER_WARN(msg)
Warning message macros.
Definition: error.h:89
virtual int Shutdown()
Finalize the driver.
Definition: driver.h:393
double pa
yaw [rad]
Definition: player.h:224
Base class for all drivers.
Definition: driver.h:109
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:105
int Unsubscribe(QueuePointer &sub_queue)
Unsubscribe the given queue from this device.
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76
Definition: maptransform.h:45