Revision: 8731
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8731&view=rev
Author:   natepak
Date:     2010-05-29 17:04:31 +0000 (Sat, 29 May 2010)

Log Message:
-----------
Added ability to load plugins from the command line

Modified Paths:
--------------
    code/gazebo/branches/simpar/libgazebo/SimIface.cc
    code/gazebo/branches/simpar/libgazebo/gz.h
    code/gazebo/branches/simpar/server/GazeboConfig.cc
    code/gazebo/branches/simpar/server/Simulator.cc
    code/gazebo/branches/simpar/server/Simulator.hh
    code/gazebo/branches/simpar/server/World.cc
    code/gazebo/branches/simpar/tools/gazebomodel.cc
    code/gazebo/branches/simpar/worlds/pioneer2dx.world

Added Paths:
-----------
    code/gazebo/branches/simpar/plugins/
    code/gazebo/branches/simpar/plugins/CMakeLists.txt
    code/gazebo/branches/simpar/plugins/pioneer_spiral.cc
    code/gazebo/branches/simpar/plugins/pioneer_spiral.hh

Modified: code/gazebo/branches/simpar/libgazebo/SimIface.cc
===================================================================
--- code/gazebo/branches/simpar/libgazebo/SimIface.cc   2010-05-29 16:47:21 UTC 
(rev 8730)
+++ code/gazebo/branches/simpar/libgazebo/SimIface.cc   2010-05-29 17:04:31 UTC 
(rev 8731)
@@ -1001,3 +1001,23 @@
   assert(this->data->responseCount == 1);
   return data->responses[0].strValue;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+/// Add a handler
+void SimulationIface::AddHandler(const std::string &name)
+{
+  this->Lock(1);
+
+  this->data->responseCount = 0;
+  SimulationRequestData *request;
+
+  request = &(this->data->requests[this->data->requestCount++]);
+  request->type = SimulationRequestData::ADD_HANDLER;
+  memset(request->strValue, 0, 512);
+  strncpy(request->strValue, name.c_str(), 512);
+  request->strValue[511] = '\0';
+
+  this->Unlock();
+}
+
+

Modified: code/gazebo/branches/simpar/libgazebo/gz.h
===================================================================
--- code/gazebo/branches/simpar/libgazebo/gz.h  2010-05-29 16:47:21 UTC (rev 
8730)
+++ code/gazebo/branches/simpar/libgazebo/gz.h  2010-05-29 17:04:31 UTC (rev 
8731)
@@ -454,7 +454,8 @@
                       SET_STEP_TYPE,
                       GET_STEP_TYPE,
                       APPLY_FORCE,
-                      APPLY_TORQUE
+                      APPLY_TORQUE,
+                      ADD_HANDLER
                    };
 
   public: Type type; 
@@ -685,6 +686,9 @@
   /// \brief Get the step type
   public: std::string GetStepType();
 
+  /// \brief Add a handler
+  public: void AddHandler(const std::string &name);
+
   private: void BlockThread();
 
   /// \brief Wait for a return message

Added: code/gazebo/branches/simpar/plugins/CMakeLists.txt
===================================================================
--- code/gazebo/branches/simpar/plugins/CMakeLists.txt                          
(rev 0)
+++ code/gazebo/branches/simpar/plugins/CMakeLists.txt  2010-05-29 17:04:31 UTC 
(rev 8731)
@@ -0,0 +1,27 @@
+project(benchmarks)
+
+cmake_minimum_required( VERSION 2.4 FATAL_ERROR )
+
+if(COMMAND cmake_policy)
+  cmake_policy(SET CMP0003 NEW)
+  cmake_policy(SET CMP0004 NEW)
+endif(COMMAND cmake_policy)
+
+include (FindPkgConfig)
+
+if (PKG_CONFIG_FOUND)
+  pkg_check_modules(GAZEBO gazeboserver)
+  include_directories(${GAZEBO_INCLUDE_DIRS})
+  link_directories(${GAZEBO_LIBRARY_DIRS})
+endif (PKG_CONFIG_FOUND)
+
+set (plugins pioneer_spiral )
+
+foreach (src ${plugins})
+  set_source_files_properties(${src}.cc PROPERTIES COMPILE_FLAGS 
${GAZEBO_CFLAGS})
+  add_library(${src} SHARED ${src}.cc)
+  target_link_libraries(${src} gazebo ${GAZEBO_LINK_LIBS} )
+  set_target_properties(${src} PROPERTIES SKIP_BUILD_RPATH TRUE)
+  set_target_properties(${src} PROPERTIES LINK_FLAGS "${GAZEBO_LDFLAGS}")
+  install (TARGETS ${src} DESTINATION 
${CMAKE_INSTALL_PREFIX}/share/gazebo/plugins/)
+endforeach (src ${benchmarks})

Added: code/gazebo/branches/simpar/plugins/pioneer_spiral.cc
===================================================================
--- code/gazebo/branches/simpar/plugins/pioneer_spiral.cc                       
        (rev 0)
+++ code/gazebo/branches/simpar/plugins/pioneer_spiral.cc       2010-05-29 
17:04:31 UTC (rev 8731)
@@ -0,0 +1,38 @@
+#include <boost/bind.hpp>
+#include "pioneer_spiral.hh"
+
+using namespace gazebo;
+
+GZ_REGISTER_HANDLER("PioneerSpiral", PioneerSpiral)
+
+PioneerSpiral::PioneerSpiral() : Handler()
+{
+}
+
+PioneerSpiral::~PioneerSpiral()
+{
+}
+
+void PioneerSpiral::Load()
+{
+
+  std::string model_name = "pioneer2dx_model";
+  this->robot = (Model*)World::Instance()->GetEntityByName(model_name);
+
+  if (this->robot)
+  {
+    this->robot->GetVisualNode()->SetRibbonTrail(true);
+    this->leftWheel = (Body*)this->robot->GetChild("left_wheel");
+    this->rightWheel = (Body*)this->robot->GetChild("right_wheel");
+
+    World::Instance()->ConnectWorldUpdateStartSignal(
+        boost::bind(&PioneerSpiral::UpdateCB, this));
+  }
+  else
+    std::cerr << "Unable to find model[" << model_name << "]\n";
+}
+
+void PioneerSpiral::UpdateCB()
+{
+  this->leftWheel->SetTorque(Vector3(0,0,0.5));
+}

Added: code/gazebo/branches/simpar/plugins/pioneer_spiral.hh
===================================================================
--- code/gazebo/branches/simpar/plugins/pioneer_spiral.hh                       
        (rev 0)
+++ code/gazebo/branches/simpar/plugins/pioneer_spiral.hh       2010-05-29 
17:04:31 UTC (rev 8731)
@@ -0,0 +1,25 @@
+#ifndef pioneer_spiral_hh
+#define pioneer_spiral_hh
+
+#include <gazebo/gazeboserver.hh>
+
+namespace gazebo
+{
+  class Model;
+
+  class PioneerSpiral : public Handler
+  {
+    public: PioneerSpiral();
+    public: virtual ~PioneerSpiral();
+
+    public: void Load();
+
+    public: void UpdateCB();
+
+    private: Model *robot;
+    private: Body *leftWheel;
+    private: Body *rightWheel;
+  };
+}
+
+#endif

Modified: code/gazebo/branches/simpar/server/GazeboConfig.cc
===================================================================
--- code/gazebo/branches/simpar/server/GazeboConfig.cc  2010-05-29 16:47:21 UTC 
(rev 8730)
+++ code/gazebo/branches/simpar/server/GazeboConfig.cc  2010-05-29 17:04:31 UTC 
(rev 8731)
@@ -84,6 +84,7 @@
       {
         gzmsg(5) << "Gazebo Path[" << node->GetValue() << "]\n";
         this->gazeboPaths.push_back(node->GetValue());
+        this->AddPluginPaths(node->GetValue()+"/plugins");
         node = node->GetNext("gazeboPath");
       }
     }
@@ -108,6 +109,7 @@
     if ( !gazebo_resource_path )
     {
       this->gazeboPaths.push_back("/usr/local/share/gazebo");
+      this->AddPluginPaths("/usr/local/share/gazebo/plugins");
     }
 
     if ( !ogre_resource_path )

Modified: code/gazebo/branches/simpar/server/Simulator.cc
===================================================================
--- code/gazebo/branches/simpar/server/Simulator.cc     2010-05-29 16:47:21 UTC 
(rev 8730)
+++ code/gazebo/branches/simpar/server/Simulator.cc     2010-05-29 17:04:31 UTC 
(rev 8731)
@@ -299,11 +299,7 @@
   XMLConfigNode *handlerNode = rootNode->GetChild("handler");
   while (handlerNode != NULL)
   {
-    std::string plugin = handlerNode->GetString("plugin","",1);
-    std::cout << "Handler[" << plugin << "]\n";
-    Handler *handler = Handler::Create(plugin);
-    this->handlers.push_back(handler);
-
+    this->AddHandler(handlerNode->GetString("plugin","",1));
     handlerNode = handlerNode->GetNext("handler");
   }
 
@@ -313,6 +309,15 @@
 }
 
 
////////////////////////////////////////////////////////////////////////////////
+// Add a handler
+void Simulator::AddHandler(const std::string &name)
+{
+  Handler *handler = Handler::Create(name);
+  handler->Load();
+  this->handlers.push_back(handler);
+}
+
+////////////////////////////////////////////////////////////////////////////////
 /// Initialize the simulation
 void Simulator::Init()
 {
@@ -328,10 +333,6 @@
     gzthrow("Failed to Initialize the World\n"  << e);
   }
 
-  std::vector<Handler*>::iterator iter;
-  for (iter = this->handlers.begin(); iter != this->handlers.end(); iter++)
-    (*iter)->Load();
-
   // This is not a debug line. This is useful for external programs that 
   // launch Gazebo and wait till it is ready   
   std::cout << "Gazebo successfully initialized" << std::endl;

Modified: code/gazebo/branches/simpar/server/Simulator.hh
===================================================================
--- code/gazebo/branches/simpar/server/Simulator.hh     2010-05-29 16:47:21 UTC 
(rev 8730)
+++ code/gazebo/branches/simpar/server/Simulator.hh     2010-05-29 17:04:31 UTC 
(rev 8731)
@@ -171,6 +171,9 @@
     /// \brief Get the state of the simulation
     public: State GetState() const;
 
+    /// \brief Add a handler
+    public: void AddHandler(const std::string &plugin);
+
     /// \brief Connect a boost::slot the the pause signal
     public: template<typename T>
             void ConnectPauseSignal( T subscriber )

Modified: code/gazebo/branches/simpar/server/World.cc
===================================================================
--- code/gazebo/branches/simpar/server/World.cc 2010-05-29 16:47:21 UTC (rev 
8730)
+++ code/gazebo/branches/simpar/server/World.cc 2010-05-29 17:04:31 UTC (rev 
8731)
@@ -1596,6 +1596,11 @@
           break;
         }
 
+     case libgazebo::SimulationRequestData::ADD_HANDLER:
+        {
+          Simulator::Instance()->AddHandler(req->strValue);
+          break;
+        }
 
      case libgazebo::SimulationRequestData::GO:
         {

Modified: code/gazebo/branches/simpar/tools/gazebomodel.cc
===================================================================
--- code/gazebo/branches/simpar/tools/gazebomodel.cc    2010-05-29 16:47:21 UTC 
(rev 8730)
+++ code/gazebo/branches/simpar/tools/gazebomodel.cc    2010-05-29 17:04:31 UTC 
(rev 8731)
@@ -128,6 +128,17 @@
     }
   }
 
+  public: void AddHandler()
+  {
+    if (this->params.size() < 2)
+      std::cerr << "Missing pluing filename\n";
+    else
+    {
+      this->simIface->AddHandler(params[1]);
+    }
+
+  }
+
   
//////////////////////////////////////////////////////////////////////////////
   // Spawn a new model into the world
   public: void Spawn()
@@ -226,6 +237,8 @@
         this->Spawn();
       else if (params[0] == "set")
         this->Set();
+      else if (params[0] == "handler")
+        this->AddHandler();
       else
         std::cerr << "Unknown command[" << this->params[0] << "]\n";
     }

Modified: code/gazebo/branches/simpar/worlds/pioneer2dx.world
===================================================================
--- code/gazebo/branches/simpar/worlds/pioneer2dx.world 2010-05-29 16:47:21 UTC 
(rev 8730)
+++ code/gazebo/branches/simpar/worlds/pioneer2dx.world 2010-05-29 17:04:31 UTC 
(rev 8731)
@@ -18,8 +18,6 @@
 
   <verbosity>4</verbosity>
 
-  <handler plugin="libtest.so"/>
-
   <physics:ode>
     <stepTime>0.001</stepTime>
     <gravity>0 0 -9.8</gravity>


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

Reply via email to