155 "\n * Part of the Player Project [http://playerstage.sourceforge.net]\n" 156 " * Copyright 2000-2009 Richard Vaughan, Brian Gerkey and contributors.\n" 157 " * Released under the GNU General Public License v2.\n";
159 #define STG_DEFAULT_WORLDFILE "default.world" 160 #define DRIVER_ERROR(X) printf( "Stage driver error: %s\n", X ) 188 return ((Driver*) (
new StgDriver(cf, section)));
197 printf(
"\n ** %s plugin v%s **", PROJECT, VERSION );
209 puts(
" Stage driver plugin init");
221 this->last_publish_time = 0;
223 this->driver = driver;
224 this->publish_interval_msec = 100;
231 const std::string& type )
232 :
Interface( addr, driver, cf, section ), mod( NULL ), subscribed( false )
234 char* model_name = (
char*)cf->ReadString(section,
"model", NULL );
236 if( model_name == NULL )
238 PRINT_ERR1(
"device \"%s\" uses the Stage driver but has " 239 "no \"model\" value defined. You must specify a " 240 "model name that matches one of the models in " 256 printf(
" ERROR! no model available for this device." 257 " Check your world and config files.\n" );
264 printf(
"\"%s\"\n", this->
mod->
Token() );
292 : Driver(cf, section, false, 4096 ),
297 int device_count = cf->GetTupleCount( section,
"provides" );
306 for(
int d=0; d<device_count; d++ )
308 player_devaddr_t player_addr;
310 if (cf->ReadDeviceAddr( &player_addr, section,
311 "provides", 0, d, NULL) != 0)
319 printf(
" Stage plugin: %d.%s.%d is ",
321 interf_to_str(player_addr.interf),
329 switch( player_addr.interf )
331 case PLAYER_ACTARRAY_CODE:
339 case PLAYER_BLOBFINDER_CODE:
347 case PLAYER_FIDUCIAL_CODE:
351 case PLAYER_RANGER_CODE:
355 case PLAYER_POSITION2D_CODE:
359 case PLAYER_SIMULATION_CODE:
363 case PLAYER_SPEECH_CODE:
371 case PLAYER_GRAPHICS2D_CODE:
375 case PLAYER_GRAPHICS3D_CODE:
389 case PLAYER_GRIPPER_CODE:
411 PRINT_ERR1(
"error: stage driver doesn't support interface type %d\n",
412 player_addr.interf );
420 if( this->AddInterface( ifsrc->
addr))
433 PRINT_ERR3(
"No Stage source found for interface %d:%d:%d",
446 player_devaddr_t* addr,
447 const std::string& type )
454 if( base_model == NULL )
456 PRINT_ERR1(
" Error! can't find a Stage model named \"%s\"",
477 puts(
"stage driver setup");
490 if( candidate->
addr.robot == addr.robot &&
491 candidate->
addr.interf == addr.interf &&
492 candidate->
addr.index == addr.index )
503 if( addr.interf == PLAYER_SIMULATION_CODE )
512 return Driver::Subscribe(addr);
515 puts(
"failed to find a device" );
523 if( addr.interf == PLAYER_SIMULATION_CODE )
532 return Driver::Unsubscribe(addr);
541 puts(
"Stage driver destroyed" );
552 (*it)->Unsubscribe();
554 puts(
"Stage driver has been shutdown");
577 PRINT_WARN3(
"can't find interface for device %d.%d.%d",
578 this->device_addr.robot,
579 this->device_addr.interf,
580 this->device_addr.index );
587 Driver::ProcessMessages();
595 switch( interface->addr.interf )
597 case PLAYER_SIMULATION_CODE:
602 StgDriver::world->
Update();
613 if((currtime - interface->last_publish_time) >=
614 (interface->publish_interval_msec / 1e3))
616 interface->Publish();
617 interface->last_publish_time = currtime;
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Driver * StgDriver_Init(ConfigFile *cf, int section)
Model * GetUnusedModelOfType(const std::string &type)
const char * copyright_notice
The Stage library uses its own namespace.
const char * basename(const char *filename)
Stg::Model * LocateModel(char *basename, player_devaddr_t *addr, const std::string &type)
#define PRINT_WARN3(m, a, b, c)
double publish_interval_msec
Interface(player_devaddr_t addr, StgDriver *driver, ConfigFile *cf, int section)
virtual int Unsubscribe(QueuePointer &queue, player_devaddr_t addr)
int player_driver_init(DriverTable *table)
void StgDriver_Register(DriverTable *table)
std::vector< Interface * > devices
an array of pointers to Interface objects, defined below
usec_t GetUpdateInterval() const
virtual bool Update(void)
InterfaceModel(player_devaddr_t addr, StgDriver *driver, ConfigFile *cf, int section, const std::string &type)
StgDriver(ConfigFile *cf, int section)
virtual void Unsubscribe(void)
virtual void Subscribe(void)
#define PRINT_ERR3(m, a, b, c)
virtual void Unsubscribe(void)
virtual int Subscribe(QueuePointer &queue, player_devaddr_t addr)
static Stg::World * world
all player devices share the same Stage world (for now)
Model * GetModel(const std::string &name) const
bool player_quiet_startup
virtual void Subscribe(void)
Interface * LookupDevice(player_devaddr_t addr)
find the device record with this Player id
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr_t *hdr, void *data)
const char * Token() const