Revision: 7920
http://playerstage.svn.sourceforge.net/playerstage/?rev=7920&view=rev
Author: natepak
Date: 2009-06-27 02:15:31 +0000 (Sat, 27 Jun 2009)
Log Message:
-----------
Added a default factory to the world
Modified Paths:
--------------
code/gazebo/trunk/server/CMakeLists.txt
code/gazebo/trunk/server/World.cc
code/gazebo/trunk/server/World.hh
code/gazebo/trunk/server/controllers/CMakeLists.txt
code/gazebo/trunk/webgazebo/WebGazebo.cc
Added Paths:
-----------
code/gazebo/trunk/server/Factory.cc
code/gazebo/trunk/server/Factory.hh
Removed Paths:
-------------
code/gazebo/trunk/worlds/factory.world
Modified: code/gazebo/trunk/server/CMakeLists.txt
===================================================================
--- code/gazebo/trunk/server/CMakeLists.txt 2009-06-27 01:46:18 UTC (rev
7919)
+++ code/gazebo/trunk/server/CMakeLists.txt 2009-06-27 02:15:31 UTC (rev
7920)
@@ -64,6 +64,7 @@
GuiAPI.cc
Simulator.cc
Rand.cc
+ Factory.cc
)
SET (headers Common.hh
@@ -89,6 +90,7 @@
GuiAPI.hh
Simulator.hh
Rand.hh
+ Factory.hh
)
APPEND_TO_SERVER_HEADERS(${headers})
Added: code/gazebo/trunk/server/Factory.cc
===================================================================
--- code/gazebo/trunk/server/Factory.cc (rev 0)
+++ code/gazebo/trunk/server/Factory.cc 2009-06-27 02:15:31 UTC (rev 7920)
@@ -0,0 +1,115 @@
+/*
+ * Gazebo - Outdoor Multi-Robot Simulator
+ * Copyright (C) 2003
+ * Nate Koenig & Andrew Howard
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+/*
+ * Desc: Factory Position2d controller.
+ * Author: Nathan Koenig
+ * Date: 01 Feb 2007
+ * SVN info: $Id: Factory.cc 7748 2009-05-30 09:46:23Z robotos $
+ */
+
+#include "Global.hh"
+#include "XMLConfig.hh"
+#include "Model.hh"
+#include "World.hh"
+#include "gazebo.h"
+#include "GazeboError.hh"
+#include "gazebo.h"
+#include "Factory.hh"
+
+using namespace gazebo;
+
+////////////////////////////////////////////////////////////////////////////////
+// Constructor
+Factory::Factory()
+{
+ // Prefix and suffix for xml files
+ this->xmlPrefix = "<?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'
>";
+
+
+ this->xmlSuffix = "</gazebo:world>";
+
+ this->factoryIface = (FactoryIface*)IfaceFactory::NewIface("factory");
+
+ // Create the iface
+ try
+ {
+ this->factoryIface->Create(World::Instance()->GetGzServer(), "default");
+ }
+ catch (std::string e)
+ {
+ gzthrow(e);
+ }
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Destructor
+Factory::~Factory()
+{
+ delete this->factoryIface;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Initialize the controller
+void Factory::Init()
+{
+ // initialize newModel to blank
+ strcpy((char*)this->factoryIface->data->newModel,"");
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Update the controller
+void Factory::Update()
+{
+ // If there is a string, then add the contents to the world
+ this->factoryIface->Lock(1);
+
+ if (strcmp((const char*)this->factoryIface->data->newModel,"")!=0)
+ {
+ //std::cout << " factory update: " << this->factoryIface->data->newModel
<< std::endl;
+ std::string xmlString;
+ std::string xmlMiddle = (const char*)(this->factoryIface->data->newModel);
+
+ // Strip leading <?xml...?> tag, if present, to allow the client to
+ // pass the contents of a valid .model file
+ std::string xmlVersion = "<?xml version=\"1.0\"?>";
+ int i = xmlMiddle.find(xmlVersion);
+ if(i >= 0)
+ xmlMiddle.replace(i, xmlVersion.length(), "");
+
+ xmlString = this->xmlPrefix + xmlMiddle + this->xmlSuffix;
+
+ // Add the new models into the World
+ World::Instance()->InsertEntity( xmlString);
+
+ strcpy((char*)this->factoryIface->data->newModel,"");
+ }
+
+ // Attempt to delete a model by name, if the string is present
+ /*if (strcmp((const char*)this->factoryIface->data->deleteModel,"")!=0)
+ {
+ World::Instance()->DeleteEntity((const
char*)this->factoryIface->data->deleteModel);
+
+ strcpy((char*)this->factoryIface->data->deleteModel,"");
+ }*/
+ this->factoryIface->Unlock();
+
+}
Added: code/gazebo/trunk/server/Factory.hh
===================================================================
--- code/gazebo/trunk/server/Factory.hh (rev 0)
+++ code/gazebo/trunk/server/Factory.hh 2009-06-27 02:15:31 UTC (rev 7920)
@@ -0,0 +1,79 @@
+/*
+ * Gazebo - Outdoor Multi-Robot Simulator
+ * Copyright (C) 2003
+ * Nate Koenig & Andrew Howard
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+/*
+ * Desc: Factory controller.
+ * Author: Nathan Koenig
+ * Date: 29 July 2007
+ * SVN: $Id: Factory.hh 7551 2009-03-27 16:15:13Z natepak $
+ */
+#ifndef FACTORY_HH
+#define FACTORY_HH
+
+#include "Controller.hh"
+#include "Entity.hh"
+#include "gazebo.h"
+
+
+namespace gazebo
+{
+ class FactoryIface;
+
+/// \addtogroup gazebo_server
+/// \{
+/** \defgroup factory factory
+ \brief Factory used for dynamic construction of models
+
+ The factory controller allows dynamic addition and deletion of models using
libgazebo's \ref factory_iface interface.
+
+\{
+*/
+
+/// \brief Factory used for dynamic construction of models
+class Factory
+{
+ /// Constructor
+ public: Factory();
+
+ /// Destructor
+ public: virtual ~Factory();
+
+ /// Init the controller
+ /// \return 0 on success
+ public: void Init();
+
+ /// Update the controller
+ /// \return 0 on success
+ public: void Update();
+
+ /// The Position interface
+ private: FactoryIface *factoryIface;
+
+ private: std::string xmlPrefix;
+ private: std::string xmlSuffix;
+};
+
+/** \} */
+/// \}
+
+}
+
+#endif
+
Modified: code/gazebo/trunk/server/World.cc
===================================================================
--- code/gazebo/trunk/server/World.cc 2009-06-27 01:46:18 UTC (rev 7919)
+++ code/gazebo/trunk/server/World.cc 2009-06-27 02:15:31 UTC (rev 7920)
@@ -29,6 +29,7 @@
#include <fstream>
#include <sys/time.h> //gettimeofday
+#include "Factory.hh"
#include "GraphicsIfaceHandler.hh"
#include "Global.hh"
#include "GazeboError.hh"
@@ -62,6 +63,7 @@
this->server = NULL;
this->graphics = NULL;
this->openAL = NULL;
+ this->factory = NULL;
}
////////////////////////////////////////////////////////////////////////////////
@@ -111,6 +113,10 @@
{
gzthrow(e);
}
+
+ if (this->factory)
+ delete this->factory;
+ this->factory = NULL;
}
////////////////////////////////////////////////////////////////////////////////
@@ -140,6 +146,9 @@
gzthrow(err);
}
+ // Create the default factory
+ this->factory = new Factory();
+
// Create the graphics iface handler
this->graphics = new GraphicsIfaceHandler();
this->graphics->Load("default");
@@ -213,12 +222,15 @@
this->graphics->Init();
+ this->factory->Init();
}
////////////////////////////////////////////////////////////////////////////////
// Primarily used to update the graphics interfaces
void World::GraphicsUpdate()
{
+ this->graphics->Update();
+
// Update all the models
std::vector< Model* >::iterator miter;
for (miter=this->models.begin(); miter!=this->models.end(); miter++)
@@ -228,6 +240,7 @@
(*miter)->GraphicsUpdate();
}
}
+
}
////////////////////////////////////////////////////////////////////////////////
@@ -278,8 +291,9 @@
this->physicsEngine->UpdatePhysics();
}
- this->graphics->Update();
+ this->factory->Update();
+
#ifdef TIMING
double tmpT4 = Simulator::Instance()->GetWallTime();
std::cout << " World::Update() Physics engine DT(" << tmpT4-tmpT2 << ")" <<
std::endl;
Modified: code/gazebo/trunk/server/World.hh
===================================================================
--- code/gazebo/trunk/server/World.hh 2009-06-27 01:46:18 UTC (rev 7919)
+++ code/gazebo/trunk/server/World.hh 2009-06-27 02:15:31 UTC (rev 7920)
@@ -51,6 +51,7 @@
class XMLConfigNode;
class GraphicsIfaceHandler;
class OpenAL;
+ class Factory;
/// \brief The World
/*
@@ -228,6 +229,9 @@
/// Simulation interface
private: SimulationIface *simIface;
+
+ private: Factory *factory;
+
private: GraphicsIfaceHandler *graphics;
/// Length of time to run before receiving a "go" command
Modified: code/gazebo/trunk/server/controllers/CMakeLists.txt
===================================================================
--- code/gazebo/trunk/server/controllers/CMakeLists.txt 2009-06-27 01:46:18 UTC
(rev 7919)
+++ code/gazebo/trunk/server/controllers/CMakeLists.txt 2009-06-27 02:15:31 UTC
(rev 7920)
@@ -3,7 +3,6 @@
ADD_SUBDIRECTORY(actarray)
ADD_SUBDIRECTORY(bumper)
ADD_SUBDIRECTORY(camera)
-ADD_SUBDIRECTORY(factory)
ADD_SUBDIRECTORY(gripper)
ADD_SUBDIRECTORY(imu)
ADD_SUBDIRECTORY(irarray)
Modified: code/gazebo/trunk/webgazebo/WebGazebo.cc
===================================================================
--- code/gazebo/trunk/webgazebo/WebGazebo.cc 2009-06-27 01:46:18 UTC (rev
7919)
+++ code/gazebo/trunk/webgazebo/WebGazebo.cc 2009-06-27 02:15:31 UTC (rev
7920)
@@ -57,8 +57,8 @@
// Open the Simulation Interface; let exceptions leak out
this->simIface->Open(this->client, "default");
puts( "(opened sim interface)" );
- // this->factoryIface->Open(this->client, "factory_model::factory_iface");
- //puts( "(opened factory interface)" );
+ this->factoryIface->Open(this->client, "default");
+ puts( "(opened factory interface)" );
puts("Done.");
puts("[webgazebo] Ready");
Deleted: code/gazebo/trunk/worlds/factory.world
===================================================================
--- code/gazebo/trunk/worlds/factory.world 2009-06-27 01:46:18 UTC (rev
7919)
+++ code/gazebo/trunk/worlds/factory.world 2009-06-27 02:15:31 UTC (rev
7920)
@@ -1,109 +0,0 @@
-<?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"
>
-
- <verbosity>5</verbosity>
-
- <physics:ode>
- <stepTime>0.02</stepTime>
- <gravity>0 0 -9.80665</gravity>
- <cfm>1e-5</cfm>
- <erp>0.8</erp>
- </physics:ode>
-
- <rendering:gui>
- <type>fltk</type>
- <size>800 600</size>
- <pos>0 0</pos>
- </rendering:gui>
-
- <rendering:ogre>
- <ambient>0.1 0.1 0.1 1.0</ambient>
- <sky>
- <material>Gazebo/CloudySky</material>
- </sky>
-
- <fog>
- <color>0.8 0.8 0.8</color>
- <type>linear</type>
- <mass>0.1</mass>
- <linearStart>20.0</linearStart>
- <linearEnd>50.0</linearEnd>
- </fog>
- <grid>false</grid>
- </rendering:ogre>
-
-
- <model:physical name="sphere1_model">
- <xyz>1 0 0.5</xyz>
- <rpy>0.0 0.0 0.0</rpy>
- <static>false</static>
-
- <body:sphere name="sphere1_body">
- <geom:sphere name="sphere1_geom">
- <size>0.2</size>
- <mass>0.0</mass>
-
- <mu1>109999.0</mu1>
-
- <visual>
- <size>0.4 0.4 0.4</size>
- <mesh>unit_sphere</mesh>
- <material>Gazebo/Rocky</material>
- </visual>
- </geom:sphere>
- </body:sphere>
- </model:physical>
-
- <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>2000 2000</size>
- <segments>10 10</segments>
- <uvTile>2000 2000</uvTile>
- <material>Gazebo/GrayGrid</material>
- </geom:plane>
- </body:plane>
- </model:physical>
-
- <model:empty name="factory_model">
- <controller:factory name="factory_controller">
- <interface:factory name="factory_iface"/>
- </controller:factory>
- </model:empty>
-
- <!-- White Point light -->
- <model:renderable name="directional_white">
- <xyz>1 1 1</xyz>
- <enableGravity>false</enableGravity>
-
- <light>
- <type>point</type>
- <diffuseColor>0.8 0.8 0.8</diffuseColor>
- <specularColor>0.1 0.1 0.1</specularColor>
- <range>10</range>
-
- <!-- Constant(0-1) Linear(0-1) Quadratic -->
- <attenuation>0.2 0.01 0.0</attenuation>
- </light>
- </model:renderable>
-
-
-</gazebo:world>
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