Revision: 8258 http://playerstage.svn.sourceforge.net/playerstage/?rev=8258&view=rev Author: rtv Date: 2009-09-11 23:13:24 +0000 (Fri, 11 Sep 2009)
Log Message: ----------- added argument string handling to controller init functions Modified Paths: -------------- code/stage/trunk/examples/ctrl/wander.cc code/stage/trunk/libstage/main.cc code/stage/trunk/libstage/model.cc code/stage/trunk/libstage/model_load.cc code/stage/trunk/libstage/stage.hh code/stage/trunk/libstage/world.cc Modified: code/stage/trunk/examples/ctrl/wander.cc =================================================================== --- code/stage/trunk/examples/ctrl/wander.cc 2009-09-11 02:48:28 UTC (rev 8257) +++ code/stage/trunk/examples/ctrl/wander.cc 2009-09-11 23:13:24 UTC (rev 8258) @@ -20,13 +20,14 @@ int PositionUpdate( Model* mod, robot_t* robot ); // Stage calls this when the model starts up -extern "C" int Init( Model* mod, char* argstr ) +extern "C" int Init( Model* mod, CtrlArgs* args ) { // local arguments - printf( "\nWander controller initialised with argument string \"%s\"", argstr ); - // global arguments - for( unsigned int i=0; i< World::args.size(); i++ ) - printf( "\nWorld argument %d is %s", i, World::args[i].c_str() ); + printf( "\nWander controller initialised with:\n" + "\tworldfile string \"%s\"\n" + "\tcmdline string \"%s\"", + args->worldfile.c_str(), + args->cmdline.c_str() ); robot_t* robot = new robot_t; Modified: code/stage/trunk/libstage/main.cc =================================================================== --- code/stage/trunk/libstage/main.cc 2009-09-11 02:48:28 UTC (rev 8257) +++ code/stage/trunk/libstage/main.cc 2009-09-11 23:13:24 UTC (rev 8258) @@ -18,6 +18,8 @@ " --gui : run without a GUI\n" " -g : short for --gui\n" " --help : print this message\n" + " --args \"str\" : define an argument string to be passed to all controllers\n" + " -a \"str\" : short for --args\n" " -h : short for --help\n" " -? : short for --help"; @@ -26,7 +28,7 @@ { "gui", optional_argument, NULL, 'g' }, { "clock", optional_argument, NULL, 'c' }, { "help", optional_argument, NULL, 'h' }, - // { "args", optional_argument, NULL, 'a' }, + { "args", required_argument, NULL, 'a' }, { NULL, 0, NULL, 0 } }; @@ -48,6 +50,9 @@ case 0: // long option given printf( "option %s given\n", longopts[optindex].name ); break; + case 'a': + World::ctrlargs = std::string(optarg); + break; case 'c': showclock = true; printf( "[Clock enabled]" ); @@ -56,9 +61,6 @@ usegui = false; printf( "[GUI disabled]" ); break; -// case 'a': -// printf( "[ignoring unrecognized arguments]" ); -// break; case 'h': case '?': puts( USAGE ); Modified: code/stage/trunk/libstage/model.cc =================================================================== --- code/stage/trunk/libstage/model.cc 2009-09-11 02:48:28 UTC (rev 8257) +++ code/stage/trunk/libstage/model.cc 2009-09-11 23:13:24 UTC (rev 8258) @@ -54,48 +54,80 @@ - pose [ x:<float> y:<float> z:<float> heading:<float> ] \n specify the pose of the model in its parent's coordinate system - - size [ x:<float> y:<float> z:<float> ]\n - specify the size of the model in each dimension + + - size [ x:<float> y:<float> z:<float> ]\n specify the size of the + model in each dimension + - origin [ x:<float> y:<float> z:<float> heading:<float> ]\n specify the position of the object's center, relative to its pose - - velocity [ x:<float> y:<float> z:<float> heading:<float> omega:<float> ]\n - Specify the initial velocity of the model. Note that if the model hits an obstacle, its velocity will be set to zero. + + - velocity [ x:<float> y:<float> z:<float> heading:<float> + omega:<float> ]\n Specify the initial velocity of the model. Note + that if the model hits an obstacle, its velocity will be set to + zero. - - color <string>\n - specify the color of the object using a color name from the X11 database (rgb.txt) - - bitmap filename:<string>\n - Draw the model by interpreting the lines in a bitmap (bmp, jpeg, gif, png supported). The file is opened and parsed into a set of lines. The lines are scaled to fit inside the rectangle defined by the model's current size. - - ctrl <string>\n - specify the controller module for the model + - color <string>\n specify the color of the object using a color + name from the X11 database (rgb.txt) + + - bitmap filename:<string>\n Draw the model by interpreting the + lines in a bitmap (bmp, jpeg, gif, png supported). The file is + opened and parsed into a set of lines. The lines are scaled to + fit inside the rectangle defined by the model's current size. + + - ctrl <string>\n Specify the controller module for the model, and + its argument string. For example, the string "foo bar bash" will + load libfoo.so, which will have its Init() function called with + the entire string as an argument (including the library name). It + is up to the controller to parse the string if it needs + arguments." - - fiducial_return fiducial_id:<int>\n - if non-zero, this model is detected by fiducialfinder sensors. The value is used as the fiducial ID. - - fiducial_key <int> - models are only detected by fiducialfinders if the fiducial_key values of model and fiducialfinder match. This allows you to have several independent types of fiducial in the same environment, each type only showing up in fiducialfinders that are "tuned" for it. - - obstacle_return <int>\n - if 1, this model can collide with other models that have this property set - - ranger_return <int>\n - if 1, this model can be detected by ranger sensors - - blob_return <int>\n - if 1, this model can be detected in the blob_finder (depending on its color) - - laser_return <int>\n - if 0, this model is not detected by laser sensors. if 1, the model shows up in a laser sensor with normal (0) reflectance. If 2, it shows up with high (1) reflectance. - - gripper_return <int>\n - iff 1, this model can be gripped by a gripper and can be pushed around by collisions with anything that has a non-zero obstacle_return. + - fiducial_return fiducial_id:<int>\n if non-zero, this model is + detected by fiducialfinder sensors. The value is used as the + fiducial ID. + + - fiducial_key <int> models are only detected by fiducialfinders + if the fiducial_key values of model and fiducialfinder match. This + allows you to have several independent types of fiducial in the + same environment, each type only showing up in fiducialfinders + that are "tuned" for it. + + - obstacle_return <int>\n if 1, this model can collide with other + models that have this property set + + - ranger_return <int>\n if 1, this model can be detected by ranger + sensors + + - blob_return <int>\n if 1, this model can be detected in the + blob_finder (depending on its color) + + - laser_return <int>\n if 0, this model is not detected by laser + sensors. if 1, the model shows up in a laser sensor with normal + (0) reflectance. If 2, it shows up with high (1) reflectance. + + - gripper_return <int>\n iff 1, this model can be gripped by a + gripper and can be pushed around by collisions with anything that + has a non-zero obstacle_return. - - gui_nose <int>\n - if 1, draw a nose on the model showing its heading (positive X axis) - - gui_grid <int>\n - if 1, draw a scaling grid over the model - - gui_outline <int>\n - if 1, draw a bounding box around the model, indicating its size - - gui_move <int>\n - if 1, the model can be moved by the mouse in the GUI window + - gui_nose <int>\n if 1, draw a nose on the model showing its + heading (positive X axis) - - friction <float>\n - Determines the proportion of velocity lost per second. For example, 0.1 would mean that the object would lose 10% of its speed due to friction per second. A value of zero (the default) means this model can not be pushed around (infinite friction). + - gui_grid <int>\n if 1, draw a scaling grid over the model + + - gui_outline <int>\n if 1, draw a bounding box around the model, + indicating its size + + - gui_move <int>\n if 1, the model can be moved by the mouse in + the GUI window */ +// todo +// - friction <float>\n Determines the proportion of velocity lost +// per second. For example, 0.1 would mean that the object would lose +// 10% of its speed due to friction per second. A value of zero (the +// default) means this model can not be pushed around (infinite +// friction). + + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif Modified: code/stage/trunk/libstage/model_load.cc =================================================================== --- code/stage/trunk/libstage/model_load.cc 2009-09-11 02:48:28 UTC (rev 8257) +++ code/stage/trunk/libstage/model_load.cc 2009-09-11 23:13:24 UTC (rev 8258) @@ -203,15 +203,19 @@ { this->SetFriction( wf->ReadFloat(wf_entity, "friction", this->friction )); } - - if( wf->PropertyExists( wf_entity, "ctrl" )) - { - char* lib = (char*)wf->ReadString(wf_entity, "ctrl", NULL ); - - if( !lib ) - printf( "Error - NULL library name specified for model %s\n", token ); - else - LoadControllerModule( lib ); + + if( CProperty* ctrlp = wf->GetProperty( wf_entity, "ctrl" ) ) + { + for( int index=0; index < ctrlp->values.size(); index++ ) + { + + const char* lib = wf->GetPropertyValue( ctrlp, index ); + + if( !lib ) + printf( "Error - NULL library name specified for model %s\n", token ); + else + LoadControllerModule( lib ); + } } @@ -283,7 +287,7 @@ } -void Model::LoadControllerModule( char* lib ) +void Model::LoadControllerModule( const char* lib ) { //printf( "[Ctrl \"%s\"", lib ); //fflush(stdout); @@ -321,7 +325,8 @@ exit(-1); } //else - AddCallback( &hooks.init, initfunc, lib ); // pass complete string into initfunc + + AddCallback( &hooks.init, initfunc, new CtrlArgs(lib,World::ctrlargs) ); // pass complete string into initfunc } else { Modified: code/stage/trunk/libstage/stage.hh =================================================================== --- code/stage/trunk/libstage/stage.hh 2009-09-11 02:48:28 UTC (rev 8257) +++ code/stage/trunk/libstage/stage.hh 2009-09-11 23:13:24 UTC (rev 8258) @@ -750,6 +750,15 @@ static void Print(); }; + class CtrlArgs + { + public: + std::string worldfile; + std::string cmdline; + + CtrlArgs( std::string w, std::string c ) : worldfile(w), cmdline(c) {} + }; + /// %World class class World : public Ancestor { @@ -762,6 +771,7 @@ /** contains the command line arguments passed to Stg::Init(), so that controllers can read them. */ static std::vector<std::string> args; + static std::string ctrlargs; private: @@ -2062,7 +2072,7 @@ /** Load a control program for this model from an external library */ - void LoadControllerModule( char* lib ); + void LoadControllerModule( const char* lib ); /** Sets the redraw flag, so this model will be redrawn at the earliest opportunity */ Modified: code/stage/trunk/libstage/world.cc =================================================================== --- code/stage/trunk/libstage/world.cc 2009-09-11 02:48:28 UTC (rev 8257) +++ code/stage/trunk/libstage/world.cc 2009-09-11 23:13:24 UTC (rev 8258) @@ -95,6 +95,7 @@ unsigned int World::next_id = 0; bool World::quit_all = false; std::set<World*> World::world_set; +std::string World::ctrlargs; World::World( const char* token, double ppm ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit