Revision: 7392
http://playerstage.svn.sourceforge.net/playerstage/?rev=7392&view=rev
Author: robotos
Date: 2009-03-09 00:06:43 +0000 (Mon, 09 Mar 2009)
Log Message:
-----------
Save (filename), load(filename), close and exit implemented for the Simulation
interface
This should allow for batch mode processing of different simulations on the
same gazebo server
Modified Paths:
--------------
code/gazebo/trunk/libgazebo/SimIface.cc
code/gazebo/trunk/libgazebo/gazebo.h
code/gazebo/trunk/server/Simulator.cc
code/gazebo/trunk/server/World.cc
Modified: code/gazebo/trunk/libgazebo/SimIface.cc
===================================================================
--- code/gazebo/trunk/libgazebo/SimIface.cc 2009-03-08 08:46:29 UTC (rev
7391)
+++ code/gazebo/trunk/libgazebo/SimIface.cc 2009-03-09 00:06:43 UTC (rev
7392)
@@ -34,6 +34,48 @@
}
////////////////////////////////////////////////////////////////////////////////
+/// Save the simulation
+void SimulationIface::Save(const char* fileName)
+{
+ this->Lock(1);
+ SimulationRequestData *request =
&(this->data->requests[this->data->requestCount++]);
+ request->type = SimulationRequestData::SAVEFILENAME;
+ memcpy(request->fileName, fileName, 512);
+ this->Unlock();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Load the simulation
+void SimulationIface::Load(const char* fileName)
+{
+ this->Lock(1);
+ SimulationRequestData *request =
&(this->data->requests[this->data->requestCount++]);
+ request->type = SimulationRequestData::LOAD;
+ memcpy(request->fileName, fileName, 512);
+ this->Unlock();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Save the simulation
+void SimulationIface::Close()
+{
+ this->Lock(1);
+ SimulationRequestData *request =
&(this->data->requests[this->data->requestCount++]);
+ request->type = SimulationRequestData::CLOSE;
+ this->Unlock();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Save the simulation
+void SimulationIface::Exit()
+{
+ this->Lock(1);
+ SimulationRequestData *request =
&(this->data->requests[this->data->requestCount++]);
+ request->type = SimulationRequestData::EXIT;
+ this->Unlock();
+}
+
+////////////////////////////////////////////////////////////////////////////////
/// Get the 3d pose of a model
void SimulationIface::GetPose3d(const char *modelName)
{
Modified: code/gazebo/trunk/libgazebo/gazebo.h
===================================================================
--- code/gazebo/trunk/libgazebo/gazebo.h 2009-03-08 08:46:29 UTC (rev
7391)
+++ code/gazebo/trunk/libgazebo/gazebo.h 2009-03-09 00:06:43 UTC (rev
7392)
@@ -391,6 +391,10 @@
public: enum Type { PAUSE,
RESET,
SAVE,
+ SAVEFILENAME,
+ LOAD,
+ CLOSE,
+ EXIT,
GET_POSE3D,
GET_POSE2D,
SET_POSE3D,
@@ -399,6 +403,7 @@
};
public: Type type;
+ public: char fileName[512];
public: char modelName[512];
public: Pose modelPose;
public: Vec3 modelLinearVel;
@@ -467,9 +472,21 @@
/// \brief Reset the simulation
public: void Reset();
- /// \brief Save the simulation
+ /// \brief Save the simulation (automatic file)
public: void Save();
+ /// \brief Save the simulation (named file)
+ public: void Save(const char* fileName);
+
+ /// \brief Load the simulation
+ public: void Load(const char* fileName);
+
+ /// \brief Close current simulation (not exit)
+ public: void Close();
+
+ /// \brief Exit current simulation
+ public: void Exit();
+
/// \brief Get the 3d pose of a model
public: void GetPose3d(const char *modelName);
Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc 2009-03-08 08:46:29 UTC (rev
7391)
+++ code/gazebo/trunk/server/Simulator.cc 2009-03-09 00:06:43 UTC (rev
7392)
@@ -158,8 +158,6 @@
// Create the GUI
this->gui = new Gui(x, y, width, height, "Gazebo");
- Fl::check();
- Fl::wait(0.3);
this->gui->Load(childNode);
}
}
@@ -219,9 +217,28 @@
void Simulator::Save(const std::string& filename)
{
std::fstream output;
+ std::string real_filename;
- output.open(filename.c_str(), std::ios::out);
+ if (filename.empty())
+ {
+ int index = 0;
+ std::string name = "worldfile";
+ std::string random_name = "worldfile.world";
+
+ while (!std::ifstream(random_name.c_str()).is_open())
+ {
+ std::ostringstream os;
+ ++index;
+ os << index;
+ random_name = name + os.str() + ".world";
+ }
+ real_filename = random_name;
+ }
+ else
+ real_filename = filename;
+ output.open(real_filename.c_str(), std::ios::out);
+
// Write out the xml header
output << "<?xml version=\"1.0\"?>\n";
output << "<gazebo:world\n\
@@ -253,8 +270,11 @@
this->GetRenderEngine()->Save(prefix, output);
output << "\n";
- this->gui->Save(prefix, output);
- output << "\n";
+ if (this->gui) //TODO: running with -g and saving the world deletes the
gui part of the file?
+ {
+ this->gui->Save(prefix, output);
+ output << "\n";
+ }
World::Instance()->Save(prefix, output);
output << "\n";
Modified: code/gazebo/trunk/server/World.cc
===================================================================
--- code/gazebo/trunk/server/World.cc 2009-03-08 08:46:29 UTC (rev 7391)
+++ code/gazebo/trunk/server/World.cc 2009-03-09 00:06:43 UTC (rev 7392)
@@ -584,6 +584,18 @@
Simulator::Instance()->Save();
break;
+ case SimulationRequestData::SAVEFILENAME:
+ Simulator::Instance()->Save(req->fileName);
+ break;
+
+ case SimulationRequestData::CLOSE:
+ Simulator::Instance()->Close();
+ break;
+
+ case SimulationRequestData::EXIT:
+ Simulator::Instance()->SetUserQuit();
+ break;
+
case SimulationRequestData::SET_STATE:
{
Model *model = this->GetModelByName((char*)req->modelName);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit