Revision: 8686
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8686&view=rev
Author:   natepak
Date:     2010-05-17 20:04:25 +0000 (Mon, 17 May 2010)

Log Message:
-----------
Added ability to start gazebo with no world file

Modified Paths:
--------------
    code/gazebo/trunk/server/GazeboMessage.cc
    code/gazebo/trunk/server/Param.hh
    code/gazebo/trunk/server/Simulator.cc
    code/gazebo/trunk/server/Simulator.hh
    code/gazebo/trunk/server/World.cc
    code/gazebo/trunk/server/XMLConfig.cc
    code/gazebo/trunk/server/gui/Gui.cc
    code/gazebo/trunk/server/main.cc
    code/gazebo/trunk/server/physics/ode/ODEPhysics.cc
    code/gazebo/trunk/server/rendering/OgreAdaptor.cc

Modified: code/gazebo/trunk/server/GazeboMessage.cc
===================================================================
--- code/gazebo/trunk/server/GazeboMessage.cc   2010-05-17 18:14:43 UTC (rev 
8685)
+++ code/gazebo/trunk/server/GazeboMessage.cc   2010-05-17 20:04:25 UTC (rev 
8686)
@@ -74,11 +74,6 @@
 {
   char logFilename[50];
 
-  if (!node)
-  {
-    gzthrow("Null XMLConfig node");
-  }
-
   this->verbosityP->Load(node);
   this->logDataP->Load(node);
 

Modified: code/gazebo/trunk/server/Param.hh
===================================================================
--- code/gazebo/trunk/server/Param.hh   2010-05-17 18:14:43 UTC (rev 8685)
+++ code/gazebo/trunk/server/Param.hh   2010-05-17 20:04:25 UTC (rev 8686)
@@ -152,8 +152,11 @@
     std::ostringstream stream;
     stream << this->defaultValue;
 
-    std::string input = node->GetString(this->key, stream.str(), 
-                                        this->required);
+    std::string input;
+    if (node)
+      input = node->GetString(this->key, stream.str(), this->required);
+    else
+      input = stream.str();
 
     this->SetFromString( input );
   }

Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc       2010-05-17 18:14:43 UTC (rev 
8685)
+++ code/gazebo/trunk/server/Simulator.cc       2010-05-17 20:04:25 UTC (rev 
8686)
@@ -50,6 +50,47 @@
 
 using namespace gazebo;
 
+std::string Simulator::defaultWorld = 
+"<?xml version='1.0'?> <gazebo:world 
xmlns:xi='http://www.w3.org/2001/XInclude' 
xmlns:gazebo='http://playerstage.sourceforge.net/gazebo/xmlschema/#gz' 
xmlns:model='http://playerstage.sourceforge.net/gazebo/xmlschema/#model' 
xmlns:sensor='http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor' 
xmlns:body='http://playerstage.sourceforge.net/gazebo/xmlschema/#body' 
xmlns:geom='http://playerstage.sourceforge.net/gazebo/xmlschema/#geom' 
xmlns:joint='http://playerstage.sourceforge.net/gazebo/xmlschema/#joint' 
xmlns:interface='http://playerstage.sourceforge.net/gazebo/xmlschema/#interface'
 
xmlns:rendering='http://playerstage.sourceforge.net/gazebo/xmlschema/#rendering'
 
xmlns:renderable='http://playerstage.sourceforge.net/gazebo/xmlschema/#renderable'
 
xmlns:controller='http://playerstage.sourceforge.net/gazebo/xmlschema/#controller'
 xmlns:physics='http://playerstage.sourceforge.net/gazebo/xmlschema/#physics' >\
+  <physics:ode>\
+    <stepTime>0.001</stepTime>\
+    <gravity>0 0 -9.8</gravity>\
+    <cfm>0.0000000001</cfm>\
+    <erp>0.2</erp>\
+    <quickStep>true</quickStep>\
+    <quickStepIters>10</quickStepIters>\
+    <quickStepW>1.3</quickStepW>\
+    <contactMaxCorrectingVel>100.0</contactMaxCorrectingVel>\
+    <contactSurfaceLayer>0.001</contactSurfaceLayer>\
+  </physics:ode>\
+  <rendering:gui>\
+    <type>fltk</type>\
+    <size>800 600</size>\
+    <pos>0 0</pos>\
+  </rendering:gui>\
+  <rendering:ogre>\
+    <ambient>1 1 1 1</ambient>\
+    <shadowTechnique>stencilModulative</shadowTechnique>\
+    <grid>false</grid>\
+  </rendering:ogre>\
+   <model:physical name=\"plane1_model\">\
+    <xyz>0 0 0</xyz>\
+    <rpy>0 0 0</rpy>\
+    <static>true</static>\
+    <body:plane name=\"plane1_body\">\
+      <geom:plane name=\"plane1_geom\">\
+        <normal>0 0 1</normal>\
+        <size>100 100</size>\
+        <segments>10 10</segments>\
+        <uvTile>100 100</uvTile>\
+        <material>Gazebo/GrayGrid</material>\
+        <mu1>109999.0</mu1>\
+        <mu2>1000.0</mu2>\
+      </geom:plane>\
+    </body:plane>\
+  </model:physical>\
+</gazebo:world>";
+
 
////////////////////////////////////////////////////////////////////////////////
 // Constructor
 Simulator::Simulator()
@@ -150,9 +191,13 @@
 
   // Load the world file
   this->xmlFile=new gazebo::XMLConfig();
+
   try
   {
-    this->xmlFile->Load(worldFileName);
+    if (worldFileName.size())
+      this->xmlFile->Load(worldFileName);
+    else
+      this->xmlFile->LoadString(defaultWorld);
   }
   catch (GazeboError e)
   {
@@ -183,19 +228,23 @@
   {
     try
     {
-      XMLConfigNode *childNode = rootNode->GetChild("gui");
+      XMLConfigNode *childNode = NULL;
+      if (rootNode)
+       childNode = rootNode->GetChild("gui");
 
+      int width, height, x, y;
+
       if (childNode)
       {
-        int width = childNode->GetTupleInt("size", 0, 800);
-        int height = childNode->GetTupleInt("size", 1, 600);
-        int x = childNode->GetTupleInt("pos",0,0);
-        int y = childNode->GetTupleInt("pos",1,0);
+        width = childNode->GetTupleInt("size", 0, 800);
+        height = childNode->GetTupleInt("size", 1, 600);
+        x = childNode->GetTupleInt("pos",0,0);
+        y = childNode->GetTupleInt("pos",1,0);
+      }
 
-        //gzmsg(1) << "Creating GUI: Pos[" << x << " " << y 
-        //         << "] Size[" << width << " " << height << "]\n";
-
         // Create the GUI
+      if (childNode || !rootNode)
+      {
         this->gui = new Gui(x, y, width, height, "Gazebo");
 
         this->gui->Load(childNode);

Modified: code/gazebo/trunk/server/Simulator.hh
===================================================================
--- code/gazebo/trunk/server/Simulator.hh       2010-05-17 18:14:43 UTC (rev 
8685)
+++ code/gazebo/trunk/server/Simulator.hh       2010-05-17 20:04:25 UTC (rev 
8686)
@@ -254,6 +254,7 @@
     private: friend class DestroyerT<Simulator>;
     private: friend class SingletonT<Simulator>;
 
+    private: static std::string defaultWorld;
 };
 
 

Modified: code/gazebo/trunk/server/World.cc
===================================================================
--- code/gazebo/trunk/server/World.cc   2010-05-17 18:14:43 UTC (rev 8685)
+++ code/gazebo/trunk/server/World.cc   2010-05-17 20:04:25 UTC (rev 8686)
@@ -196,19 +196,24 @@
   }
 
   // Load OpenAL audio 
-  if (rootNode->GetChild("openal","audio"))
+  if (rootNode && rootNode->GetChild("openal","audio"))
   {
     this->openAL = OpenAL::Instance();
     this->openAL->Load(rootNode->GetChild("openal", "audio"));
   }
 
-  XMLConfigNode *physicsNode = rootNode->GetChildByNSPrefix("physics");
+  XMLConfigNode *physicsNode = NULL;
+  if (rootNode )
+    physicsNode = rootNode->GetChildByNSPrefix("physics");
+
   if (Simulator::Instance()->GetPhysicsEnabled() && physicsNode)
   {
     this->physicsEngine = PhysicsFactory::NewPhysicsEngine( 
physicsNode->GetName());
     if (this->physicsEngine == NULL)
       gzthrow("Unable to create physics engine\n");
   }
+  else
+    this->physicsEngine = PhysicsFactory::NewPhysicsEngine("ode");
 
   // last bool is initModel, init model is not needed as Init()
   // is called separately from main.cc
@@ -451,7 +456,7 @@
   XMLConfigNode *cnode;
   Model *model = NULL;
 
-  if (node->GetNSPrefix() != "")
+  if (node && node->GetNSPrefix() != "")
   {
     // Check for model nodes
     if (node->GetNSPrefix() == "model")
@@ -462,11 +467,9 @@
   }
 
   // Load children
-  for (cnode = node->GetChild(); cnode != NULL; cnode = cnode->GetNext())
-  {
-    this->LoadEntities( cnode, model, removeDuplicate, initModel);
-  }
-
+  if (node)
+    for (cnode = node->GetChild(); cnode != NULL; cnode = cnode->GetNext())
+      this->LoadEntities( cnode, model, removeDuplicate, initModel);
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: code/gazebo/trunk/server/XMLConfig.cc
===================================================================
--- code/gazebo/trunk/server/XMLConfig.cc       2010-05-17 18:14:43 UTC (rev 
8685)
+++ code/gazebo/trunk/server/XMLConfig.cc       2010-05-17 20:04:25 UTC (rev 
8686)
@@ -390,7 +390,6 @@
 {
   XMLConfigNode *tmp;
 
-
   for (tmp = this->childFirst; tmp != NULL; tmp = tmp->GetNext() )
   {
     if (tmp->xmlNode->name && name == (const char*)tmp->xmlNode->name)

Modified: code/gazebo/trunk/server/gui/Gui.cc
===================================================================
--- code/gazebo/trunk/server/gui/Gui.cc 2010-05-17 18:14:43 UTC (rev 8685)
+++ code/gazebo/trunk/server/gui/Gui.cc 2010-05-17 20:04:25 UTC (rev 8686)
@@ -136,7 +136,10 @@
   this->sizeP->Load(node);
   this->posP->Load(node);
 
-  this->frameMgr->Load( node->GetChild("frames") );
+  if (node)
+    this->frameMgr->Load( node->GetChild("frames") );
+  else
+    this->frameMgr->Load(NULL);
 }
 
 
////////////////////////////////////////////////////////////////////////////////

Modified: code/gazebo/trunk/server/main.cc
===================================================================
--- code/gazebo/trunk/server/main.cc    2010-05-17 18:14:43 UTC (rev 8685)
+++ code/gazebo/trunk/server/main.cc    2010-05-17 20:04:25 UTC (rev 8686)
@@ -112,7 +112,7 @@
 #include "Global.hh"
 
 // Command line options
-const char *worldFileName;
+std::string worldFileName = "";
 const char *optLogFileName = NULL;
 unsigned int optServerId = 0;
 bool optServerForce = true;
@@ -225,14 +225,15 @@
   argc -= optind;
   argv += optind;
 
-  if (argc < 1)
+  /*if (argc < 1)
   {
     PrintUsage();
     return -1;
-  }
+  }*/
 
   // Get the world file name
-  worldFileName = argv[0];
+  if (argc > 1)
+    worldFileName = argv[0];
   return 0;
 }
 

Modified: code/gazebo/trunk/server/physics/ode/ODEPhysics.cc
===================================================================
--- code/gazebo/trunk/server/physics/ode/ODEPhysics.cc  2010-05-17 18:14:43 UTC 
(rev 8685)
+++ code/gazebo/trunk/server/physics/ode/ODEPhysics.cc  2010-05-17 20:04:25 UTC 
(rev 8686)
@@ -130,10 +130,11 @@
 // Load the ODE engine
 void ODEPhysics::Load(XMLConfigNode *node)
 {
-  XMLConfigNode *cnode = node->GetChild("ode", "physics");
-  if (cnode == NULL)
-    gzthrow("Must define a <physics:ode> node in the XML file");
+  XMLConfigNode *cnode = NULL;
 
+  if (node)
+    cnode = node->GetChild("ode", "physics");
+
   this->gravityP->Load(cnode);
   this->stepTimeP->Load(cnode);
   this->updateRateP->Load(cnode);

Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2010-05-17 18:14:43 UTC 
(rev 8685)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.cc   2010-05-17 20:04:25 UTC 
(rev 8686)
@@ -245,10 +245,6 @@
 /// Load the parameters for Ogre
 void OgreAdaptor::Load(XMLConfigNode *rootNode)
 {
-  XMLConfigNode *node;
-
-  node = rootNode->GetChild("ogre", "rendering");
-
   // Make the root
   try
   {
@@ -276,10 +272,11 @@
 // Initialize ogre
 void OgreAdaptor::Init(XMLConfigNode *rootNode)
 {
-  XMLConfigNode *node;
+  XMLConfigNode *node = NULL;
   Ogre::ColourValue ambient;
 
-  node = rootNode->GetChild("ogre", "rendering");
+  if (rootNode)
+    node = rootNode->GetChild("ogre", "rendering");
 
   /// Create a dummy rendering context.
   /// This will allow gazebo to run headless. And it also allows OGRE to 
@@ -314,7 +311,7 @@
   Ogre::TextureManager::getSingleton().setDefaultNumMipmaps( 5 );
 
   // Get the SceneManager, in this case a generic one
-  if (node->GetChild("bsp"))
+  if (node && node->GetChild("bsp"))
   {
     this->sceneType= SCENE_BSP;
     this->sceneMgr = this->root->createSceneManager("BspSceneManager");
@@ -383,14 +380,15 @@
 
 
   // Add a sky dome to our scene
-  if (node->GetChild("sky"))
+  if (node && node->GetChild("sky"))
   {
     this->skyMaterialP->Load(node->GetChild("sky"));
     OgreCreator::CreateSky(**(this->skyMaterialP));
   }
 
   // Add fog. This changes the background color
-  OgreCreator::CreateFog(node->GetChild("fog"));
+  if (node)
+    OgreCreator::CreateFog(node->GetChild("fog"));
 
   if (**(this->drawGridP))
     OgreCreator::DrawGrid();
@@ -398,7 +396,8 @@
   // Set up the world geometry link
   if (this->sceneType==SCENE_BSP)
   {
-    this->worldGeometry = node->GetString("bsp","",1);
+    if (node)
+      this->worldGeometry = node->GetString("bsp","",1);
 
     try
     {


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

------------------------------------------------------------------------------

_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to