Revision: 6965
http://playerstage.svn.sourceforge.net/playerstage/?rev=6965&view=rev
Author: natepak
Date: 2008-08-20 21:53:33 +0000 (Wed, 20 Aug 2008)
Log Message:
-----------
Added patch 2028314 by John Hsu
Modified Paths:
--------------
code/gazebo/trunk/libgazebo/Server.cc
code/gazebo/trunk/server/physics/BallJoint.cc
code/gazebo/trunk/server/physics/Hinge2Joint.cc
code/gazebo/trunk/server/physics/HingeJoint.cc
code/gazebo/trunk/server/physics/SliderJoint.cc
code/gazebo/trunk/server/physics/UniversalJoint.cc
code/gazebo/trunk/server/sensors/Sensor.cc
code/gazebo/trunk/server/sensors/Sensor.hh
code/gazebo/trunk/server/sensors/camera/MonoCameraSensor.cc
code/gazebo/trunk/server/sensors/camera/MonoCameraSensor.hh
code/gazebo/trunk/server/sensors/camera/StereoCameraSensor.cc
code/gazebo/trunk/server/sensors/camera/StereoCameraSensor.hh
code/gazebo/trunk/server/sensors/ray/RaySensor.cc
code/gazebo/trunk/server/sensors/ray/RaySensor.hh
Modified: code/gazebo/trunk/libgazebo/Server.cc
===================================================================
--- code/gazebo/trunk/libgazebo/Server.cc 2008-08-20 21:28:24 UTC (rev
6964)
+++ code/gazebo/trunk/libgazebo/Server.cc 2008-08-20 21:53:33 UTC (rev
6965)
@@ -95,36 +95,41 @@
// check to see if there is already a directory created.
struct stat astat;
- if (stat(this->filename.c_str(), &astat) == 0) {
+ if (stat(this->filename.c_str(), &astat) == 0)
+ {
// directory already exists, check gazebo.pid to see if
// another gazebo is already running.
std::string pidfn = this->filename + "/gazebo.pid";
-
+
FILE *fp = fopen(pidfn.c_str(), "r");
- if(fp) {
+ if(fp)
+ {
int pid;
fscanf(fp, "%d", &pid);
fclose(fp);
std::cout << "found a pid file: pid=" << pid << "\n";
- if(kill(pid, 0) == 0) {
- // a gazebo process is still alive.
- errStream << "directory [" << this->filename
- << "] already exists (previous crash?)\n"
- << "gazebo (pid=" << pid << ") is still running.";
- throw(errStream.str());
- } else {
- // the gazebo process is not alive.
- // remove directory.
- std::cout << "The gazebo process is not alive.\n";
+ if(kill(pid, 0) == 0)
+ {
+ // a gazebo process is still alive.
+ errStream << "directory [" << this->filename
+ << "] already exists (previous crash?)\n"
+ << "gazebo (pid=" << pid << ") is still running.";
+ throw(errStream.str());
+ }
+ else
+ {
+ // the gazebo process is not alive.
+ // remove directory.
+ std::cout << "The gazebo process is not alive.\n";
- // remove the existing directory.
- std::string cmd = "rm -rf '" + this->filename + "'";
- if(system(cmd.c_str()) != 0) {
- errStream << "couldn't remove directory [" << this->filename << "]";
- throw(errStream.str());
- }
+ // remove the existing directory.
+ std::string cmd = "rm -rf '" + this->filename + "'";
+ if(system(cmd.c_str()) != 0) {
+ errStream << "couldn't remove directory [" << this->filename << "]";
+ throw(errStream.str());
+ }
}
}
}
Modified: code/gazebo/trunk/server/physics/BallJoint.cc
===================================================================
--- code/gazebo/trunk/server/physics/BallJoint.cc 2008-08-20 21:28:24 UTC
(rev 6964)
+++ code/gazebo/trunk/server/physics/BallJoint.cc 2008-08-20 21:53:33 UTC
(rev 6965)
@@ -34,7 +34,7 @@
BallJoint::BallJoint(dWorldID worldId)
: Joint()
{
- this->type = BALL;
+ this->type = Joint::BALL;
this->jointId = dJointCreateBall(worldId, NULL);
}
Modified: code/gazebo/trunk/server/physics/Hinge2Joint.cc
===================================================================
--- code/gazebo/trunk/server/physics/Hinge2Joint.cc 2008-08-20 21:28:24 UTC
(rev 6964)
+++ code/gazebo/trunk/server/physics/Hinge2Joint.cc 2008-08-20 21:53:33 UTC
(rev 6965)
@@ -35,7 +35,7 @@
Hinge2Joint::Hinge2Joint( dWorldID worldId )
: Joint()
{
- this->type = HINGE2;
+ this->type = Joint::HINGE2;
this->jointId = dJointCreateHinge2( worldId, NULL );
this->axis1P = new Param<Vector3>("axis1",Vector3(0,0,1), 0);
Modified: code/gazebo/trunk/server/physics/HingeJoint.cc
===================================================================
--- code/gazebo/trunk/server/physics/HingeJoint.cc 2008-08-20 21:28:24 UTC
(rev 6964)
+++ code/gazebo/trunk/server/physics/HingeJoint.cc 2008-08-20 21:53:33 UTC
(rev 6965)
@@ -37,7 +37,7 @@
HingeJoint::HingeJoint( dWorldID worldId )
: Joint()
{
- this->type = HINGE;
+ this->type = Joint::HINGE;
this->jointId = dJointCreateHinge( worldId, NULL );
this->axisP = new Param<Vector3>("axis",Vector3(0,0,1), 0);
Modified: code/gazebo/trunk/server/physics/SliderJoint.cc
===================================================================
--- code/gazebo/trunk/server/physics/SliderJoint.cc 2008-08-20 21:28:24 UTC
(rev 6964)
+++ code/gazebo/trunk/server/physics/SliderJoint.cc 2008-08-20 21:53:33 UTC
(rev 6965)
@@ -34,7 +34,7 @@
SliderJoint::SliderJoint( dWorldID worldId )
: Joint()
{
- this->type = SLIDER;
+ this->type = Joint::SLIDER;
this->jointId = dJointCreateSlider( worldId, NULL );
this->axisP = new Param<Vector3>("axis",Vector3(0,0,1), 0);
Modified: code/gazebo/trunk/server/physics/UniversalJoint.cc
===================================================================
--- code/gazebo/trunk/server/physics/UniversalJoint.cc 2008-08-20 21:28:24 UTC
(rev 6964)
+++ code/gazebo/trunk/server/physics/UniversalJoint.cc 2008-08-20 21:53:33 UTC
(rev 6965)
@@ -36,7 +36,7 @@
UniversalJoint::UniversalJoint( dWorldID worldId )
: Joint()
{
- this->type = UNIVERSAL;
+ this->type = Joint::UNIVERSAL;
this->jointId = dJointCreateUniversal( worldId, NULL );
this->axis1P = new Param<Vector3>("axis1",Vector3(0,0,1),0);
Modified: code/gazebo/trunk/server/sensors/Sensor.cc
===================================================================
--- code/gazebo/trunk/server/sensors/Sensor.cc 2008-08-20 21:28:24 UTC (rev
6964)
+++ code/gazebo/trunk/server/sensors/Sensor.cc 2008-08-20 21:53:33 UTC (rev
6965)
@@ -31,6 +31,7 @@
#include "XMLConfig.hh"
#include "World.hh"
#include "ControllerFactory.hh"
+#include "Simulator.hh"
#include "Sensor.hh"
using namespace gazebo;
@@ -43,12 +44,15 @@
this->body = body;
this->controller = NULL;
this->active = true;
+
+ this->updateRateP = new Param<double>("updateRate", 0, 0);
}
////////////////////////////////////////////////////////////////////////////////
// Destructor
Sensor::~Sensor()
{
+ delete this->updateRateP;
}
////////////////////////////////////////////////////////////////////////////////
@@ -56,6 +60,13 @@
void Sensor::Load(XMLConfigNode *node)
{
this->nameP->Load(node);
+ this->updateRateP->Load(node);
+
+ if (**(this->updateRateP) == 0)
+ this->updatePeriod = 0.0;
+ else
+ this->updatePeriod = 1.0 / **(updateRateP);
+
this->LoadController( node->GetChildByNSPrefix("controller") );
this->LoadChild(node);
}
@@ -64,13 +75,26 @@
/// Save the sensor info in XML format
void Sensor::Save(std::string &prefix, std::ostream &stream)
{
-
+ std::string p = prefix + " ";
+
+ stream << prefix << "<sensor:" << this->typeName << " name=\"" <<
this->nameP->GetValue() << "\">\n";
+
+ stream << prefix << *(this->updateRateP) << "\n";
+
+ this->SaveChild(prefix, stream);
+
+ if (this->controller)
+ this->controller->Save(p, stream);
+
+ stream << prefix << "</sensor:" << this->typeName << ">\n";
}
////////////////////////////////////////////////////////////////////////////////
/// Initialize the sensor
void Sensor::Init()
{
+ this->lastUpdate = Simulator::Instance()->GetSimTime();
+
this->InitChild();
}
@@ -78,7 +102,12 @@
/// Update the sensor
void Sensor::Update()
{
- this->UpdateChild();
+ if (this->lastUpdate + this->updatePeriod <=
Simulator::Instance()->GetSimTime())
+ {
+ this->UpdateChild();
+ this->lastUpdate = Simulator::Instance()->GetSimTime();
+ }
+
if (this->controller)
this->controller->Update();
}
Modified: code/gazebo/trunk/server/sensors/Sensor.hh
===================================================================
--- code/gazebo/trunk/server/sensors/Sensor.hh 2008-08-20 21:28:24 UTC (rev
6964)
+++ code/gazebo/trunk/server/sensors/Sensor.hh 2008-08-20 21:53:33 UTC (rev
6965)
@@ -27,6 +27,7 @@
#ifndef SENSOR_HH
#define SENSOR_HH
+#include "Param.hh"
#include "Entity.hh"
namespace gazebo
@@ -53,7 +54,10 @@
public: virtual void Load(XMLConfigNode *node);
/// \brief Save the sensor info in XML format
- public: virtual void Save(std::string &prefix, std::ostream &stream);
+ public: void Save(std::string &prefix, std::ostream &stream);
+
+ /// \brief Child save function
+ protected: virtual void SaveChild(std::string &prefix,std::ostream
&stream) {}
/// \brief Initialize the sensor
public: void Init();
@@ -91,6 +95,11 @@
/// \brief True if active
protected: bool active;
+
+ protected: Param<double> *updateRateP;
+ protected: double updatePeriod;
+ protected: double lastUpdate;
+ protected: std::string typeName;
};
/// \}
Modified: code/gazebo/trunk/server/sensors/camera/MonoCameraSensor.cc
===================================================================
--- code/gazebo/trunk/server/sensors/camera/MonoCameraSensor.cc 2008-08-20
21:28:24 UTC (rev 6964)
+++ code/gazebo/trunk/server/sensors/camera/MonoCameraSensor.cc 2008-08-20
21:53:33 UTC (rev 6965)
@@ -50,6 +50,7 @@
MonoCameraSensor::MonoCameraSensor(Body *body)
: Sensor(body), OgreCamera("Mono")
{
+ this->typeName = "monocamera";
}
@@ -91,17 +92,10 @@
//////////////////////////////////////////////////////////////////////////////
/// Save the sensor info in XML format
-void MonoCameraSensor::Save(std::string &prefix, std::ostream &stream)
+void MonoCameraSensor::SaveChild(std::string &prefix, std::ostream &stream)
{
std::string p = prefix + " ";
- stream << prefix << "<sensor:monocamera name=\"" << this->nameP->GetValue()
<< "\">\n";
-
this->SaveCam(p, stream);
-
- if (this->controller)
- this->controller->Save(p, stream);
-
- stream << prefix << "</sensor:monocamera>\n";
}
//////////////////////////////////////////////////////////////////////////////
Modified: code/gazebo/trunk/server/sensors/camera/MonoCameraSensor.hh
===================================================================
--- code/gazebo/trunk/server/sensors/camera/MonoCameraSensor.hh 2008-08-20
21:28:24 UTC (rev 6964)
+++ code/gazebo/trunk/server/sensors/camera/MonoCameraSensor.hh 2008-08-20
21:53:33 UTC (rev 6965)
@@ -58,7 +58,7 @@
protected: virtual void LoadChild( XMLConfigNode *node );
/// \brief Save the sensor info in XML format
- public: virtual void Save(std::string &prefix, std::ostream &stream);
+ protected: virtual void SaveChild(std::string &prefix, std::ostream &stream);
/// \brief Initialize the camera
protected: virtual void InitChild();
Modified: code/gazebo/trunk/server/sensors/camera/StereoCameraSensor.cc
===================================================================
--- code/gazebo/trunk/server/sensors/camera/StereoCameraSensor.cc
2008-08-20 21:28:24 UTC (rev 6964)
+++ code/gazebo/trunk/server/sensors/camera/StereoCameraSensor.cc
2008-08-20 21:53:33 UTC (rev 6965)
@@ -59,6 +59,8 @@
this->depthBuffer[1] = NULL;
this->rgbBuffer[0] = NULL;
this->rgbBuffer[1] = NULL;
+
+ this->typeName = "stereocamera";
}
@@ -87,18 +89,10 @@
//////////////////////////////////////////////////////////////////////////////
/// Save the sensor info in XML format
-void StereoCameraSensor::Save(std::string &prefix, std::ostream &stream)
+void StereoCameraSensor::SaveChild(std::string &prefix, std::ostream &stream)
{
std::string p = prefix + " ";
-
- stream << prefix << "<sensor:stereocamera name=\"" <<
this->nameP->GetValue() << "\">\n";
-
this->SaveCam(p, stream);
-
- if (this->controller)
- this->controller->Save(p, stream);
-
- stream << prefix << "</sensor:stereocamera>\n";
}
//////////////////////////////////////////////////////////////////////////////
Modified: code/gazebo/trunk/server/sensors/camera/StereoCameraSensor.hh
===================================================================
--- code/gazebo/trunk/server/sensors/camera/StereoCameraSensor.hh
2008-08-20 21:28:24 UTC (rev 6964)
+++ code/gazebo/trunk/server/sensors/camera/StereoCameraSensor.hh
2008-08-20 21:53:33 UTC (rev 6965)
@@ -71,7 +71,7 @@
protected: virtual void LoadChild( XMLConfigNode *node );
/// \brief Save the sensor info in XML format
- public: void Save(std::string &prefix, std::ostream &stream);
+ protected: virtual void SaveChild(std::string &prefix, std::ostream
&stream);
/// \brief Initialize the camera
protected: virtual void InitChild();
Modified: code/gazebo/trunk/server/sensors/ray/RaySensor.cc
===================================================================
--- code/gazebo/trunk/server/sensors/ray/RaySensor.cc 2008-08-20 21:28:24 UTC
(rev 6964)
+++ code/gazebo/trunk/server/sensors/ray/RaySensor.cc 2008-08-20 21:53:33 UTC
(rev 6965)
@@ -53,6 +53,8 @@
{
this->active = false;
+ this->typeName = "ray";
+
this->rayCountP = new Param<int>("rayCount",0,1);
this->rangeCountP = new Param<int>("rangeCount",0,1);
this->minAngleP = new Param<Angle>("minAngle",DTOR(-90),1);
@@ -114,10 +116,8 @@
//////////////////////////////////////////////////////////////////////////////
/// Save the sensor info in XML format
-void RaySensor::Save(std::string &prefix, std::ostream &stream)
+void RaySensor::SaveChild(std::string &prefix, std::ostream &stream)
{
- std::string p = prefix + " ";
- stream << prefix << "<sensor:ray name=\"" << this->nameP->GetValue() <<
"\">\n";
stream << prefix << " " << *(this->minAngleP) << "\n";
stream << prefix << " " << *(this->maxAngleP) << "\n";
stream << prefix << " " << *(this->minRangeP) << "\n";
@@ -126,11 +126,6 @@
stream << prefix << " " << *(this->rayCountP) << "\n";
stream << prefix << " " << *(this->rangeCountP) << "\n";
stream << prefix << " " << *(this->displayRaysP) << "\n";
-
- if (this->controller)
- this->controller->Save(p, stream);
-
- stream << prefix << "</sensor:ray>\n";
}
//////////////////////////////////////////////////////////////////////////////
Modified: code/gazebo/trunk/server/sensors/ray/RaySensor.hh
===================================================================
--- code/gazebo/trunk/server/sensors/ray/RaySensor.hh 2008-08-20 21:28:24 UTC
(rev 6964)
+++ code/gazebo/trunk/server/sensors/ray/RaySensor.hh 2008-08-20 21:53:33 UTC
(rev 6965)
@@ -65,7 +65,7 @@
protected: virtual void LoadChild(XMLConfigNode *node);
/// \brief Save the sensor info in XML format
- public: void Save(std::string &prefix, std::ostream &stream);
+ protected: virtual void SaveChild(std::string &prefix, std::ostream &stream);
/// Initialize the ray
protected: virtual void InitChild();
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 Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit