Revision: 7923
http://playerstage.svn.sourceforge.net/playerstage/?rev=7923&view=rev
Author: natepak
Date: 2009-06-27 16:13:05 +0000 (Sat, 27 Jun 2009)
Log Message:
-----------
Fixed pause
Modified Paths:
--------------
code/gazebo/trunk/libgazebo/gazebo.h
code/gazebo/trunk/server/Simulator.cc
code/gazebo/trunk/server/Simulator.hh
code/gazebo/trunk/server/World.cc
code/gazebo/trunk/server/gui/StatusBar.cc
Modified: code/gazebo/trunk/libgazebo/gazebo.h
===================================================================
--- code/gazebo/trunk/libgazebo/gazebo.h 2009-06-27 11:40:25 UTC (rev
7922)
+++ code/gazebo/trunk/libgazebo/gazebo.h 2009-06-27 16:13:05 UTC (rev
7923)
@@ -428,15 +428,14 @@
SET_STATE,
GET_STATE,
GO,
- GET_MODEL_TYPE,
+ GET_MODEL_TYPE,
GET_NUM_MODELS,
GET_NUM_CHILDREN,
GET_CHILD_NAME,
GET_MODEL_NAME,
GET_MODEL_EXTENT,
- GET_MODEL_INTERFACES, // for getting interfaces as well
as the models which are ancestors of interfaces
- GET_INTERFACE_TYPE // if the model is not an interface
'unknown' is returned
-
+ GET_MODEL_INTERFACES, // for getting interfaces as well
as the models which are ancestors of interfaces
+ GET_INTERFACE_TYPE, // if the model is not an
interface 'unknown' is returned
};
public: Type type;
@@ -540,6 +539,9 @@
/// \brief Save the simulation
public: void Save();
+ /// \brief Run the specified amount of simulation time
+ public: void Run(double simTime);
+
/// \brief Get the 3d pose of a model
public: bool GetPose3d(const char *modelName, Pose &pose);
@@ -587,7 +589,6 @@
/// \brief Get the extents of a model
public: bool GetModelExtent(const char *modelName, Vec3 &ext);
-
public: void GoAckWait();
public: void GoAckPost();
Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc 2009-06-27 11:40:25 UTC (rev
7922)
+++ code/gazebo/trunk/server/Simulator.cc 2009-06-27 16:13:05 UTC (rev
7923)
@@ -66,8 +66,7 @@
physicsUpdates(0),
checkpoint(0.0),
renderUpdates(0),
- userPause(false),
- userStepInc(false),
+ stepInc(false),
userQuit(false),
guiEnabled(true),
renderEngineEnabled(true),
@@ -221,7 +220,6 @@
// Initialize the GUI
if (this->gui)
{
- printf("Init gui\n");
this->gui->Init();
}
@@ -409,6 +407,7 @@
/// Set whether the simulation is paused
void Simulator::SetPaused(bool p)
{
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
this->pause = p;
}
@@ -457,30 +456,19 @@
}
////////////////////////////////////////////////////////////////////////////////
-bool Simulator::GetUserPause() const
+bool Simulator::GetStepInc() const
{
- return this->userPause;
+ return this->stepInc;
}
////////////////////////////////////////////////////////////////////////////////
-void Simulator::SetUserPause(bool pause)
+void Simulator::SetStepInc(bool step)
{
- this->userPause = pause;
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+ this->stepInc = step;
}
////////////////////////////////////////////////////////////////////////////////
-bool Simulator::GetUserStepInc() const
-{
- return this->userStepInc;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-void Simulator::SetUserStepInc(bool step)
-{
- this->userStepInc = step;
-}
-
-////////////////////////////////////////////////////////////////////////////////
// True if the gui is to be used
void Simulator::SetGuiEnabled( bool enabled )
{
@@ -614,7 +602,8 @@
double step = world->GetPhysicsEngine()->GetStepTime();
double physicsUpdateRate = world->GetPhysicsEngine()->GetUpdateRate();
double physicsUpdatePeriod = 1.0 / physicsUpdateRate;
-
+
+ bool userStepped;
double diffTime;
double currTime;
double lastTime = this->GetRealTime();
@@ -628,62 +617,62 @@
currTime = this->GetRealTime();
- //if (physicsUpdateRate == 0 ||
- //currTime - lastTime >= physicsUpdatePeriod)
+ userStepped = false;
+
+ // Update the physics engine
+ //if (!this->GetUserPause() && !this->IsPaused() ||
+ // (this->GetUserPause() && this->GetUserStepInc()))
+ if (!this->IsPaused() || this->GetStepInc())
{
+ this->simTime += step;
+ this->SetPaused(false);
- // Update the physics engine
- //if (!this->GetUserPause() && !this->IsPaused() ||
- // (this->GetUserPause() && this->GetUserStepInc()))
- if (!this->IsPaused())
- {
- this->simTime += step;
- this->SetUserStepInc(!this->GetUserStepInc());
- }
- else
- {
- this->pauseTime += step;
+ if (this->GetStepInc())
+ userStepped = true;
+ }
+ else
+ {
+ this->pauseTime += step;
// this->pause=true;
- }
+ }
- lastTime = this->GetRealTime();
+ lastTime = this->GetRealTime();
- {
- boost::recursive_mutex::scoped_lock lock(*this->mutex);
- world->Update();
- }
+ {
+ boost::recursive_mutex::scoped_lock lock(*this->mutex);
+ world->Update();
+ }
- currTime = this->GetRealTime();
+ currTime = this->GetRealTime();
- // Set a default sleep time
- req.tv_sec = 0;
- req.tv_nsec = 10000;
+ // Set a default sleep time
+ req.tv_sec = 0;
+ req.tv_nsec = 10000;
- // If the physicsUpdateRate < 0, then we should try to match the
- // update rate to real time
- if ( physicsUpdateRate < 0 &&
- (this->GetSimTime() + this->GetPauseTime()) >
- this->GetRealTime())
- {
- diffTime = (this->GetSimTime() + this->GetPauseTime()) -
- this->GetRealTime();
- req.tv_sec = (int) floor(diffTime);
- req.tv_nsec = (int) (fmod(diffTime, 1.0) * 1e9);
- }
- // Otherwise try to match the update rate to the one specified in
- // the xml file
- else if (physicsUpdateRate > 0 &&
- currTime - lastTime < physicsUpdatePeriod)
- {
- diffTime = physicsUpdatePeriod - (currTime - lastTime);
+ // If the physicsUpdateRate < 0, then we should try to match the
+ // update rate to real time
+ if ( physicsUpdateRate < 0 &&
+ (this->GetSimTime() + this->GetPauseTime()) >
+ this->GetRealTime())
+ {
+ diffTime = (this->GetSimTime() + this->GetPauseTime()) -
+ this->GetRealTime();
+ req.tv_sec = (int) floor(diffTime);
+ req.tv_nsec = (int) (fmod(diffTime, 1.0) * 1e9);
+ }
+ // Otherwise try to match the update rate to the one specified in
+ // the xml file
+ else if (physicsUpdateRate > 0 &&
+ currTime - lastTime < physicsUpdatePeriod)
+ {
+ diffTime = physicsUpdatePeriod - (currTime - lastTime);
- req.tv_sec = (int) floor(diffTime);
- req.tv_nsec = (int) (fmod(diffTime, 1.0) * 1e9);
- }
-
- nanosleep(&req, &rem);
+ req.tv_sec = (int) floor(diffTime);
+ req.tv_nsec = (int) (fmod(diffTime, 1.0) * 1e9);
}
+ nanosleep(&req, &rem);
+
// Process all incoming messages from simiface
world->ProcessMessages();
@@ -693,10 +682,16 @@
break;
}
+ if (userStepped)
+ {
+ this->SetStepInc(false);
+ this->SetPaused(true);
+ }
+
#ifdef TIMING
double tmpT2 = this->GetWallTime();
std::cout << " Simulator::PhysicsLoop() DT(" << tmpT2-tmpT1
- << ")" << std::endl;
+ << ")" << std::endl;
#endif
}
}
Modified: code/gazebo/trunk/server/Simulator.hh
===================================================================
--- code/gazebo/trunk/server/Simulator.hh 2009-06-27 11:40:25 UTC (rev
7922)
+++ code/gazebo/trunk/server/Simulator.hh 2009-06-27 16:13:05 UTC (rev
7923)
@@ -121,17 +121,11 @@
/// \brief Simulator finished by the user
public: void SetUserQuit();
- /// \brief Return true if the user has pased
- public: bool GetUserPause() const;
-
- /// \brief Set whether the user has paused
- public: void SetUserPause(bool pause);
-
/// \brief Return true if the step has incremented
- public: bool GetUserStepInc() const;
+ public: bool GetStepInc() const;
/// \brief Set whether the step has incremented
- public: void SetUserStepInc(bool step);
+ public: void SetStepInc(bool step);
/// \brief True if the gui is to be used
public: void SetGuiEnabled( bool enabled );
@@ -204,13 +198,9 @@
// render updates
private: int renderUpdates;
- // UserIteractions
- /// \brief Set to true to pause the simulation
- private: bool userPause;
-
/// Set to true to increment the simulation once. This is only
/// valid when paused.
- private: bool userStepInc;
+ private: bool stepInc;
//The user has somewhat signaled the end of the program
private: bool userQuit;
Modified: code/gazebo/trunk/server/World.cc
===================================================================
--- code/gazebo/trunk/server/World.cc 2009-06-27 11:40:25 UTC (rev 7922)
+++ code/gazebo/trunk/server/World.cc 2009-06-27 16:13:05 UTC (rev 7923)
@@ -669,7 +669,7 @@
this->simIface->data->simTime = Simulator::Instance()->GetSimTime();
this->simIface->data->pauseTime = Simulator::Instance()->GetPauseTime();
this->simIface->data->realTime = Simulator::Instance()->GetRealTime();
- this->simIface->data->state = !Simulator::Instance()->GetUserPause();
+ this->simIface->data->state = !Simulator::Instance()->IsPaused();
unsigned int requestCount = this->simIface->data->requestCount;
@@ -688,13 +688,12 @@
switch (req->type)
{
-
case SimulationRequestData::UNPAUSE:
- Simulator::Instance()->SetUserPause(false);
+ Simulator::Instance()->SetPaused(false);
break;
case SimulationRequestData::PAUSE:
- Simulator::Instance()->SetUserPause(
- !Simulator::Instance()->GetUserPause());
+ Simulator::Instance()->SetPaused(
+ !Simulator::Instance()->IsPaused());
break;
case SimulationRequestData::RESET:
Modified: code/gazebo/trunk/server/gui/StatusBar.cc
===================================================================
--- code/gazebo/trunk/server/gui/StatusBar.cc 2009-06-27 11:40:25 UTC (rev
7922)
+++ code/gazebo/trunk/server/gui/StatusBar.cc 2009-06-27 16:13:05 UTC (rev
7923)
@@ -188,6 +188,18 @@
this->lastUpdateTime = Simulator::Instance()->GetRealTime();
}
+
+ if (Simulator::Instance()->IsPaused())
+ {
+ this->playButton->label("@>");
+ this->stepButton->activate();
+ }
+ else
+ {
+ this->playButton->label("@||");
+ this->stepButton->deactivate();
+ }
+
}
////////////////////////////////////////////////////////////////////////////////
@@ -198,14 +210,14 @@
if (strcmp(w->label(), "@||") == 0)
{
- Simulator::Instance()->SetUserPause(true);
+ Simulator::Instance()->SetPaused(true);
sb->stepButton->activate();
w->label("@>");
}
else
{
- Simulator::Instance()->SetUserPause(false);
+ Simulator::Instance()->SetPaused(false);
sb->stepButton->deactivate();
w->label("@||");
}
@@ -217,5 +229,5 @@
/// Set button callback
void StatusBar::StepButtonCB( Fl_Widget * /*w*/, void * /*data*/ )
{
- Simulator::Instance()->SetUserStepInc( true );
+ Simulator::Instance()->SetStepInc( true );
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit