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