52 #include <libplayercore/globals.h> 61 #define DRIVER_ERROR(X) printf( "Stage driver error: %s\n", X ) 63 #ifndef PLAYER_CAPABILITIES_REQ 64 #ifdef PLAYER_CAPABILTIES_REQ 65 #define PLAYER_CAPABILITIES_REQ PLAYER_CAPABILTIES_REQ 80 printf(
"a Stage world" ); fflush(stdout);
87 const char* worldfile_name = cf->ReadString(section,
"worldfile", NULL );
89 if( worldfile_name == NULL )
91 PRINT_ERR1(
"device \"%s\" uses the Stage driver but has " 92 "no \"model\" value defined. You must specify a " 93 "model name that matches one of the models in " 99 char fullname[MAXPATHLEN];
101 if( worldfile_name[0] ==
'/' )
102 strcpy( fullname, worldfile_name );
105 char *tmp = strdup(cf->filename);
106 snprintf( fullname, MAXPATHLEN,
107 "%s/%s",
dirname(tmp), worldfile_name );
151 driver->alwayson = TRUE;
157 player_msghdr_t* hdr,
160 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ, PLAYER_CAPABILITIES_REQ,
addr))
162 PLAYER_ERROR1(
"%p\n", data);
163 player_capabilities_req_t & cap_req = *
reinterpret_cast<player_capabilities_req_t *
> (data);
164 if (cap_req.type == PLAYER_MSGTYPE_REQ && (cap_req.subtype == PLAYER_SIMULATION_REQ_SET_POSE3D || cap_req.subtype == PLAYER_SIMULATION_REQ_GET_POSE3D))
166 this->
driver->Publish(
addr, resp_queue, PLAYER_MSGTYPE_RESP_ACK, PLAYER_CAPABILITIES_REQ);
172 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
173 PLAYER_SIMULATION_REQ_GET_POSE2D,
176 player_simulation_pose2d_req_t* req =
177 (player_simulation_pose2d_req_t*)data;
179 PRINT_DEBUG1(
"Stage: received request for the 2D position of object \"%s\"\n", req->name );
188 PRINT_DEBUG3(
"Stage: returning location [ %.2f, %.2f, %.2f ]\n",
189 pose.
x, pose.
y, pose.
a );
191 player_simulation_pose2d_req_t reply;
192 memcpy( &reply, req,
sizeof(reply));
193 reply.pose.px = pose.
x;
194 reply.pose.py = pose.
y;
195 reply.pose.pa = pose.
a;
197 this->
driver->Publish( this->
addr, resp_queue,
198 PLAYER_MSGTYPE_RESP_ACK,
199 PLAYER_SIMULATION_REQ_GET_POSE2D,
200 (
void*)&reply,
sizeof(reply), NULL );
205 PRINT_WARN1(
"Stage: GET_POSE2D request: simulation model \"%s\" not found", req->name );
211 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
212 PLAYER_SIMULATION_REQ_SET_POSE2D,
215 player_simulation_pose2d_req_t* req =
216 (player_simulation_pose2d_req_t*)data;
223 PRINT_DEBUG4(
"Stage: moving \"%s\" to [ %.2f, %.2f, %.2f ]\n",
224 req->name, req->pose.px, req->pose.py, req->pose.pa );
227 pose.
x = req->pose.px;
228 pose.
y = req->pose.py;
229 pose.
a = req->pose.pa;
234 PLAYER_MSGTYPE_RESP_ACK,
235 PLAYER_SIMULATION_REQ_SET_POSE2D);
240 PRINT_WARN1(
"SETPOSE2D request: simulation model \"%s\" not found", req->name );
246 else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
247 PLAYER_SIMULATION_REQ_GET_POSE3D,
250 player_simulation_pose3d_req_t* req =
251 (player_simulation_pose3d_req_t*)data;
253 PRINT_DEBUG1(
"Stage: received request for the 3D position of object \"%s\"\n", req->name );
262 PRINT_DEBUG4(
"Stage: returning location [ %.2f, %.2f, %.2f, %.2f ]\n",
263 pose.
x, pose.
y, pose.
z, pose.
a );
265 player_simulation_pose3d_req_t reply;
266 memcpy( &reply, req,
sizeof(reply));
267 reply.pose.px = pose.
x;
268 reply.pose.py = pose.
y;
269 reply.pose.pz = pose.
z;
270 reply.pose.proll = 0;
271 reply.pose.ppitch = 0;
272 reply.pose.pyaw = pose.
a;
275 this->
driver->Publish( this->
addr, resp_queue,
276 PLAYER_MSGTYPE_RESP_ACK,
277 PLAYER_SIMULATION_REQ_GET_POSE3D,
278 (
void*)&reply,
sizeof(reply), NULL );
283 PRINT_WARN1(
"Stage: GET_POSE3D request: simulation model \"%s\" not found", req->name );
289 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
290 PLAYER_SIMULATION_REQ_SET_POSE3D,
293 player_simulation_pose3d_req_t* req =
294 (player_simulation_pose3d_req_t*)data;
301 PRINT_DEBUG5(
"Stage: moving \"%s\" to [ %.2f, %.2f, %.2f %.2f ]\n",
302 req->name, req->pose.px, req->pose.py, req->pose.pz, req->pose.pyaw );
305 pose.
x = req->pose.px;
306 pose.
y = req->pose.py;
307 pose.
z = req->pose.pz;
308 pose.
a = req->pose.pyaw;
314 PLAYER_MSGTYPE_RESP_ACK,
315 PLAYER_SIMULATION_REQ_SET_POSE3D);
320 PRINT_WARN1(
"SETPOSE2D request: simulation model \"%s\" not found", req->name );
327 else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
328 PLAYER_SIMULATION_REQ_SET_PROPERTY,
331 player_simulation_property_req_t* req =
332 (player_simulation_property_req_t*)data;
338 if( strncmp(req->prop,
"color", (
size_t)req->prop_count) )
340 PRINT_WARN1(
"Property \"%s\" can not be set. Options are \"color\"", req->prop);
345 if(req->value_count !=
sizeof(
float)*4)
347 PRINT_WARN(
"Value given by SetProperty must be an array of 4 floats\n");
359 float *col = (
float *)req->value;
360 Color newColour =
Color(col[0], col[1], col[2], col[3]);
365 ack==0 ? PLAYER_MSGTYPE_RESP_ACK : PLAYER_MSGTYPE_RESP_NACK,
366 PLAYER_SIMULATION_REQ_SET_PROPERTY);
371 PRINT_WARN1(
"SET_PROPERTY request: simulation model \"%s\" not found", req->name );
377 else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
378 PLAYER_SIMULATION_REQ_GET_PROPERTY,
381 player_simulation_property_req_t* req =
382 (player_simulation_property_req_t*)data;
389 if( !(strncmp(req->prop,
"color", (
size_t)req->prop_count) ))
392 if(req->value_count !=
sizeof(
float)*4)
394 PRINT_WARN(
"Colour requires an array of 4 floats to store\n");
406 col[0] = newColour.
r;
407 col[1] = newColour.
g;
408 col[2] = newColour.
b;
409 col[3] = newColour.
a;
412 memcpy(req->value, col, req->value_count);
416 player_simulation_property_req_t reply;
417 memcpy( &reply, req,
sizeof(reply));
420 memcpy(reply.value, col, reply.value_count);
423 this->
driver->Publish( this->
addr, resp_queue,
424 PLAYER_MSGTYPE_RESP_ACK,
425 PLAYER_SIMULATION_REQ_GET_PROPERTY,
426 (
void*)&reply,
sizeof(reply), NULL );
432 PRINT_WARN1(
"GET_PROPERTY request: simulation model \"%s\" not found", req->name );
436 else if( strncmp(req->prop,
"time", (
size_t)req->prop_count ) == 0 )
439 if(req->value_count !=
sizeof(uint64_t))
441 PRINT_WARN(
"Simulation time requires a uint64_t to store\n");
452 player_simulation_property_req_t reply;
453 memcpy( &reply, req,
sizeof(reply));
458 this->
driver->Publish( this->
addr, resp_queue,
459 PLAYER_MSGTYPE_RESP_ACK,
460 PLAYER_SIMULATION_REQ_GET_PROPERTY,
461 (
void*)&reply,
sizeof(reply), NULL );
467 PRINT_WARN1(
"GET_PROPERTY request: simulation model \"%s\" not found", req->name );
474 PRINT_WARN1(
"Property \"%s\" is not accessible. Options are \"color\", \"_mp_color\", or \"colour\" for changing colour. \"simtime\" or \"sim_time\" for getting the simulation time.", req->prop);
483 PRINT_WARN2(
"simulation doesn't support msg with type/subtype %d/%d",
484 hdr->type, hdr->subtype);
InterfaceSimulation(player_devaddr_t addr, StgDriver *driver, ConfigFile *cf, int section)
usec_t SimTimeNow(void) const
The Stage library uses its own namespace.
void SetPose(const Pose &pose)
#define PRINT_DEBUG5(m, a, b, c, d, e)
void Init(int *argc, char **argv[])
#define PRINT_WARN2(m, a, b)
meters_t z
location in 3 axes
#define PRINT_DEBUG3(m, a, b, c)
char * dirname(char *path)
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr_t *hdr, void *data)
bool player_quiet_startup
#define PRINT_DEBUG1(m, a)
static Stg::World * world
all player devices share the same Stage world (for now)
Model * GetModel(const std::string &name) const
#define PRINT_DEBUG4(m, a, b, c, d)
radians_t a
rotation about the z axis.
#define PRINT_WARN1(m, a)
virtual void Load(const std::string &worldfile_path)