Revision: 8224
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8224&view=rev
Author:   rtv
Date:     2009-08-25 18:58:06 +0000 (Tue, 25 Aug 2009)

Log Message:
-----------
better fix for removing update events on zero subscriptions

Modified Paths:
--------------
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/world.cc
    code/stage/trunk/webstage/CMakeLists.txt
    code/stage/trunk/webstage/webstage.cc
    code/stage/trunk/worlds/benchmark/expand_swarm.cc
    code/stage/trunk/worlds/benchmark/hospital.world

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2009-08-25 10:44:06 UTC (rev 8223)
+++ code/stage/trunk/libstage/model.cc  2009-08-25 18:58:06 UTC (rev 8224)
@@ -665,12 +665,9 @@
 
 void Model::Update( void )
 { 
-  CallCallbacks( &hooks.update );
-
-  last_update = world->sim_time;
-  
-  if( subs > 0 )
-        world->Enqueue( event_queue_num, World::Event::UPDATE, interval, this 
);
+  CallCallbacks( &hooks.update );  
+  last_update = world->sim_time;  
+  world->Enqueue( event_queue_num, World::Event::UPDATE, interval, this );
 }
 
 
@@ -790,7 +787,6 @@
         }
   
   // set up the next event
-  if( subs > 0 ) // TODO XX ? 
   world->Enqueue( 0, World::Event::ENERGY, interval_energy, this );
 }
 
@@ -851,11 +847,8 @@
                if( trail.size() > trail_length )
                  trail.pop_front();
         }                  
-
-  //if( ! velocity.IsZero() )
-
-  if( subs > 0 )// TODO XX ? 
-        world->Enqueue( 0, World::Event::POSE, interval_pose, this );
+  
+  world->Enqueue( 0, World::Event::POSE, interval_pose, this );
 }
 
 Model* Model::GetUnsubscribedModelOfType( const std::string& type ) const

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2009-08-25 10:44:06 UTC (rev 8223)
+++ code/stage/trunk/libstage/world.cc  2009-08-25 18:58:06 UTC (rev 8224)
@@ -477,12 +477,15 @@
     {
       // printf( "@ %llu next event <%s %llu %s>\n",  sim_time, ev.TypeStr( 
ev.type ), ev.time, ev.mod->Token() ); 
       queue.pop();      
+               
       // only update events are allowed in queues other than zero
       if( queue_num > 0 && ev.type != Event::UPDATE )
-       PRINT_WARN1( "event type %d in async queue", queue_num );
+                 PRINT_WARN1( "event type %d in async queue", queue_num );
       
-      //process the event and move to the next
-      ev.Execute();
+               if( ev.mod->subs > 0 ) // no subscriptions means the event is 
discarded
+                 ev.Execute(); // simulate the event
+
+      // and move to the next
       ev = queue.top();
     }
 }
@@ -536,14 +539,14 @@
   
   // world callbacks
   CallUpdateCallbacks();
-  
-  ++updates;  
-  
+    
   if( show_clock && ((this->updates % show_clock_interval) == 0) )
     {
       printf( "\r[Stage: %s]", ClockString().c_str() );
       fflush( stdout );
     }
+
+  ++updates;  
     
   return false;
 }

Modified: code/stage/trunk/webstage/CMakeLists.txt
===================================================================
--- code/stage/trunk/webstage/CMakeLists.txt    2009-08-25 10:44:06 UTC (rev 
8223)
+++ code/stage/trunk/webstage/CMakeLists.txt    2009-08-25 18:58:06 UTC (rev 
8224)
@@ -1,19 +1,8 @@
 MESSAGE( STATUS "Configuring webstage" )
 
-#include(FindPkgConfig)
-
-#pkg_search_module( LIBXML2 REQUIRED libxml-2.0)
-#IF( LIBXML2_FOUND )
-#  MESSAGE( STATUS ${INDENT} "libxml version ${LIBXML2_VERSION} detected at 
${LIBXML2_PREFIX}" )
-#ELSE( LIBXML2_FOUND )
-#  MESSAGE( ${INDENT} "libxml2 not detected" )
-#ENDIF( LIBXML2_FOUND )
-
-#include_directories( ${LIBXML2_INCLUDE_DIRS} )
-
 add_executable( webstage webstage.cc )
 
-target_link_libraries( webstage  ${WEBSIM_LIBRARIES} stage )
+target_link_libraries( webstage  ${WEBSIM_LIBRARIES} event stage )
 
 INSTALL(TARGETS webstage
        RUNTIME DESTINATION bin

Modified: code/stage/trunk/webstage/webstage.cc
===================================================================
--- code/stage/trunk/webstage/webstage.cc       2009-08-25 10:44:06 UTC (rev 
8223)
+++ code/stage/trunk/webstage/webstage.cc       2009-08-25 18:58:06 UTC (rev 
8224)
@@ -49,19 +49,29 @@
         return true;
   }
 
-  virtual bool ClockRunFor( double usec )
+  virtual bool ClockRunFor( uint32_t msec )
   {
         puts( "[WebStage]  Clock tick" );
-
+        
         world->paused = true;
-        // when paused, the world will run while steps > 0, decrementing
-        // steps each cycle.
-        // TODO
-        world->steps = 1;//(usec * 1e6) / world->GetSimInterval();
+        world->sim_interval = msec * 1e3; // usec
+        world->Update();
 
         return true;
   }
 
+  virtual bool GetModelType( const std::string& name, std::string& type )
+  {
+        Stg::Model* mod = world->GetModel( name.c_str() );
+
+        if( ! mod )
+               return false;
+        
+        type = mod->GetModelType();
+        return true;
+  }
+ 
+
   void Push( const std::string& name )
   {
         Stg::Model* mod = world->GetModel( name.c_str() );
@@ -193,7 +203,7 @@
 
         Model*mod = world->GetModel( name.c_str() );
         if(mod){
-               stg_model_type_t type = mod->GetModelType();
+               std::string type = mod->GetModelType();
                if(type == "position") {
 
                  websim::Pose p;
@@ -333,232 +343,249 @@
         return true;
   }
 
-virtual bool GetModelPVA(const std::string& name, 
-                                                                websim::Time& 
t,
-                                                                websim::Pose& 
p,
-                                                                
websim::Velocity& v,
-                                                                
websim::Acceleration& a,
-                                                                std::string& 
error)
-{
-  //printf( "get model name:%s\n", name.c_str() ); 
+  virtual bool GetModelPVA(const std::string& name, 
+                                                                       
websim::Time& t,
+                                                                       
websim::Pose& p,
+                                                                       
websim::Velocity& v,
+                                                                       
websim::Acceleration& a,
+                                                                       
std::string& error)
+  {
+        //printf( "get model name:%s\n", name.c_str() ); 
 
-  t = GetTime();
+        t = GetTime();
 
-  Model* mod = world->GetModel( name.c_str() );
-  if( mod )
-        {
-               Stg::Pose sp = mod->GetPose(); 
-               p.x = sp.x;
-               p.y = sp.y;
-               p.z = sp.z;
-               p.a = sp.a;
+        Model* mod = world->GetModel( name.c_str() );
+        if( mod )
+               {
+                 Stg::Pose sp = mod->GetPose(); 
+                 p.x = sp.x;
+                 p.y = sp.y;
+                 p.z = sp.z;
+                 p.a = sp.a;
 
-               Stg::Velocity sv = mod->GetVelocity(); 
-               v.x = sv.x;
-               v.y = sv.y;
-               v.z = sv.z;
-               v.a = sv.a;
-        }
-  else
-        printf( "Warning: attempt to set PVA for unrecognized model \"%s\"\n",
-                               name.c_str() );
+                 Stg::Velocity sv = mod->GetVelocity(); 
+                 v.x = sv.x;
+                 v.y = sv.y;
+                 v.z = sv.z;
+                 v.a = sv.a;
+               }
+        else
+               printf( "Warning: attempt to set PVA for unrecognized model 
\"%s\"\n",
+                                 name.c_str() );
 
-  return true;
-}
-/*
-  virtual bool GetLaserData(const std::string& name,                   
-  websim::Time& t,                                                             
                                
-  uint32_t& resolution,
-  double& fov,
-  websim::Pose& p,
-  std::vector<double>& ranges,                                                 
                                                
-  std::string& error,
-  void* parent){
+        return true;
+  }
+  /*
+        virtual bool GetLaserData(const std::string& name,                     
+        websim::Time& t,                                                       
                                        
+        uint32_t& resolution,
+        double& fov,
+        websim::Pose& p,
+        std::vector<double>& ranges,                                           
                                                        
+        std::string& error,
+        void* parent){
 
 
-  t = GetTime();
+        t = GetTime();
 
-  Model* mod = world->GetModel( name.c_str() );
-  if( mod )
-  {
-  ModelLaser* laser = (ModelLaser*)mod->GetModel("laser:0");           
+        Model* mod = world->GetModel( name.c_str() );
+        if( mod )
+        {
+        ModelLaser* laser = (ModelLaser*)mod->GetModel("laser:0");             
                        
-  if(laser){
-  uint32_t sample_count=0;
-  ModelLaser::Sample* scan = laser->GetSamples( &sample_count );
-  assert(scan);
+        if(laser){
+        uint32_t sample_count=0;
+        ModelLaser::Sample* scan = laser->GetSamples( &sample_count );
+        assert(scan);
                    
-  ModelLaser::Config  cfg = laser->GetConfig();
-  resolution =  cfg.resolution;
-  fov = cfg.fov;
+        ModelLaser::Config  cfg = laser->GetConfig();
+        resolution =  cfg.resolution;
+        fov = cfg.fov;
         
-  for(unsigned int i=0;i<sample_count;i++)
-  ranges.push_back(scan[i].range);
-  }else{
+        for(unsigned int i=0;i<sample_count;i++)
+        ranges.push_back(scan[i].range);
+        }else{
 
-  printf( "Warning: attempt to get laser data for unrecognized laser model of 
model \"%s\"\n",
-  name.c_str() );
-  return false;
+        printf( "Warning: attempt to get laser data for unrecognized laser 
model of model \"%s\"\n",
+        name.c_str() );
+        return false;
 
 
-  }
+        }
                          
-  }
-  else{
-  printf( "Warning: attempt to get laser data for unrecognized model \"%s\"\n",
-  name.c_str() );
-  return false;
-  }
+        }
+        else{
+        printf( "Warning: attempt to get laser data for unrecognized model 
\"%s\"\n",
+        name.c_str() );
+        return false;
+        }
 
-  return true;
+        return true;
 
-  }                                       
-  virtual bool GetRangerData(const std::string& name,
-  websim::Time& t,
-  std::vector<websim::Pose>& p,
-  std::vector<double>& ranges,
-  std::string& response,
-  xmlNode* parent){
-  t = GetTime();
+        }                                         
+        virtual bool GetRangerData(const std::string& name,
+        websim::Time& t,
+        std::vector<websim::Pose>& p,
+        std::vector<double>& ranges,
+        std::string& response,
+        xmlNode* parent){
+        t = GetTime();
 
-  Model* mod = world->GetModel( name.c_str() );
-  if( mod )
-  {
-  ModelRanger* ranger = (ModelRanger*)mod->GetModel("ranger:0");               
+        Model* mod = world->GetModel( name.c_str() );
+        if( mod )
+        {
+        ModelRanger* ranger = (ModelRanger*)mod->GetModel("ranger:0");         
        
        
-  if(ranger){
-  uint32_t count = ranger->sensors.size();
-  for(unsigned int i=0;i<count;i++)
-  ranges.push_back(ranger->sensors[i].range);
-  
//std::copy(ranger->samples,ranger->samples+ranger->sensor_count,ranges.begin());
+        if(ranger){
+        uint32_t count = ranger->sensors.size();
+        for(unsigned int i=0;i<count;i++)
+        ranges.push_back(ranger->sensors[i].range);
+        
//std::copy(ranger->samples,ranger->samples+ranger->sensor_count,ranges.begin());
                                 
-  for(unsigned int i=0;i<count;i++){
-  websim::Pose pos;
-  Pose rpos;
-  rpos = ranger->sensors[i].pose;
-  pos.x = rpos.x;
-  pos.y = rpos.y;
-  pos.z = rpos.z;
-  pos.a = rpos.a;
-  p.push_back(pos);                                    
-  }
+        for(unsigned int i=0;i<count;i++){
+        websim::Pose pos;
+        Pose rpos;
+        rpos = ranger->sensors[i].pose;
+        pos.x = rpos.x;
+        pos.y = rpos.y;
+        pos.z = rpos.z;
+        pos.a = rpos.a;
+        p.push_back(pos);                                      
+        }
                                 
-  }else{
+        }else{
                                 
-  printf( "Warning: attempt to get ranger data for unrecognized ranger model 
of model \"%s\"\n",
-  name.c_str() );
-  return false;                                                                
 
-  }         
-  }
-  else{
-  printf( "Warning: attempt to get ranger data for unrecognized model 
\"%s\"\n",
-  name.c_str() );
-  return false;
-  }
+        printf( "Warning: attempt to get ranger data for unrecognized ranger 
model of model \"%s\"\n",
+        name.c_str() );
+        return false;                                                          
 
+        }           
+        }
+        else{
+        printf( "Warning: attempt to get ranger data for unrecognized model 
\"%s\"\n",
+        name.c_str() );
+        return false;
+        }
 
-  return true;
+        return true;
 
-  }*/
+        }*/
 
-virtual bool GetModelGeometry(const std::string& name,
-                                                                               
double& x,
-                                                                               
double& y,
-                                                                               
double& z,
-                                                                               
websim::Pose& center,
-                                                                               
std::string& response)
-{
-  if(name == "sim"){
+  virtual bool GetModelGeometry(const std::string& name,
+                                                                               
  double& x,
+                                                                               
  double& y,
+                                                                               
  double& z,
+                                                                               
  websim::Pose& center,
+                                                                               
  std::string& response)
+  {
+        if(name == "sim"){
        
-        stg_bounds3d_t ext = world->GetExtent();
+               stg_bounds3d_t ext = world->GetExtent();
        
-        x = ext.x.max - ext.x.min;
-        y = ext.y.max - ext.y.min;
-        z = ext.z.max - ext.z.min;
+               x = ext.x.max - ext.x.min;
+               y = ext.y.max - ext.y.min;
+               z = ext.z.max - ext.z.min;
 
-  }
-  else
-        {
-               Model* mod = world->GetModel(name.c_str());
-               if(mod){
-                 Geom ext = mod->GetGeom();
+        }
+        else
+               {
+                 Model* mod = world->GetModel(name.c_str());
+                 if(mod){
+                        Geom ext = mod->GetGeom();
        
-                 x = ext.size.x;
-                 y = ext.size.y;
-                 z = ext.size.z;
-                 center.x = ext.pose.x;
-                 center.y = ext.pose.y;
-                 center.a = ext.pose.a;
+                        x = ext.size.x;
+                        y = ext.size.y;
+                        z = ext.size.z;
+                        center.x = ext.pose.x;
+                        center.y = ext.pose.y;
+                        center.a = ext.pose.a;
+                 }
+                 else
+                        {
+                               printf("Warning: attemp to get the extent of 
unrecognized model \"%s\"\n", name.c_str());
+                               return false;           
+                        }
                }
-               else
-                 {
-                        printf("Warning: attemp to get the extent of 
unrecognized model \"%s\"\n", name.c_str());
-                        return false;          
-                 }
-        }
         
-  return true;
-}
+        return true;
+  }
 
-static int CountRobots(Model * mod, int* n ){
+  static int CountRobots(Model * mod, int* n ){
  
-  if(n && mod->GetModelType() == MODEL_TYPE_POSITION)
-        (*n)++;
+        if(n && mod->GetModelType() == "position")
+               (*n)++;
   
-  return 0;
-} 
+        return 0;
+  } 
   
-virtual bool GetNumberOfRobots(unsigned int& n)
-{
+  virtual bool GetNumberOfRobots(unsigned int& n)
+  {
        
        
-  world->ForEachDescendant((stg_model_callback_t)CountRobots, &n);     
-  return true;
+        world->ForEachDescendant((stg_model_callback_t)CountRobots, &n);       
+        return true;
 
-}
-/*
-  virtual bool GetModelTree()
-  {
+  }
+  /*
+        virtual bool GetModelTree()
+        {
        
-  //   world->ForEachDescendant((stg_model_callback_t)printname, NULL);        
+        //     world->ForEachDescendant((stg_model_callback_t)printname, 
NULL);        
 
-  return true;
-  }
-*/
-virtual bool GetSayStrings(std::vector<std::string>& sayings)
-{
-  unsigned int n=0;
-  this->GetNumberOfRobots(n);
+        return true;
+        }
+  */
+  virtual bool GetSayStrings(std::vector<std::string>& sayings)
+  {
+        unsigned int n=0;
+        this->GetNumberOfRobots(n);
        
-  for(unsigned int i=0;i<n;i++){
-        char temp[128];
-        sprintf(temp,"position:%d",i);
-        Model *mod = world->GetModel(temp);
-        if(mod->GetSayString() != "")
-               {       
+        for(unsigned int i=0;i<n;i++){
+               char temp[128];
+               sprintf(temp,"position:%d",i);
+               Model *mod = world->GetModel(temp);
+               if(mod->GetSayString() != "")
+                 {     
                        
-                 std::string str = temp;
-                 str += " says: \" ";
-                 str += mod->GetSayString();
-                 str += " \" ";
+                        std::string str = temp;
+                        str += " says: \" ";
+                        str += mod->GetSayString();
+                        str += " \" ";
                        
-                 sayings.push_back(str);
+                        sayings.push_back(str);
                        
-               }
+                 }
+        }
+
+        return true;
   }
 
-  return true;
-}
+  virtual websim::Time GetTime()
+  {
+        stg_usec_t stgtime = world->SimTimeNow();
 
-virtual websim::Time GetTime()
-{
-  stg_usec_t stgtime = world->SimTimeNow();
+        websim::Time t;
+        t.sec = stgtime / 1e6;
+        t.usec = stgtime - (t.sec * 1e6);
+        return t;
+  }
+  
+  // add an FLTK event loop update to WebSim's implementation
+  virtual void Wait()
+  {
+        Fl::check();  
+        
+        while( unacknowledged_ticks || unacknowledged_pushes || 
ticks_remaining )
+               {                        
+                 printf( "event loop in wait (%d %d %d)\n",
+                                        unacknowledged_ticks, 
unacknowledged_pushes, ticks_remaining );
 
-  websim::Time t;
-  t.sec = stgtime / 1e6;
-  t.usec = stgtime - (t.sec * 1e6);
-  return t;
-}
-
+                 event_loop( EVLOOP_NONBLOCK );
+                 
+                 puts( "fl::check\n" );
+                 Fl::check();  
+               }        
+  }
+  
 };
 
 
@@ -636,20 +663,22 @@
                // todo? check for changes?
                // send my updates              
                ws.Push();
-               //puts( "pushes  done" );
+               //puts( "push  done" );
 
-               // tell my friends to start simulating
-               ws.Go();
+               // run one step of the simulation
+               ws.Tick();
                
-               // puts( "go done" );
+               //puts( "tick done" );
                
                // update Stage
                world->Update();
                //puts( "update done" );
+         
+               Fl::check();
 
-               // wait for goes from all my friends
+               // wait until everyone report simulation step done
                ws.Wait();                      
-               //puts( "wait done" );
+               puts( "wait done" );
         }
 
   printf( "Webstage done.\n" );

Modified: code/stage/trunk/worlds/benchmark/expand_swarm.cc
===================================================================
--- code/stage/trunk/worlds/benchmark/expand_swarm.cc   2009-08-25 10:44:06 UTC 
(rev 8223)
+++ code/stage/trunk/worlds/benchmark/expand_swarm.cc   2009-08-25 18:58:06 UTC 
(rev 8224)
@@ -39,7 +39,8 @@
   // subscribe to the ranger, which we use for navigating
   robot->ranger = (ModelRanger*)mod->GetModel( "ranger:0" );
   assert( robot->ranger );
-  
+
+
   // ask Stage to call into our ranger update function
   robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot 
);
 

Modified: code/stage/trunk/worlds/benchmark/hospital.world
===================================================================
--- code/stage/trunk/worlds/benchmark/hospital.world    2009-08-25 10:44:06 UTC 
(rev 8223)
+++ code/stage/trunk/worlds/benchmark/hospital.world    2009-08-25 18:58:06 UTC 
(rev 8224)
@@ -43,6 +43,7 @@
   color "random"
 
   ranger( pose [ 0 0 -0.050 0 ] 
+  alwayson 1
 
          scount 12 
          spose[0] [0 0 0]


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
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to