Skip to content

Commit a49a223

Browse files
At initialization time read the ros param /robot_description
and record it in the sot parameter-server.
1 parent 232d5d7 commit a49a223

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ set(${PROJECT_NAME}_HEADERS
6666
SET(${PROJECT_NAME}_SOURCES
6767
src/ros_init.cpp
6868
src/sot_to_ros.cpp
69+
src/ros_parameter.cpp
6970
)
7071

7172
ADD_LIBRARY(ros_bridge SHARED
7273
${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS})
7374
TARGET_INCLUDE_DIRECTORIES(ros_bridge SYSTEM PUBLIC ${catkin_INCLUDE_DIRS})
7475
TARGET_INCLUDE_DIRECTORIES(ros_bridge PUBLIC $<INSTALL_INTERFACE:include>)
75-
TARGET_LINK_LIBRARIES(ros_bridge ${catkin_LIBRARIES} sot-core::sot-core)
76+
TARGET_LINK_LIBRARIES(ros_bridge ${catkin_LIBRARIES}
77+
sot-core::sot-core pinocchio::pinocchio)
7678
pkg_config_use_dependency(ros_bridge dynamic_graph_bridge_msgs)
7779

7880
IF(SUFFIX_SO_VERSION)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef _ROS_DYNAMIC_GRAPH_PARAMETER_
2+
#define _ROS_DYNAMIC_GRAPH_PARAMETER_
3+
4+
namespace dynamicgraph {
5+
6+
bool parameter_server_read_robot_description();
7+
8+
};
9+
#endif /* _ROS_DYNAMIC_GRAPH_PARAMETER_ */

src/ros_parameter.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "pinocchio/multibody/model.hpp"
2+
#include "pinocchio/parsers/urdf.hpp"
3+
4+
#include <stdexcept>
5+
#include <boost/make_shared.hpp>
6+
#include <boost/shared_ptr.hpp>
7+
8+
#include <urdf_parser/urdf_parser.h>
9+
10+
#include <sot/core/robot-utils.hh>
11+
#include <ros/ros.h>
12+
#include "dynamic_graph_bridge/ros_parameter.hh"
13+
14+
namespace dynamicgraph {
15+
bool parameter_server_read_robot_description()
16+
{
17+
ros::NodeHandle nh;
18+
if (!nh.hasParam("/robot_description"))
19+
{
20+
ROS_ERROR("No /robot_description parameter");
21+
return false;
22+
}
23+
24+
std::string robot_description;
25+
std::string parameter_name("/robot_description");
26+
nh.getParam(parameter_name,robot_description);
27+
28+
pinocchio::Model model;
29+
pinocchio::urdf::buildModelFromXML(robot_description, model);
30+
31+
ROS_INFO("Robot name : %s.",model.name.c_str());
32+
// Search for the robot util related to robot_name.
33+
sot::RobotUtilShrPtr aRobotUtil = sot::getRobotUtil(model.name);
34+
// If does not exist then it is created.
35+
if (aRobotUtil != sot::RefVoidRobotUtil())
36+
aRobotUtil = sot::createRobotUtil(model.name);
37+
38+
// If the creation is fine
39+
if (aRobotUtil != sot::RefVoidRobotUtil())
40+
{
41+
// Then set the robot model.
42+
aRobotUtil->set_parameter(parameter_name,robot_description);
43+
ROS_INFO("Set parameter_name : %s.",parameter_name.c_str());
44+
// Everything went fine.
45+
return true;
46+
}
47+
ROS_ERROR("Wrong initialization of parameter_name %s",
48+
parameter_name.c_str());
49+
50+
// Otherwise something went wrong.
51+
return false;
52+
53+
}
54+
55+
};

src/sot_loader_basic.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <dynamic_graph_bridge/sot_loader.hh>
1313
#include "dynamic_graph_bridge/ros_init.hh"
14+
#include "dynamic_graph_bridge/ros_parameter.hh"
1415

1516
#include <dynamic-graph/pool.h>
1617

@@ -41,6 +42,8 @@ void SotLoaderBasic::initializeRosNode(int, char* []) {
4142
service_start_ = n.advertiseService("start_dynamic_graph", &SotLoaderBasic::start_dg, this);
4243

4344
service_stop_ = n.advertiseService("stop_dynamic_graph", &SotLoaderBasic::stop_dg, this);
45+
46+
dynamicgraph::parameter_server_read_robot_description();
4447
}
4548

4649
void SotLoaderBasic::setDynamicLibraryName(std::string& afilename) { dynamicLibraryName_ = afilename; }

0 commit comments

Comments
 (0)