Revision: 6856
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6856&view=rev
Author:   natepak
Date:     2008-07-11 16:37:55 -0700 (Fri, 11 Jul 2008)

Log Message:
-----------
Implemented timeout feature, and preliminary disabling of the physics engine.

Modified Paths:
--------------
    code/gazebo/trunk/server/Entity.hh
    code/gazebo/trunk/server/Model.cc
    code/gazebo/trunk/server/Simulator.cc
    code/gazebo/trunk/server/Simulator.hh
    code/gazebo/trunk/server/World.cc
    code/gazebo/trunk/server/main.cc
    code/gazebo/trunk/worlds/test.world

Modified: code/gazebo/trunk/server/Entity.hh
===================================================================
--- code/gazebo/trunk/server/Entity.hh  2008-07-11 23:05:24 UTC (rev 6855)
+++ code/gazebo/trunk/server/Entity.hh  2008-07-11 23:37:55 UTC (rev 6856)
@@ -108,7 +108,7 @@
   protected: Entity *parent;
 
   /// \brief Children of this entity
-  private: std::vector< Entity* > children;
+  protected: std::vector< Entity* > children;
 
   /// \brief This entities ID
   private: unsigned int id;

Modified: code/gazebo/trunk/server/Model.cc
===================================================================
--- code/gazebo/trunk/server/Model.cc   2008-07-11 23:05:24 UTC (rev 6855)
+++ code/gazebo/trunk/server/Model.cc   2008-07-11 23:37:55 UTC (rev 6856)
@@ -379,7 +379,7 @@
   Body *body;
   std::map<std::string, Body* >::iterator iter;
 
-  Pose3d bodyPose, origPose;
+  Pose3d newPose, origPose;
 
   origPose = this->pose;
   this->pose = setPose;
@@ -392,15 +392,27 @@
     body = iter->second;
 
     // Compute the pose relative to the model
-    bodyPose = body->GetPose() - origPose;
+    newPose = body->GetPose() - origPose;
 
     // Compute the new pose
-    bodyPose += this->pose;
+    newPose += this->pose;
 
+    body->SetPose(newPose);
+  }
 
-    body->SetPose(bodyPose);
+  // Update the child models as well
+  std::vector<Entity*>::iterator citer;
+  for (citer = this->children.begin(); citer != this->children.end(); citer++)
+  {
+    Model *childModel = dynamic_cast<Model*>(*citer);
+    if (childModel)
+    {
+      newPose = childModel->GetPose() - origPose;
+      newPose += this->pose;
+
+      childModel->SetPose(newPose);
+    }
   }
-
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc       2008-07-11 23:05:24 UTC (rev 
6855)
+++ code/gazebo/trunk/server/Simulator.cc       2008-07-11 23:37:55 UTC (rev 
6856)
@@ -65,7 +65,9 @@
   userStep(false),
   userStepInc(false),
   userQuit(false),
-  guiEnabled(true)
+  guiEnabled(true),
+  physicsEnabled(true),
+  timeout(-1)
 {
 }
 
@@ -294,6 +296,9 @@
     {
       usleep( (int)((1.0/MAX_FRAME_RATE - elapsedTime) * 1e6)  );
     }
+
+    if (this->timeout > 0 && this->GetRealTime() > this->timeout)
+      break;
   }
 }
 
@@ -441,4 +446,23 @@
   return this->guiEnabled;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+/// Set the length of time the simulation should run.
+void Simulator::SetTimeout(double time)
+{
+  this->timeout = time;
+}
 
+////////////////////////////////////////////////////////////////////////////////
+// Set the physics enabled/disabled
+void Simulator::SetPhysicsEnabled( bool enabled )
+{
+  this->physicsEnabled = enabled;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Get the physics enabled/disabled
+bool Simulator::GetPhysicsEnabled() const
+{
+  return this->physicsEnabled;
+}

Modified: code/gazebo/trunk/server/Simulator.hh
===================================================================
--- code/gazebo/trunk/server/Simulator.hh       2008-07-11 23:05:24 UTC (rev 
6855)
+++ code/gazebo/trunk/server/Simulator.hh       2008-07-11 23:37:55 UTC (rev 
6856)
@@ -148,7 +148,15 @@
     /// \brief Return true if the gui is enabled
     public: bool GetGuiEnabled() const;
 
-  
+    /// \brief Set the length of time the simulation should run.
+    public: void SetTimeout(double time);
+
+    /// \brief Set the physics enabled/disabled
+    public: void SetPhysicsEnabled(bool enabled);
+
+    /// \brief Get the physics enabled/disabled
+    public: bool GetPhysicsEnabled() const;
+
     ///pointer to the XML Data
     private: XMLConfig *xmlFile;
 
@@ -199,6 +207,12 @@
     /// True if the GUI is enabled
     private: bool guiEnabled;
 
+    /// True if physics is enabled
+    private: bool physicsEnabled;
+
+    /// Length of time the simulation should run
+    private: double timeout;
+
     //Singleton implementation
     private: friend class DestroyerT<Simulator>;
     private: friend class SingletonT<Simulator>;

Modified: code/gazebo/trunk/server/World.cc
===================================================================
--- code/gazebo/trunk/server/World.cc   2008-07-11 23:05:24 UTC (rev 6855)
+++ code/gazebo/trunk/server/World.cc   2008-07-11 23:37:55 UTC (rev 6856)
@@ -179,7 +179,8 @@
     }
   }
 
-  if (!Simulator::Instance()->IsPaused())
+  if (!Simulator::Instance()->IsPaused() &&
+       Simulator::Instance()->GetPhysicsEnabled())
   {
     this->physicsEngine->Update();
   }

Modified: code/gazebo/trunk/server/main.cc
===================================================================
--- code/gazebo/trunk/server/main.cc    2008-07-11 23:05:24 UTC (rev 6855)
+++ code/gazebo/trunk/server/main.cc    2008-07-11 23:37:55 UTC (rev 6856)
@@ -118,8 +118,8 @@
 double optTimeout = -1;
 unsigned int optMsgLevel = 1;
 int optTimeControl = 1;
+bool optPhysicsEnabled  = true;
 
-
 
////////////////////////////////////////////////////////////////////////////////
 // TODO: Implement these options
 void PrintUsage()
@@ -133,6 +133,7 @@
   fprintf(stderr, "  -g            : Run without a GUI\n");
   fprintf(stderr, "  -l <logfile>  : Log to indicated file.\n");
   fprintf(stderr, "  -n            : Do not do any time control\n");
+  fprintf(stderr,"   -p            : Run without physics engine\n");
   fprintf(stderr, "  <worldfile>   : load the the indicated world file\n");
   return;
 }
@@ -155,7 +156,7 @@
 {
   FILE *tmpFile;
   int ch;
-  char *flags = (char*)("l:hd:s:fgxt:nq");
+  char *flags = (char*)("l:hd:s:fgxt:nqp");
 
   // Get letter options
   while ((ch = getopt(argc, argv, flags)) != -1)
@@ -195,6 +196,10 @@
         optGuiEnabled = false;
         break;
 
+      case 'p':
+        optPhysicsEnabled = false;
+        break;
+
       case 'h':
       default:
         PrintUsage();
@@ -260,6 +265,8 @@
   try
   {
     gazebo::Simulator::Instance()->Load(worldFileName, optServerId);
+    gazebo::Simulator::Instance()->SetTimeout(optTimeout);
+    gazebo::Simulator::Instance()->SetPhysicsEnabled(optPhysicsEnabled);
   }
   catch (gazebo::GazeboError e)
   {

Modified: code/gazebo/trunk/worlds/test.world
===================================================================
--- code/gazebo/trunk/worlds/test.world 2008-07-11 23:05:24 UTC (rev 6855)
+++ code/gazebo/trunk/worlds/test.world 2008-07-11 23:37:55 UTC (rev 6856)
@@ -86,7 +86,7 @@
   <model:physical name="sphere1_model">
     <xyz>2.15 -1.68 .7</xyz>
     <rpy>0.0 0.0 0.0</rpy>
-    <static>true</static>
+    <static>false</static>
 
     <body:sphere name="sphere1_body">
       <geom:sphere name="sphere1_geom">


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to