13
13
14
14
#include < dynamic-graph/pool.h>
15
15
16
+ #include < boost/make_shared.hpp>
17
+ #include < boost/shared_ptr.hpp>
16
18
#include < exception>
19
+ #include < sot/core/robot-utils.hh>
20
+ #include < stdexcept>
17
21
18
- #include " dynamic_graph_bridge/ros_parameter.hpp"
22
+ #include " pinocchio/multibody/model.hpp"
23
+ #include " pinocchio/parsers/urdf.hpp"
19
24
20
25
// POSIX.1-2001
21
26
#include < dlfcn.h>
@@ -24,15 +29,15 @@ using namespace std;
24
29
using namespace dynamicgraph ::sot;
25
30
namespace po = boost::program_options;
26
31
27
- SotLoaderBasic::SotLoaderBasic (const std::string & aNodeName)
32
+ SotLoaderBasic::SotLoaderBasic (const std::string& aNodeName)
28
33
: rclcpp::Node(aNodeName),
29
34
dynamic_graph_stopped_(true ),
35
+ sotController_(NULL ),
30
36
sotRobotControllerLibrary_(0 ) {
31
37
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge::" ),
32
38
" Beginning of SotLoaderBasic" );
33
- // nh_ = dynamic_graph_bridge::get_ros_node("SotLoaderBasic");
34
39
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
35
- " End of SotLoaderBasic" );
40
+ " End of SotLoaderBasic" );
36
41
}
37
42
38
43
SotLoaderBasic::~SotLoaderBasic () {
@@ -41,23 +46,23 @@ SotLoaderBasic::~SotLoaderBasic() {
41
46
42
47
void SotLoaderBasic::initialize () {}
43
48
44
- // rclcpp::Node::SharedPtr SotLoaderBasic::returnsNodeHandle() { return nh_; }
45
49
int SotLoaderBasic::initPublication () {
46
50
// Prepare message to be published
47
51
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
48
52
" SotLoaderBasic::initPublication - create joint_pub" );
49
-
53
+
50
54
joint_pub_ =
51
55
create_publisher<sensor_msgs::msg::JointState>(" joint_states" , 1 );
52
56
53
57
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
54
- " SotLoaderBasic::initPublication - after create joint_pub" );
58
+ " SotLoaderBasic::initPublication - after create joint_pub" );
55
59
return 0 ;
56
60
}
57
61
58
62
void SotLoaderBasic::initializeServices () {
59
- RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
60
- " SotLoaderBasic::initializeServices - Ready to start dynamic graph." );
63
+ RCLCPP_INFO (
64
+ rclcpp::get_logger (" dynamic_graph_bridge" ),
65
+ " SotLoaderBasic::initializeServices - Ready to start dynamic graph." );
61
66
62
67
using namespace std ::placeholders;
63
68
service_start_ = create_service<std_srvs::srv::Empty>(
@@ -74,8 +79,7 @@ void SotLoaderBasic::initializeServices() {
74
79
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
75
80
" SotLoaderBasic::initializeServices - stopped dynamic graph." );
76
81
77
- rclcpp::Node::SharedPtr a_node_ptr (this );
78
- dynamicgraph::parameter_server_read_robot_description (a_node_ptr);
82
+ parameter_server_read_robot_description ();
79
83
}
80
84
81
85
void SotLoaderBasic::setDynamicLibraryName (std::string& afilename) {
@@ -106,8 +110,7 @@ int SotLoaderBasic::readSotVectorStateParam() {
106
110
RCLCPP_INFO (get_logger (), " state_vector_map parameter size %ld" ,
107
111
stateVectorMap_.size ());
108
112
} catch (exception& e) {
109
- std::throw_with_nested (
110
- std::logic_error (" Unable to call nh_->get_parameter" ));
113
+ std::throw_with_nested (std::logic_error (" Unable to call get_parameter" ));
111
114
}
112
115
113
116
nbOfJoints_ = static_cast <int >(stateVectorMap_.size ());
@@ -233,17 +236,19 @@ void SotLoaderBasic::CleanUp() {
233
236
// SignalCaster singleton could probably be destroyed.
234
237
235
238
// Load the symbols.
236
- destroySotExternalInterface_t* destroySot =
237
- reinterpret_cast <destroySotExternalInterface_t*>(reinterpret_cast <long >(
238
- dlsym (sotRobotControllerLibrary_, " destroySotExternalInterface" )));
239
- const char * dlsym_error = dlerror ();
240
- if (dlsym_error) {
241
- std::cerr << " Cannot load symbol destroy: " << dlsym_error << ' \n ' ;
242
- return ;
243
- }
239
+ if (sotController_ != NULL ) {
240
+ destroySotExternalInterface_t* destroySot =
241
+ reinterpret_cast <destroySotExternalInterface_t*>(reinterpret_cast <long >(
242
+ dlsym (sotRobotControllerLibrary_, " destroySotExternalInterface" )));
243
+ const char * dlsym_error = dlerror ();
244
+ if (dlsym_error) {
245
+ std::cerr << " Cannot load symbol destroy: " << dlsym_error << ' \n ' ;
246
+ return ;
247
+ }
244
248
245
- destroySot (sotController_);
246
- sotController_ = NULL ;
249
+ destroySot (sotController_);
250
+ sotController_ = NULL ;
251
+ }
247
252
248
253
// / Uncount the number of access to this library.
249
254
try {
@@ -265,3 +270,44 @@ void SotLoaderBasic::stop_dg(
265
270
std::shared_ptr<std_srvs::srv::Empty::Response>) {
266
271
dynamic_graph_stopped_ = true ;
267
272
}
273
+
274
+ bool SotLoaderBasic::parameter_server_read_robot_description () {
275
+ if (!has_parameter (" robot_description" )) {
276
+ declare_parameter (" robot_description" , std::string (" " ));
277
+ }
278
+
279
+ std::string robot_description;
280
+ std::string parameter_name (" robot_description" );
281
+ get_parameter (parameter_name, robot_description);
282
+ if (robot_description.empty ()) {
283
+ RCLCPP_FATAL (rclcpp::get_logger (" dynamic_graph_bridge" ),
284
+ " Parameter robot_description is empty" );
285
+ return false ;
286
+ }
287
+
288
+ std::string model_name (" robot" );
289
+
290
+ // Search for the robot util related to robot_name.
291
+ RobotUtilShrPtr aRobotUtil = getRobotUtil (model_name);
292
+ // If does not exist then it is created.
293
+ if (aRobotUtil == RefVoidRobotUtil ())
294
+ aRobotUtil = createRobotUtil (model_name);
295
+
296
+ // If the creation is fine
297
+ if (aRobotUtil != RefVoidRobotUtil ()) {
298
+ // Then set the robot model.
299
+ aRobotUtil->set_parameter (parameter_name, robot_description);
300
+ RCLCPP_INFO (
301
+ rclcpp::get_logger (" dynamic_graph_bridge" ),
302
+ " parameter_server_read_robot_description : Set parameter_name : %s." ,
303
+ parameter_name.c_str ());
304
+ // Everything went fine.
305
+ return true ;
306
+ }
307
+ RCLCPP_FATAL (rclcpp::get_logger (" dynamic_graph_bridge" ),
308
+ " Wrong initialization of parameter_name %s" ,
309
+ parameter_name.c_str ());
310
+
311
+ // Otherwise something went wrong.
312
+ return false ;
313
+ }
0 commit comments