|
From: <stu...@us...> - 2008-08-08 21:55:17
|
Revision: 2828
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=2828&view=rev
Author: stuglaser
Date: 2008-08-08 21:55:23 +0000 (Fri, 08 Aug 2008)
Log Message:
-----------
MechanismControlNode is MechanismControl on ROS. It's used by the gazebo_actuators gazebo plugin.
Modified Paths:
--------------
pkg/trunk/drivers/simulator/gazebo_plugin/include/gazebo_plugin/gazebo_actuators.h
pkg/trunk/drivers/simulator/gazebo_plugin/src/gazebo_actuators.cpp
pkg/trunk/mechanism/mechanism_control/CMakeLists.txt
pkg/trunk/mechanism/mechanism_control/include/mechanism_control/mechanism_control.h
pkg/trunk/mechanism/mechanism_control/manifest.xml
pkg/trunk/mechanism/mechanism_control/src/mechanism_control.cpp
pkg/trunk/util/misc_utils/include/misc_utils/factory.h
Added Paths:
-----------
pkg/trunk/mechanism/mechanism_control/srv/
pkg/trunk/mechanism/mechanism_control/srv/ListControllerTypes.srv
Modified: pkg/trunk/drivers/simulator/gazebo_plugin/include/gazebo_plugin/gazebo_actuators.h
===================================================================
--- pkg/trunk/drivers/simulator/gazebo_plugin/include/gazebo_plugin/gazebo_actuators.h 2008-08-08 21:54:14 UTC (rev 2827)
+++ pkg/trunk/drivers/simulator/gazebo_plugin/include/gazebo_plugin/gazebo_actuators.h 2008-08-08 21:55:23 UTC (rev 2828)
@@ -60,7 +60,8 @@
Model *parent_model_;
HardwareInterface hw_;
- MechanismControl mc_;
+ MechanismControlNode mc_;
+ ros::node *rosnode_;
// Each joint in joints_ corresponds to the joint with the same
// index in mech_joints_. The mech_joints_ vector exists so that
Modified: pkg/trunk/drivers/simulator/gazebo_plugin/src/gazebo_actuators.cpp
===================================================================
--- pkg/trunk/drivers/simulator/gazebo_plugin/src/gazebo_actuators.cpp 2008-08-08 21:54:14 UTC (rev 2827)
+++ pkg/trunk/drivers/simulator/gazebo_plugin/src/gazebo_actuators.cpp 2008-08-08 21:55:23 UTC (rev 2828)
@@ -50,10 +50,21 @@
GazeboActuators::GazeboActuators(Entity *parent)
: Controller(parent), hw_(0), mc_(&hw_)
{
- this->parent_model_ = dynamic_cast<Model*>(this->parent);
+ this->parent_model_ = dynamic_cast<Model*>(this->parent);
- if (!this->parent_model_)
- gzthrow("GazeboActuators controller requires a Model as its parent");
+ if (!this->parent_model_)
+ gzthrow("GazeboActuators controller requires a Model as its parent");
+
+ rosnode_ = ros::g_node;
+ int argc = 0;
+ char** argv = NULL;
+ if (rosnode_ == NULL)
+ {
+ // start a ros node if none exist
+ ros::init(argc,argv);
+ rosnode_ = new ros::node("ros_gazebo",ros::node::DONT_HANDLE_SIGINT);
+ printf("-------------------- starting node in GazeboActuators\n");
+ }
}
GazeboActuators::~GazeboActuators()
Modified: pkg/trunk/mechanism/mechanism_control/CMakeLists.txt
===================================================================
--- pkg/trunk/mechanism/mechanism_control/CMakeLists.txt 2008-08-08 21:54:14 UTC (rev 2827)
+++ pkg/trunk/mechanism/mechanism_control/CMakeLists.txt 2008-08-08 21:55:23 UTC (rev 2828)
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.6)
include(rosbuild)
rospack(mechanism_control)
+genmsg()
+gensrv()
rospack_add_library(mechanism_control src/mechanism_control.cpp)
-
Modified: pkg/trunk/mechanism/mechanism_control/include/mechanism_control/mechanism_control.h
===================================================================
--- pkg/trunk/mechanism/mechanism_control/include/mechanism_control/mechanism_control.h 2008-08-08 21:54:14 UTC (rev 2827)
+++ pkg/trunk/mechanism/mechanism_control/include/mechanism_control/mechanism_control.h 2008-08-08 21:55:23 UTC (rev 2828)
@@ -41,18 +41,21 @@
#include <map>
#include <string>
#include <vector>
+#include "ros/node.h"
#include <tinyxml/tinyxml.h>
#include <hardware_interface/hardware_interface.h>
#include <mechanism_model/robot.h>
#include <rosthread/mutex.h>
#include <generic_controllers/controller.h>
+#include "mechanism_control/ListControllerTypes.h"
+
typedef controller::Controller* (*ControllerAllocator)();
class MechanismControl {
public:
MechanismControl(HardwareInterface *hw);
- ~MechanismControl();
+ virtual ~MechanismControl();
// Real-time functions
void update();
@@ -77,4 +80,19 @@
controller::Controller* controllers_[MAX_NUM_CONTROLLERS];
};
+/*
+ * Exposes MechanismControl's interface over ROS
+ */
+class MechanismControlNode : public MechanismControl, public ros::node
+{
+public:
+ MechanismControlNode(HardwareInterface *hw);
+ virtual ~MechanismControlNode() {}
+
+ bool listControllerTypes(mechanism_control::ListControllerTypes::request &req,
+ mechanism_control::ListControllerTypes::response &resp);
+
+private:
+};
+
#endif /* MECHANISM_CONTROL_H */
Modified: pkg/trunk/mechanism/mechanism_control/manifest.xml
===================================================================
--- pkg/trunk/mechanism/mechanism_control/manifest.xml 2008-08-08 21:54:14 UTC (rev 2827)
+++ pkg/trunk/mechanism/mechanism_control/manifest.xml 2008-08-08 21:55:23 UTC (rev 2828)
@@ -5,13 +5,16 @@
<license>BSD</license>
<url>http://pr.willowgarage.com</url>
<depend package="rosthread"/>
+<depend package="roscpp" />
<depend package="hardware_interface"/>
<depend package="tinyxml"/>
<depend package="mechanism_model"/>
<depend package="generic_controllers"/>
<depend package="misc_utils" />
+<depend package="rospy" />
<export>
- <cpp cflags='-I${prefix}/include' lflags='-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lmechanism_control'/>
+ <cpp cflags='-I${prefix}/include -I${prefix}/msg/cpp -I${prefix}/srv/cpp'
+ lflags='-Wl,-rpath,${prefix}/lib -L${prefix}/lib -lmechanism_control'/>
</export>
</package>
Modified: pkg/trunk/mechanism/mechanism_control/src/mechanism_control.cpp
===================================================================
--- pkg/trunk/mechanism/mechanism_control/src/mechanism_control.cpp 2008-08-08 21:54:14 UTC (rev 2827)
+++ pkg/trunk/mechanism/mechanism_control/src/mechanism_control.cpp 2008-08-08 21:55:23 UTC (rev 2828)
@@ -175,3 +175,23 @@
return addController(c);
}
+
+
+
+MechanismControlNode::MechanismControlNode(HardwareInterface *hw)
+ : MechanismControl(hw), ros::node("MechanismControl")
+{
+ advertise_service("list_controller_types", &MechanismControlNode::listControllerTypes);
+}
+
+
+bool MechanismControlNode::listControllerTypes(
+ mechanism_control::ListControllerTypes::request &req,
+ mechanism_control::ListControllerTypes::response &resp)
+{
+ std::vector<std::string> types;
+ controller::ControllerFactory::instance().getTypes(&types);
+ resp.set_types_vec(types);
+ return true;
+}
+
Added: pkg/trunk/mechanism/mechanism_control/srv/ListControllerTypes.srv
===================================================================
--- pkg/trunk/mechanism/mechanism_control/srv/ListControllerTypes.srv (rev 0)
+++ pkg/trunk/mechanism/mechanism_control/srv/ListControllerTypes.srv 2008-08-08 21:55:23 UTC (rev 2828)
@@ -0,0 +1,2 @@
+---
+string[] types
\ No newline at end of file
Modified: pkg/trunk/util/misc_utils/include/misc_utils/factory.h
===================================================================
--- pkg/trunk/util/misc_utils/include/misc_utils/factory.h 2008-08-08 21:54:14 UTC (rev 2827)
+++ pkg/trunk/util/misc_utils/include/misc_utils/factory.h 2008-08-08 21:55:23 UTC (rev 2828)
@@ -31,6 +31,7 @@
#include <string>
#include <map>
+#include <vector>
template <class BaseResult,
class Constructor = BaseResult* (*)()>
@@ -60,6 +61,15 @@
return true;
}
+ void getTypes(std::vector<std::string> *result)
+ {
+ result->resize(types_.size());
+ int i = 0;
+ typename ConstructorMap::const_iterator it;
+ for (it = types_.begin(); it != types_.end(); ++it)
+ (*result)[i++] = it->first;
+ }
+
private:
Factory() {}
~Factory() {}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|