From: Richard V. <rt...@us...> - 2008-02-19 22:03:58
|
Update of /cvsroot/playerstage/code/stage/libstage In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12236 Modified Files: Makefile Makefile.am Makefile.manual canvas.cc model.cc model_load.cc stage.hh world.cc worldgui.cc Added Files: ctrl.cc main.cc Log Message: added loadable modules for robot control, and reintroduced the program Stage Index: worldgui.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/worldgui.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** worldgui.cc 18 Feb 2008 03:52:30 -0000 1.5 --- worldgui.cc 20 Feb 2008 06:03:59 -0000 1.6 *************** *** 343,347 **** --- 343,349 ---- void StgWorldGui::DrawFloor() { + PushColor( 1,1,1,1 ); g_hash_table_foreach( superregions, (GHFunc)SuperRegion::Floor_cb, NULL ); + PopColor(); } Index: model.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/model.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** model.cc 18 Feb 2008 03:52:30 -0000 1.4 --- model.cc 20 Feb 2008 06:03:58 -0000 1.5 *************** *** 216,219 **** --- 216,222 ---- this->interval = 1e4; // 10msec + this->initfunc = NULL; + this->updatefunc = NULL; + // now we can add the basic square shape this->AddBlockRect( -0.5,-0.5,1,1 ); *************** *** 235,238 **** --- 238,251 ---- } + // this should be called after all models have loaded from the + // worldfile - it's a chance to do any setup now that all models are + // in existence + void StgModel::Init() + { + if( initfunc && updatefunc ) + Subscribe(); + + // anything else to do here? + } void StgModel::AddBlock( stg_point_t* pts, *************** *** 634,637 **** --- 647,653 ---- { //printf( "Startup model %s\n", this->token ); + + if( initfunc ) + initfunc( this ); world->StartUpdatingModel( this ); *************** *** 656,664 **** } - // void StgModel::UpdateTree( void ) - // { - // LISTMETHOD( this->children, StgModel*, UpdateTree ); - // } - void StgModel::Update( void ) { --- 672,675 ---- *************** *** 666,669 **** --- 677,684 ---- // this->world->sim_time_ms, this->token, this->subs ); + //puts( "UPDATE" ); + if( updatefunc ) + updatefunc( this ); + CallCallbacks( &update ); --- NEW FILE: ctrl.cc --- #include "stage.hh" using namespace Stg; extern "C" void Init( StgModel* mod ); extern "C" void Update( StgModel* mod ); StgModelPosition* pos = NULL; StgModelLaser* laser = NULL; // Stage calls this once when the model starts up void Init( StgModel* mod ) { puts( "Init controller" ); pos = (StgModelPosition*)mod; laser = (StgModelLaser*)mod->GetUnsubscribedModelOfType( "laser" ); assert( laser ); laser->Subscribe(); } // Stage calls this once per simulation update void Update( StgModel* mod ) { pos->SetSpeed( 0.1, 0, 0.1 ); } Index: Makefile =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Makefile,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile 12 Feb 2008 02:53:53 -0000 1.5 --- Makefile 20 Feb 2008 06:03:58 -0000 1.6 *************** *** 42,49 **** host_triplet = i386-apple-darwin9.2.0 target_triplet = i386-apple-darwin9.2.0 ! bin_PROGRAMS = stest$(EXEEXT) subdir = libstage DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \ ! $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ --- 42,49 ---- host_triplet = i386-apple-darwin9.2.0 target_triplet = i386-apple-darwin9.2.0 ! bin_PROGRAMS = stage$(EXEEXT) subdir = libstage DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \ ! $(srcdir)/Makefile.in TODO ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ *************** *** 64,69 **** libLTLIBRARIES_INSTALL = $(INSTALL) LTLIBRARIES = $(lib_LTLIBRARIES) libstage_la_DEPENDENCIES = ! am_libstage_la_OBJECTS = ancestor.lo block.lo canvas.lo \ glcolorstack.lo model.lo model_callbacks.lo model_fiducial.lo \ model_laser.lo model_load.lo model_position.lo model_ranger.lo \ --- 64,75 ---- libLTLIBRARIES_INSTALL = $(INSTALL) LTLIBRARIES = $(lib_LTLIBRARIES) + ctrl_la_LIBADD = + am_ctrl_la_OBJECTS = ctrl.lo + ctrl_la_OBJECTS = $(am_ctrl_la_OBJECTS) + ctrl_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(ctrl_la_LDFLAGS) $(LDFLAGS) -o $@ libstage_la_DEPENDENCIES = ! am_libstage_la_OBJECTS = ancestor.lo block.lo canvas.lo gl.lo \ glcolorstack.lo model.lo model_callbacks.lo model_fiducial.lo \ model_laser.lo model_load.lo model_position.lo model_ranger.lo \ *************** *** 76,81 **** binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) ! am_stest_OBJECTS = stest.$(OBJEXT) ! stest_OBJECTS = $(am_stest_OBJECTS) DEFAULT_INCLUDES = -I. -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp --- 82,87 ---- binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) ! am_stage_OBJECTS = main.$(OBJEXT) ! stage_OBJECTS = $(am_stage_OBJECTS) DEFAULT_INCLUDES = -I. -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp *************** *** 99,104 **** --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ ! SOURCES = $(libstage_la_SOURCES) $(stest_SOURCES) ! DIST_SOURCES = $(libstage_la_SOURCES) $(stest_SOURCES) pkgdataDATA_INSTALL = $(INSTALL_DATA) DATA = $(pkgdata_DATA) --- 105,111 ---- --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ ! SOURCES = $(ctrl_la_SOURCES) $(libstage_la_SOURCES) $(stage_SOURCES) ! DIST_SOURCES = $(ctrl_la_SOURCES) $(libstage_la_SOURCES) \ ! $(stage_SOURCES) pkgdataDATA_INSTALL = $(INSTALL_DATA) DATA = $(pkgdata_DATA) *************** *** 241,245 **** # build the stage library ! lib_LTLIBRARIES = libstage.la # The stage library --- 248,252 ---- # build the stage library ! lib_LTLIBRARIES = libstage.la ctrl.la # The stage library *************** *** 250,253 **** --- 257,261 ---- canvas.cc \ colors.h \ + gl.cc \ glcolorstack.cc \ model.cc \ *************** *** 272,279 **** #logo.cc libstage_la_LDFLAGS = -version-info 3:1:0 -rpath $(libdir) ! libstage_la_LIBADD = -L/opt/local/lib -lgdk_pixbuf-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -liconv -L/opt/local/lib -lfltk_images -lfltk_png -lz -lfltk_jpeg -lfltk_gl -framework AGL -framework OpenGL -lfltk -framework Carbon -framework ApplicationServices ! stest_DEPENDENCIES = libstage.la ! stest_SOURCES = stest.cc ! stest_LDADD = libstage.la all: all-am --- 280,289 ---- #logo.cc libstage_la_LDFLAGS = -version-info 3:1:0 -rpath $(libdir) ! libstage_la_LIBADD = -L/opt/local/lib -lgdk_pixbuf-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -liconv -L/opt/local/lib -lfltk_images -lfltk_png -lz -lfltk_jpeg -lfltk_gl -framework AGL -framework OpenGL -lfltk -framework Carbon -framework ApplicationServices -lltdl ! stage_DEPENDENCIES = libstage.la ! stage_SOURCES = main.cc ! stage_LDADD = libstage.la ! ctrl_la_SOURCES = ctrl.cc stage.hh ! ctrl_la_LDFLAGS = -module all: all-am *************** *** 336,339 **** --- 346,351 ---- rm -f "$${dir}/so_locations"; \ done + ctrl.la: $(ctrl_la_OBJECTS) $(ctrl_la_DEPENDENCIES) + $(ctrl_la_LINK) -rpath $(libdir) $(ctrl_la_OBJECTS) $(ctrl_la_LIBADD) $(LIBS) libstage.la: $(libstage_la_OBJECTS) $(libstage_la_DEPENDENCIES) $(libstage_la_LINK) -rpath $(libdir) $(libstage_la_OBJECTS) $(libstage_la_LIBADD) $(LIBS) *************** *** 366,372 **** rm -f $$p $$f ; \ done ! stest$(EXEEXT): $(stest_OBJECTS) $(stest_DEPENDENCIES) ! @rm -f stest$(EXEEXT) ! $(CXXLINK) $(stest_OBJECTS) $(stest_LDADD) $(LIBS) mostlyclean-compile: --- 378,384 ---- rm -f $$p $$f ; \ done ! stage$(EXEEXT): $(stage_OBJECTS) $(stage_DEPENDENCIES) ! @rm -f stage$(EXEEXT) ! $(CXXLINK) $(stage_OBJECTS) $(stage_LDADD) $(LIBS) mostlyclean-compile: *************** *** 379,383 **** --- 391,398 ---- include ./$(DEPDIR)/block.Plo include ./$(DEPDIR)/canvas.Plo + include ./$(DEPDIR)/ctrl.Plo + include ./$(DEPDIR)/gl.Plo include ./$(DEPDIR)/glcolorstack.Plo + include ./$(DEPDIR)/main.Po include ./$(DEPDIR)/model.Plo include ./$(DEPDIR)/model_blobfinder.Plo *************** *** 390,394 **** include ./$(DEPDIR)/model_ranger.Plo include ./$(DEPDIR)/stage.Plo - include ./$(DEPDIR)/stest.Po include ./$(DEPDIR)/typetable.Plo include ./$(DEPDIR)/world.Plo --- 405,408 ---- --- NEW FILE: main.cc --- #include "config.h" #include "stage_internal.hh" int main( int argc, char* argv[] ) { printf( %s %s\n", PACKAGE, VERSION ); if( argc < 2 ) { printf( "Usage: %s <worldfile>", PACKAGE ); exit(0); } // initialize libstage Stg::Init( &argc, &argv ); StgWorldGui world(800, 700, argv[0]); world.Load( argv[1] ); while( ! world.TestQuit() ) world.RealTimeUpdate(); } Index: world.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/world.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** world.cc 18 Feb 2008 03:52:30 -0000 1.7 --- world.cc 20 Feb 2008 06:03:59 -0000 1.8 *************** *** 217,220 **** --- 217,226 ---- } + // wrapper to startup all models from the hash table + void init_models( gpointer dummy1, StgModel* mod, gpointer dummy2 ) + { + mod->Init(); + } + void StgWorld::Load( const char* worldfile_path ) { *************** *** 295,299 **** // warn about unused WF linesa wf->WarnUnused(); ! stg_usec_t load_end_time = RealTimeNow(); --- 301,308 ---- // warn about unused WF linesa wf->WarnUnused(); ! ! // run through the loaded models and initialise them ! g_hash_table_foreach( models_by_id, (GHFunc)init_models, NULL ); ! stg_usec_t load_end_time = RealTimeNow(); Index: model_load.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/model_load.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** model_load.cc 18 Feb 2008 03:52:30 -0000 1.3 --- model_load.cc 20 Feb 2008 06:03:58 -0000 1.4 *************** *** 7,10 **** --- 7,16 ---- //#define DEBUG 1 + #include <ltdl.h> + + void FooInit( StgModel* ); + void FooUpdate( StgModel* ); + + void StgModel::Load( void ) { *************** *** 315,326 **** this->SetMapResolution( wf->ReadFloat(this->id, "map_resolution", this->map_resolution )); ! // call any type-specific load callbacks ! this->CallCallbacks( &this->load ); ! ! ! if( this->debug ) ! printf( "Model \"%s\" is in debug mode\n", token ); ! ! PRINT_DEBUG1( "Model \"%s\" loading complete", token ); } --- 321,343 ---- this->SetMapResolution( wf->ReadFloat(this->id, "map_resolution", this->map_resolution )); ! ! if( wf->PropertyExists( this->id, "ctrl" )) ! { ! char* lib = (char*)wf->ReadString(this->id, "ctrl", NULL ); ! ! if( !lib ) ! puts( "Error - NULL library name" ); ! else ! LoadControllerModule( lib ); ! } ! ! // call any type-specific load callbacks ! this->CallCallbacks( &this->load ); ! ! ! if( this->debug ) ! printf( "Model \"%s\" is in debug mode\n", token ); ! ! PRINT_DEBUG1( "Model \"%s\" loading complete", token ); } *************** *** 353,354 **** --- 370,408 ---- PRINT_DEBUG1( "Model \"%s\" saving complete.", token ); } + + + void StgModel::LoadControllerModule( char* lib ) + { + printf( "Loading controller \"%s\" ...", lib ); + + /* Initialise libltdl. */ + int errors = lt_dlinit(); + assert(errors==0); + + // TODO - do this properly! + lt_dlsetsearchpath( ".:.libs:/usr/lib/" ); + + lt_dlhandle handle = NULL; + + if(( handle = lt_dlopenext( lib ) )) + puts( "success." ); + else + puts( "fail." ); + + this->initfunc = (ctrlinit_t*)lt_dlsym( handle, "Init" ); + if( this->initfunc == NULL ) + { + puts( lt_dlerror() ); + } + assert( this->initfunc ); + + this->updatefunc = (ctrlupdate_t*)lt_dlsym( handle, "Update" ); + if( this->updatefunc == NULL ) + { + puts( lt_dlerror() ); + } + assert( this->updatefunc ); + + //this->Subscribe(); // causes the model to startup and update + } + Index: Makefile.am =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 12 Feb 2008 02:53:53 -0000 1.3 --- Makefile.am 20 Feb 2008 06:03:58 -0000 1.4 *************** *** 17,21 **** # build the stage library ! lib_LTLIBRARIES = libstage.la # The stage library --- 17,21 ---- # build the stage library ! lib_LTLIBRARIES = libstage.la ctrl.la # The stage library *************** *** 26,29 **** --- 26,30 ---- canvas.cc \ colors.h \ + gl.cc \ glcolorstack.cc \ model.cc \ *************** *** 47,56 **** #logo.cc libstage_la_LDFLAGS = -version-info 3:1:0 -rpath $(libdir) ! libstage_la_LIBADD = @PIXBUF_LIBS@ @FLTK_LIBS@ # build stest, a stand-alone test binary using the stage library, ! bin_PROGRAMS = stest ! stest_DEPENDENCIES = libstage.la ! stest_SOURCES = stest.cc ! stest_LDADD = libstage.la --- 48,66 ---- #logo.cc libstage_la_LDFLAGS = -version-info 3:1:0 -rpath $(libdir) ! libstage_la_LIBADD = @PIXBUF_LIBS@ @FLTK_LIBS@ -lltdl # build stest, a stand-alone test binary using the stage library, ! #bin_PROGRAMS = stest stage ! #stest_DEPENDENCIES = libstage.la ! #stest_SOURCES = stest.cc ! #stest_LDADD = libstage.la ! ! bin_PROGRAMS = stage ! ! stage_DEPENDENCIES = libstage.la ! stage_SOURCES = main.cc ! stage_LDADD = libstage.la ! ! ctrl_la_SOURCES = ctrl.cc stage.hh ! ctrl_la_LDFLAGS = -module Index: Makefile.manual =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/Makefile.manual,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.manual 18 Feb 2008 03:52:30 -0000 1.5 --- Makefile.manual 20 Feb 2008 06:03:58 -0000 1.6 *************** *** 13,16 **** --- 13,17 ---- gl.cc \ glcolorstack.cc \ + main.cc \ model.cc \ model_callbacks.cc \ *************** *** 22,26 **** model_position.cc \ model_props.cc \ - stest.cc \ stage.cc \ typetable.cc \ --- 23,26 ---- *************** *** 30,33 **** --- 30,35 ---- # blockgrid.cc + # stest.cc + *************** *** 42,45 **** --- 44,48 ---- g++ $(CXXFLAGS) -c $< + stage: $(OBJ) g++ $(OBJ) -o $@ $(LIBS) *************** *** 49,51 **** demo: gldemo.cc ! g++ gldemo.cc -o $@ $(LIBS) \ No newline at end of file --- 52,59 ---- demo: gldemo.cc ! g++ gldemo.cc -o $@ $(LIBS) ! ! ctrl: ctrl.cc ! g++ $(CXXFLAGS) -fPIC -c ctrl.cc ! g++ -shared -o libctrl.so -fPIC ctrl.o ! Index: stage.hh =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/stage.hh,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** stage.hh 18 Feb 2008 03:52:30 -0000 1.6 --- stage.hh 20 Feb 2008 06:03:58 -0000 1.7 *************** *** 934,938 **** stg_id_t id; - //stg_meters_t width, height; GHashTable* models_by_id; ///< the models that make up the world, indexed by id --- 934,937 ---- *************** *** 1009,1014 **** stg_msec_t interval_real, double ppm ); - //double width, - //double height ); virtual ~StgWorld(); --- 1008,1011 ---- *************** *** 1069,1072 **** --- 1066,1072 ---- stg_usec_t time; } stg_trail_item_t; + + typedef void ctrlinit_t( StgModel* mod ); + typedef void ctrlupdate_t( StgModel* mod ); // MODEL CLASS *************** *** 1155,1158 **** --- 1155,1159 ---- double* hitx, double* hity ); + void Map(); void UnMap(); *************** *** 1221,1225 **** variables) */ char startup, shutdown, load, save, update; ! public: --- 1222,1229 ---- variables) */ char startup, shutdown, load, save, update; ! ! ctrlinit_t* initfunc; ! ctrlupdate_t* updatefunc; ! public: *************** *** 1238,1241 **** --- 1242,1248 ---- /** save the state of the model to the current world file */ virtual void Save(); + + /** Should be called after all models are loaded, to do any last-minute setup */ + void Init(); virtual void PushColor( stg_color_t col ) *************** *** 1249,1253 **** void Enable(){ disabled = false; }; void Disable(){ disabled = true; }; ! // call this to ensure the GUI window is redrawn void NeedRedraw(); --- 1256,1263 ---- void Enable(){ disabled = false; }; void Disable(){ disabled = true; }; ! ! // Load a control program for this model from an external library ! void LoadControllerModule( char* lib ); ! // call this to ensure the GUI window is redrawn void NeedRedraw(); Index: canvas.cc =================================================================== RCS file: /cvsroot/playerstage/code/stage/libstage/canvas.cc,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** canvas.cc 18 Feb 2008 03:52:30 -0000 1.7 --- canvas.cc 20 Feb 2008 06:03:58 -0000 1.8 *************** *** 97,102 **** glEnable(GL_DITHER); ! //glClearColor ( 0.7, 0.7, 0.8, 1.0); ! glClearColor ( 1,1,1,1 ); if( mod ) // we clicked on a root model --- 97,102 ---- glEnable(GL_DITHER); ! glClearColor ( 0.7, 0.7, 0.8, 1.0); ! //glClearColor ( 1,1,1,1 ); if( mod ) // we clicked on a root model *************** *** 340,345 **** // set gl state that won't change every redraw ! //glClearColor ( 0.7, 0.7, 0.8, 1.0); ! glClearColor ( 1,1,1,1 ); glDisable(GL_LIGHTING); glEnable (GL_DEPTH_TEST); --- 340,345 ---- // set gl state that won't change every redraw ! glClearColor ( 0.7, 0.7, 0.8, 1.0); ! //glClearColor ( 1,1,1,1 ); glDisable(GL_LIGHTING); glEnable (GL_DEPTH_TEST); *************** *** 423,440 **** } // draw the world size rectangle in white, using the polygon offset // so it doesn't z-fight with the models ! //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); ! //glEnable(GL_POLYGON_OFFSET_FILL); ! //glPolygonOffset(1.0, 1.0); ! //glColor3f( 1,1,1 ); ! //colorstack.Push(1,1,1); - glPushMatrix(); - glScalef( 1.0/world->Resolution(), 1.0/world->Resolution(), 0 ); ! //((StgWorldGui*)world)->DrawFloor(); ! //glDisable(GL_POLYGON_OFFSET_FILL); if( (showflags & STG_SHOW_QUADTREE) || (showflags & STG_SHOW_OCCUPANCY) ) --- 423,438 ---- } + glPushMatrix(); + // draw the world size rectangle in white, using the polygon offset // so it doesn't z-fight with the models ! glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); ! glEnable(GL_POLYGON_OFFSET_FILL); ! glPolygonOffset(1.0, 1.0); glScalef( 1.0/world->Resolution(), 1.0/world->Resolution(), 0 ); ! ((StgWorldGui*)world)->DrawFloor(); ! glDisable(GL_POLYGON_OFFSET_FILL); if( (showflags & STG_SHOW_QUADTREE) || (showflags & STG_SHOW_OCCUPANCY) ) |