Revision: 6411
http://playerstage.svn.sourceforge.net/playerstage/?rev=6411&view=rev
Author: robotos
Date: 2008-05-09 23:58:37 -0700 (Fri, 09 May 2008)
Log Message:
-----------
Solved a weird error when loading ogre plugins
Added updateRate tag to rendering and physics.
This tag sets a upper limit on the updates.
Modified Paths:
--------------
code/gazebo/trunk/server/GazeboConfig.cc
code/gazebo/trunk/server/GazeboConfig.hh
code/gazebo/trunk/server/Simulator.cc
code/gazebo/trunk/server/physics/PhysicsEngine.cc
code/gazebo/trunk/server/physics/PhysicsEngine.hh
code/gazebo/trunk/server/physics/ode/ODEPhysics.cc
code/gazebo/trunk/server/rendering/OgreAdaptor.cc
code/gazebo/trunk/server/rendering/OgreAdaptor.hh
Modified: code/gazebo/trunk/server/GazeboConfig.cc
===================================================================
--- code/gazebo/trunk/server/GazeboConfig.cc 2008-05-10 06:29:12 UTC (rev
6410)
+++ code/gazebo/trunk/server/GazeboConfig.cc 2008-05-10 06:58:37 UTC (rev
6411)
@@ -29,6 +29,7 @@
#include "XMLConfig.hh"
#include "GazeboConfig.hh"
+#include "GazeboMessage.hh"
using namespace gazebo;
@@ -64,7 +65,7 @@
node = rc.GetRootNode()->GetChild("gazeboPath");
while (node)
{
- std::cout << "Gazebo Path[" << node->GetValue() << "]\n";
+ gzmsg(1) << "Gazebo Path[" << node->GetValue() << "]\n";
this->gazeboPaths.push_back(node->GetValue());
node = node->GetNext("gazeboPath");
}
@@ -72,7 +73,7 @@
node = rc.GetRootNode()->GetChild("ogrePath");
while (node)
{
- std::cout << "Ogre Path[" << node->GetValue() << "]\n";
+ gzmsg(1) << "Ogre Path[" << node->GetValue() << "]\n";
this->ogrePaths.push_back( node->GetValue() );
node = node->GetNext("ogrePath");
}
@@ -81,7 +82,7 @@
}
else
{
- std::cout << "Unable to find the file ~/.gazeborc. Using default paths.
This may cause OGRE to fail.\n";
+ gzmsg(0) << "Unable to find the file ~/.gazeborc. Using default paths.
This may cause OGRE to fail.\n";
this->gazeboPaths.push_back("/usr/local/share/gazebo");
this->ogrePaths.push_back("/usr/local/lib/OGRE");
this->ogrePaths.push_back("/usr/lib/OGRE");
@@ -89,17 +90,17 @@
}
}
-std::list<std::string> GazeboConfig::GetGazeboPaths() const
+std::list<std::string> &GazeboConfig::GetGazeboPaths()
{
return this->gazeboPaths;
}
-std::list<std::string> GazeboConfig::GetOgrePaths() const
+std::list<std::string> &GazeboConfig::GetOgrePaths()
{
return this->ogrePaths;
}
-std::string GazeboConfig::GetRTTMode() const
+std::string &GazeboConfig::GetRTTMode()
{
return this->RTTMode;
}
Modified: code/gazebo/trunk/server/GazeboConfig.hh
===================================================================
--- code/gazebo/trunk/server/GazeboConfig.hh 2008-05-10 06:29:12 UTC (rev
6410)
+++ code/gazebo/trunk/server/GazeboConfig.hh 2008-05-10 06:58:37 UTC (rev
6411)
@@ -48,12 +48,12 @@
public: void Load();
/// \brief Get paths to Gazebo install
- public: std::list<std::string> GetGazeboPaths() const;
+ public: std::list<std::string>& GetGazeboPaths();
/// \brief Get paths to ogre install
- public: std::list<std::string> GetOgrePaths() const;
+ public: std::list<std::string>& GetOgrePaths();
- public: std::string GetRTTMode() const;
+ public: std::string& GetRTTMode();
/// Paths gazebo install
private: std::list<std::string> gazeboPaths;
Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc 2008-05-10 06:29:12 UTC (rev
6410)
+++ code/gazebo/trunk/server/Simulator.cc 2008-05-10 06:58:37 UTC (rev
6411)
@@ -68,6 +68,8 @@
this->xmlFile=NULL;
this->gazeboConfig=NULL;
+ this->prevPhysicsTime=0.0;
+ this->prevRenderTime=0.0;
}
////////////////////////////////////////////////////////////////////////////////
@@ -102,37 +104,35 @@
loaded=false;
}
- // load the configuration options
- this->gazeboConfig=new gazebo::GazeboConfig();
+ // Load the world file
+ this->xmlFile=new gazebo::XMLConfig();
try
{
- this->gazeboConfig->Load();
+ this->xmlFile->Load(worldFileName);
}
catch (GazeboError e)
{
- gzthrow("Error loading the Gazebo configuration file, check the .gazeborc
file on your HOME directory \n" << e);
+ gzthrow("The XML config file can not be loaded, please make sure is a
correct file\n" << e);
}
+ XMLConfigNode *rootNode(xmlFile->GetRootNode());
+ // Load the messaging system
+ gazebo::GazeboMessage::Instance()->Load(rootNode);
- // Load the world file
- this->xmlFile=new gazebo::XMLConfig();
+ // load the configuration options
+ this->gazeboConfig=new gazebo::GazeboConfig();
try
{
- this->xmlFile->Load(worldFileName);
+ this->gazeboConfig->Load();
}
catch (GazeboError e)
{
- gzthrow("The XML config file can not be loaded, please make sure is a
correct file\n" << e);
+ gzthrow("Error loading the Gazebo configuration file, check the .gazeborc
file on your HOME directory \n" << e);
}
- XMLConfigNode *rootNode(xmlFile->GetRootNode());
-
- // Load the messaging system
- gazebo::GazeboMessage::Instance()->Load(rootNode);
-
+ //Create and initialize the Gui
try
{
- //Create and initialize the Gui
this->LoadGui(rootNode);
}
catch (GazeboError e)
@@ -140,7 +140,7 @@
gzthrow( "Error loading the GUI\n" << e);
}
- //Initialize RenderingEngine
+ //Initialize RenderingEngine
try
{
gazebo::OgreAdaptor::Instance()->Init(rootNode);
@@ -150,12 +150,12 @@
gzthrow("Failed to Initialize the OGRE Rendering system\n" << e );
}
- //Preload basic shapes that can be used anywhere
+ //Preload basic shapes that can be used anywhere
OgreCreator::CreateBasicShapes();
+ //Create the world
try
{
- //Create the world
gazebo::World::Instance()->Load(rootNode, serverId);
}
catch (GazeboError e)
@@ -209,22 +209,35 @@
/// Main simulation loop, when this loop ends the simulation finish
void Simulator::MainLoop()
{
- double step= World::Instance()->GetPhysicsEngine()->GetStepTime();
- double currTime;
- double elapsedTime;
+ double maxPhysicsUpdateRate =
World::Instance()->GetPhysicsEngine()->GetUpdateRate();
+ double maxRenderUpdateRate = OgreAdaptor::Instance()->GetUpdateRate();
+ double step = World::Instance()->GetPhysicsEngine()->GetStepTime();
+
+ if (maxPhysicsUpdateRate == 0)
+ gzmsg(2) << "updating the physics at full speed";
+ else
+ gzmsg(2) << "updating the physics " << 1/maxPhysicsUpdateRate << "
times/seconds";
+ if (maxRenderUpdateRate == 0)
+ gzmsg(2) << "updating the visualization at full speed";
+ else
+ gzmsg(2) << "updating the visualization " << 1/maxRenderUpdateRate << "
times/seconds";
+ std::cout.flush();
+
while (!this->userQuit)
- {
- currTime = this->GetRealTime();
+ {
+ bool updated=false;
- if ((currTime - this->prevPhysicsTime) >= step)
+ // Update the physics engine
+ double currentPhysicsTime = this->GetRealTime();
+
+ if ((currentPhysicsTime - this->prevPhysicsTime) >= maxPhysicsUpdateRate)
{
- this->simTime += step;
- // Update the physics engine
if (!this->GetUserPause() && !this->GetUserStep() ||
(this->GetUserStep() && this->GetUserStepInc()))
{
+ this->simTime += step;
this->iterations++;
this->pause=false;
this->SetUserStepInc(!this->GetUserStepInc());
@@ -237,25 +250,31 @@
World::Instance()->Update(); //physics
- this->prevPhysicsTime = this->GetRealTime();
+ this->prevPhysicsTime = currentPhysicsTime;
+ updated=true;
}
- // Update the rendering
- if (currTime - this->prevRenderTime > 0.02)
+ // Update the rendering and gui
+ double currentRenderTime = this->GetRealTime();
+
+ if ((currentRenderTime - this->prevRenderTime) >= maxRenderUpdateRate)
{
gazebo::OgreAdaptor::Instance()->Render();
- this->prevRenderTime = this->GetRealTime();
+ this->prevRenderTime = currentRenderTime;
+ this->gui->Update();
+ this->prevRenderTime = currentRenderTime;
+ updated=true;
}
- // Update the gui
- this->gui->Update();
-
- elapsedTime = (this->GetRealTime()-currTime)*2.0;
-
- // Wait if we're going too fast
- if ( elapsedTime < 0.02 )
+ if (!updated)
{
- usleep( (0.02 - elapsedTime) * 1e6 );
+ double nextUpdate;
+ nextUpdate=MAX(this->prevRenderTime+maxRenderUpdateRate,
this->prevPhysicsTime+maxPhysicsUpdateRate);
+ int realStep = static_cast<int>(this->GetRealTime() - nextUpdate);
+ struct timespec waiting;
+ waiting.tv_sec=0;
+ waiting.tv_nsec=realStep *1000000; //TODO: binary
+ nanosleep(&waiting,0);
}
}
}
Modified: code/gazebo/trunk/server/physics/PhysicsEngine.cc
===================================================================
--- code/gazebo/trunk/server/physics/PhysicsEngine.cc 2008-05-10 06:29:12 UTC
(rev 6410)
+++ code/gazebo/trunk/server/physics/PhysicsEngine.cc 2008-05-10 06:58:37 UTC
(rev 6411)
@@ -49,6 +49,13 @@
////////////////////////////////////////////////////////////////////////////////
/// Get the time between each update cycle
+double PhysicsEngine::GetUpdateRate() const
+{
+ return this->updateRate;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the time between each update cycle
double PhysicsEngine::GetStepTime() const
{
return this->stepTime;
Modified: code/gazebo/trunk/server/physics/PhysicsEngine.hh
===================================================================
--- code/gazebo/trunk/server/physics/PhysicsEngine.hh 2008-05-10 06:29:12 UTC
(rev 6410)
+++ code/gazebo/trunk/server/physics/PhysicsEngine.hh 2008-05-10 06:58:37 UTC
(rev 6411)
@@ -109,14 +109,23 @@
public: Vector3 GetGravity() const;
/// \brief Get the time between each update cycle
- /// \return Time in seconds
+ /// \return seconds between updates
+ public: double GetUpdateRate() const;
+
+ /// \brief Get the physics time steps in the virtual world
+ /// \return step time
public: double GetStepTime() const;
/// The gravity vector
protected: Vector3 gravity;
- /// Time between each update cycle
+ /// time steps the physical engine will take
+ /// how much time will pass on each update
protected: double stepTime;
+
+ /// update rate of the physical engine, how many times
+ /// it is called
+ protected: double updateRate;
};
/** \}*/
Modified: code/gazebo/trunk/server/physics/ode/ODEPhysics.cc
===================================================================
--- code/gazebo/trunk/server/physics/ode/ODEPhysics.cc 2008-05-10 06:29:12 UTC
(rev 6410)
+++ code/gazebo/trunk/server/physics/ode/ODEPhysics.cc 2008-05-10 06:58:37 UTC
(rev 6411)
@@ -72,6 +72,7 @@
this->gravity.z = -9.80665;
this->stepTime = 0.05;
+ this->updateRate = 0.0;
}
////////////////////////////////////////////////////////////////////////////////
@@ -98,6 +99,11 @@
this->gravity = cnode->GetVector3("gravity",this->gravity);
this->stepTime = cnode->GetDouble("stepTime",this->stepTime);
+ int maxUpdatesSecond = cnode->GetInt("updateRate",0);
+ if (maxUpdatesSecond == 0)
+ this->updateRate = 0.0;
+ else
+ this->updateRate = 1.0/maxUpdatesSecond;
this->globalCFM = cnode->GetDouble("cfm",1e-5,0);
this->globalERP = cnode->GetDouble("erp",0.2,0);
}
Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.cc 2008-05-10 06:29:12 UTC
(rev 6410)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.cc 2008-05-10 06:58:37 UTC
(rev 6411)
@@ -124,6 +124,12 @@
{
gzthrow( "missing OGRE Rendering information" );
}
+
+ int maxFPS = node->GetInt("updateRate", 0);
+ if (maxFPS == 0)
+ this->updateRate=0;
+ else
+ this->updateRate = 1.0/maxFPS;
ambient.r = node->GetTupleDouble("ambient",0,1.0);
ambient.g = node->GetTupleDouble("ambient",1,1.0);
@@ -238,8 +244,8 @@
}
catch (Ogre::Exception e)
{
- gzmsg(0) << "Unable to load BSP geometry." << e.getDescription() << "\n";
- exit(0);
+ gzmsg(-1) << "Unable to load BSP geometry." << e.getDescription() <<
"\n";
+ exit(-1);
}
}
@@ -296,17 +302,15 @@
// Load plugins
void OgreAdaptor::LoadPlugins()
{
- std::string pathStr;
- std::string pluginStr;
- XMLConfigNode *pluginNode;
std::list<std::string>::iterator iter;
+ std::list<std::string>
ogrePaths=Simulator::Instance()->GetGazeboConfig()->GetOgrePaths();
-
- for (iter=Simulator::Instance()->GetGazeboConfig()->GetOgrePaths().begin();
- iter!=Simulator::Instance()->GetGazeboConfig()->GetOgrePaths().end();
iter++)
+ for (iter=ogrePaths.begin();
+ iter!=ogrePaths.end(); ++iter)
{
- DIR *dir;
- if ((dir=opendir((*iter).c_str())) == NULL)
+ std::string path(*iter);
+ DIR *dir=opendir(path.c_str());
+ if (dir == NULL)
{
continue;
}
@@ -315,10 +319,10 @@
std::vector<std::string> plugins;
std::vector<std::string>::iterator piter;
- plugins.push_back((*iter)+"/RenderSystem_GL.so");
- plugins.push_back((*iter)+"/Plugin_ParticleFX.so");
- plugins.push_back((*iter)+"/Plugin_BSPSceneManager.so");
- plugins.push_back((*iter)+"/Plugin_OctreeSceneManager.so");
+ plugins.push_back(path+"/RenderSystem_GL.so");
+ plugins.push_back(path+"/Plugin_ParticleFX.so");
+ plugins.push_back(path+"/Plugin_BSPSceneManager.so");
+ plugins.push_back(path+"/Plugin_OctreeSceneManager.so");
for (piter=plugins.begin(); piter!=plugins.end(); piter++)
{
@@ -326,10 +330,14 @@
{
// Load the plugin into OGRE
this->root->loadPlugin(*piter);
+ //gzmsg(2) << "Loaded plugin:" << (*piter);
}
catch (Ogre::Exception e)
{
- gzthrow("Unable to load Ogre Plugins.\nMake sure the plugins path in
the world file is set correctly");
+ std::string description("Unable to load Ogre Plugins on directory ");
+ description.append(path);
+ description.append("\n Make sure the plugins path in the gazebo
configuration file are set correctly.\n");
+ gzthrow( description + e.getDescription() );
}
}
}
@@ -487,3 +495,8 @@
return 0;
}
+double OgreAdaptor::GetUpdateRate() const
+{
+ return this->updateRate;
+}
+
Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.hh
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.hh 2008-05-10 06:29:12 UTC
(rev 6410)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.hh 2008-05-10 06:58:37 UTC
(rev 6411)
@@ -88,6 +88,9 @@
/// \brief Render a single frame
public: int Render();
+ /// \brief Gets the minimum time between renders, set by in the file to
limit Framerate
+ public: double GetUpdateRate() const;
+
/// \brief Resize the rendering window
public: void ResizeWindow(unsigned int w, unsigned int h);
@@ -117,6 +120,8 @@
/// Pointer to the input reader
public: Ogre::InputReader *inputDevice;
+ private: double updateRate;
+
private: Ogre::LogManager *logManager;
// Our custom frame listener
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit