p_position.cc
Go to the documentation of this file.
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2004, 2005 Richard Vaughan
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 /*
23  * Desc: A plugin driver for Player that gives access to Stage devices.
24  * Author: Richard Vaughan
25  * Date: 10 December 2004
26  * CVS: $Id$
27  */
28 // DOCUMENTATION ------------------------------------------------------------
29 
43 // CODE ----------------------------------------------------------------------
44 
45 #include "p_driver.h"
46 using namespace Stg;
47 
48 InterfacePosition::InterfacePosition( player_devaddr_t addr,
49  StgDriver* driver,
50  ConfigFile* cf,
51  int section )
52 
53  : InterfaceModel( addr, driver, cf, section, "position" )
54 {
55  //puts( "InterfacePosition constructor" );
56 }
57 
58 int InterfacePosition::ProcessMessage(QueuePointer &resp_queue,
59  player_msghdr_t* hdr,
60  void* data)
61 {
62  ModelPosition* mod = (ModelPosition*)this->mod;
63 
64  // Is it a new motor command?
65  if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD,
66  PLAYER_POSITION2D_CMD_VEL,
67  this->addr))
68  {
69  // convert from Player to Stage format
70  player_position2d_cmd_vel_t* pcmd = (player_position2d_cmd_vel_t*)data;
71 
72  //position_cmd_t scmd;
73  //memset( &scmd, 0, sizeof(scmd));
74 
75  mod->SetSpeed( pcmd->vel.px, pcmd->vel.py, pcmd->vel.pa );
76 
77  return 0;
78  }
79 
80  // Is it a new motor command?
81  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD,
82  PLAYER_POSITION2D_CMD_POS,
83  this->addr))
84  {
85  // convert from Player to Stage format
86  player_position2d_cmd_pos_t* pcmd = (player_position2d_cmd_pos_t*)data;
87 
88  mod->GoTo( pcmd->pos.px, pcmd->pos.py, pcmd->pos.pa );
89  return 0;
90  }
91 
92  // Is it a new motor command?
93  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD,
94  PLAYER_POSITION2D_CMD_CAR,
95  this->addr))
96  {
97  // convert from Player to Stage format
98  player_position2d_cmd_car_t* pcmd = (player_position2d_cmd_car_t*)data;
99 
100  mod->SetSpeed( pcmd->velocity, 0, pcmd->angle );
101  return 0;
102  }
103 
104  // Is it a request for position geometry?
105  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
106  PLAYER_POSITION2D_REQ_GET_GEOM,
107  this->addr))
108  {
109  if(hdr->size == 0)
110  {
111  Geom geom = this->mod->GetGeom();
112 
113  // fill in the geometry data formatted player-like
114  player_position2d_geom_t pgeom;
115  pgeom.pose.px = geom.pose.x;
116  pgeom.pose.py = geom.pose.y;
117  pgeom.pose.pyaw = geom.pose.a;
118 
119  pgeom.size.sl = geom.size.x;
120  pgeom.size.sw = geom.size.y;
121 
122  this->driver->Publish( this->addr, resp_queue,
123  PLAYER_MSGTYPE_RESP_ACK,
124  PLAYER_POSITION2D_REQ_GET_GEOM,
125  (void*)&pgeom, sizeof(pgeom), NULL );
126  return 0;
127  }
128  else
129  {
130  PRINT_ERR2("config request len is invalid (%d != %d)",
131  (int)hdr->size, 0);
132  return(-1);
133  }
134  }
135  // Is it a request to reset odometry?
136  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
137  PLAYER_POSITION2D_REQ_RESET_ODOM,
138  this->addr))
139  {
140  if(hdr->size == 0)
141  {
142  PRINT_DEBUG( "resetting odometry" );
143 
144  mod->est_pose.x = 0;
145  mod->est_pose.y = 0;
146  mod->est_pose.z = 0;
147  mod->est_pose.a = 0;
148 
149  this->driver->Publish( this->addr, resp_queue,
150  PLAYER_MSGTYPE_RESP_ACK,
151  PLAYER_POSITION2D_REQ_RESET_ODOM );
152  return 0;
153  }
154  else
155  {
156  PRINT_ERR2("config request len is invalid (%d != %d)",
157  (int)hdr->size, 0);
158  return -1;
159  }
160  }
161  // Is it a request to set odometry?
162  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
163  PLAYER_POSITION2D_REQ_SET_ODOM,
164  this->addr))
165  {
166  if(hdr->size == sizeof(player_position2d_set_odom_req_t))
167  {
168  player_position2d_set_odom_req_t* req =
169  (player_position2d_set_odom_req_t*)data;
170 
171 
172  mod->est_pose.x = req->pose.px;
173  mod->est_pose.y = req->pose.py;
174  //mod->est_pose.z = req->pose.pz;
175  mod->est_pose.a = req->pose.pa;
176 
177  PRINT_DEBUG3( "set odometry to (%.2f,%.2f,%.2f)",
178  pose.x,
179  pose.y,
180  pose.a );
181 
182  this->driver->Publish( this->addr, resp_queue,
183  PLAYER_MSGTYPE_RESP_ACK,
184  PLAYER_POSITION2D_REQ_SET_ODOM );
185  return(0);
186  }
187  else
188  {
189  PRINT_ERR2("config request len is invalid (%d != %d)",
190  (int)hdr->size, (int)sizeof(player_position2d_set_odom_req_t));
191  return(-1);
192  }
193  }
194  // Is it a request to enable motor power?
195  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
196  PLAYER_POSITION2D_REQ_MOTOR_POWER,
197  this->addr))
198  {
199  if(hdr->size == sizeof(player_position2d_power_config_t))
200  {
201  player_position2d_power_config_t* req =
202  (player_position2d_power_config_t*)data;
203 
204  int motors_on = req->state;
205 
206  PRINT_WARN1( "Stage ignores motor power state (%d)",
207  motors_on );
208  this->driver->Publish( this->addr, resp_queue,
209  PLAYER_MSGTYPE_RESP_ACK,
210  PLAYER_POSITION2D_REQ_MOTOR_POWER );
211  return(0);
212  }
213  else
214  {
215  PRINT_ERR2("config request len is invalid (%d != %d)",
216  (int)hdr->size, (int)sizeof(player_position2d_power_config_t));
217  return(-1);
218  }
219  }
220  // Is it a request to switch control mode?
221  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
222  PLAYER_POSITION2D_REQ_POSITION_MODE,
223  this->addr))
224  {
225  if(hdr->size == sizeof(player_position2d_position_mode_req_t))
226  {
227 
228  //player_position2d_position_mode_req_t* req =
229  // (player_position2d_position_mode_req_t*)data;
230 
231  //position_control_mode_t mode = (position_control_mode_t)req->state;
232 
233 
234  PRINT_WARN2( "Put model %s into %s control mode", this->mod->Token(), mod ? "POSITION" : "VELOCITY" );
235  PRINT_WARN( "set control mode not yet implemented") ;
236 
237  this->driver->Publish( this->addr, resp_queue,
238  PLAYER_MSGTYPE_RESP_ACK,
239  PLAYER_POSITION2D_REQ_POSITION_MODE );
240  return(0);
241  }
242  else
243  {
244  PRINT_ERR2("config request len is invalid (%d != %d)",
245  (int)hdr->size,
246  (int)sizeof(player_position2d_position_mode_req_t));
247  return(-1);
248  }
249  }
250 
251  //else
252 
253  // Don't know how to handle this message.
254  PRINT_WARN2( "position doesn't support msg with type %d subtype %d",
255  hdr->type, hdr->subtype);
256  return(-1);
257 }
258 
260 {
261  //puts( "publishing position data" );
262 
263  ModelPosition* mod = (ModelPosition*)this->mod;
264 
265  //printf( "stage position data: %.2f,%.2f,%.2f\n",
266  // data->pose.x, data->pose.y, data->pose.a );
267 
268  player_position2d_data_t ppd;
269  bzero( &ppd, sizeof(ppd) );
270 
271  // pack the data into player format
272  // packing by hand allows for type conversions
273  ppd.pos.px = mod->est_pose.x;
274  ppd.pos.py = mod->est_pose.y;
275  //ppd.pos.pz = mod->est_pose.z;
276  ppd.pos.pa = mod->est_pose.a;
277 
278  Velocity v = mod->GetVelocity();
279 
280  ppd.vel.px = v.x;
281  ppd.vel.py = v.y;
282  ppd.vel.pa = v.a;
283 
284  // etc
285  ppd.stall = this->mod->Stalled();
286 
287  // publish this data
288  this->driver->Publish( this->addr,
289  PLAYER_MSGTYPE_DATA, PLAYER_POSITION2D_DATA_STATE,
290  (void*)&ppd, sizeof(ppd), NULL);
291 }
void GoTo(double x, double y, double a)
The Stage library uses its own namespace.
Definition: canvas.hh:8
meters_t x
Definition: stage.hh:228
void SetSpeed(double x, double y, double a)
#define PRINT_WARN2(m, a, b)
Definition: stage.hh:635
Size size
extent
Definition: stage.hh:395
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr_t *hdr, void *data)
Definition: p_position.cc:58
StgDriver * driver
Definition: p_driver.h:72
meters_t z
location in 3 axes
Definition: stage.hh:251
meters_t y
Definition: stage.hh:251
player_devaddr_t addr
Definition: p_driver.h:66
ModelPosition class
Definition: stage.hh:2927
#define PRINT_DEBUG3(m, a, b, c)
Definition: stage.hh:669
Pose est_pose
position estimate in local coordinates
Definition: stage.hh:3044
Pose pose
position
Definition: stage.hh:394
bool Stalled() const
Definition: stage.hh:2457
meters_t y
Definition: stage.hh:228
virtual void Publish(void)
Definition: p_position.cc:259
#define PRINT_WARN(m)
Definition: stage.hh:633
Stg::Model * mod
Definition: p_driver.h:115
Velocity GetVelocity() const
Definition: stage.hh:2984
InterfacePosition(player_devaddr_t addr, StgDriver *driver, ConfigFile *cf, int section)
Definition: p_position.cc:48
#define PRINT_ERR2(m, a, b)
Definition: stage.hh:627
radians_t a
rotation about the z axis.
Definition: stage.hh:252
#define PRINT_DEBUG(m)
Definition: stage.hh:666
#define PRINT_WARN1(m, a)
Definition: stage.hh:634
meters_t x
Definition: stage.hh:251
const char * Token() const
Definition: stage.hh:715
Geom GetGeom() const
Definition: stage.hh:2378


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:09