@@ -27,10 +27,13 @@ using namespace dynamicgraph::sot;
27
27
namespace po = boost::program_options;
28
28
29
29
SotLoaderBasic::SotLoaderBasic (const std::string& aNodeName)
30
- : rclcpp::Node(aNodeName ),
30
+ : ros_node_( nullptr ),
31
31
dynamic_graph_stopped_(true ),
32
32
sotController_(NULL ),
33
33
sotRobotControllerLibrary_(0 ) {
34
+
35
+ ros_node_ = dynamic_graph_bridge::get_ros_node (aNodeName);
36
+
34
37
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge::" ),
35
38
" Beginning of SotLoaderBasic" );
36
39
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
@@ -48,7 +51,7 @@ int SotLoaderBasic::initPublication() {
48
51
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
49
52
" SotLoaderBasic::initPublication - create joint_pub" );
50
53
51
- joint_pub_ =
54
+ joint_pub_ = ros_node_->
52
55
create_publisher<sensor_msgs::msg::JointState>(" joint_states" , 1 );
53
56
54
57
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
@@ -62,19 +65,21 @@ void SotLoaderBasic::initializeServices() {
62
65
" SotLoaderBasic::initializeServices - Ready to start dynamic graph." );
63
66
64
67
using namespace std ::placeholders;
65
- service_start_ = create_service<std_srvs::srv::Empty>(
66
- " start_dynamic_graph" ,
67
- std::bind (&SotLoaderBasic::start_dg, this , std::placeholders::_1,
68
- std::placeholders::_2));
68
+ service_start_ = ros_node_->
69
+ create_service<std_srvs::srv::Empty>(
70
+ " start_dynamic_graph" ,
71
+ std::bind (&SotLoaderBasic::start_dg, this , std::placeholders::_1,
72
+ std::placeholders::_2));
69
73
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
70
- " SotLoaderBasic::initializeServices - started dynamic graph ." );
74
+ " SotLoaderBasic::initializeServices - start_dynamic_graph ." );
71
75
72
- service_stop_ = create_service<std_srvs::srv::Empty>(
73
- " stop_dynamic_graph" ,
74
- std::bind (&SotLoaderBasic::stop_dg, this , std::placeholders::_1,
75
- std::placeholders::_2));
76
+ service_stop_ = ros_node_->
77
+ create_service<std_srvs::srv::Empty>(
78
+ " stop_dynamic_graph" ,
79
+ std::bind (&SotLoaderBasic::stop_dg, this , std::placeholders::_1,
80
+ std::placeholders::_2));
76
81
RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
77
- " SotLoaderBasic::initializeServices - stopped dynamic graph ." );
82
+ " SotLoaderBasic::initializeServices - stop_dynamic_graph ." );
78
83
79
84
parameter_server_read_robot_description ();
80
85
}
@@ -89,22 +94,22 @@ int SotLoaderBasic::readSotVectorStateParam() {
89
94
90
95
// It is necessary to declare parameters first
91
96
// before trying to access them.
92
- if (not has_parameter (" state_vector_map" ))
93
- declare_parameter (" state_vector_map" , std::vector<std::string>{});
94
- if (not has_parameter (" joint_state_parallel" ))
95
- declare_parameter (" joint_state_parallel" , std::vector<std::string>{});
97
+ if (not ros_node_-> has_parameter (" state_vector_map" ))
98
+ ros_node_-> declare_parameter (" state_vector_map" , std::vector<std::string>{});
99
+ if (not ros_node_-> has_parameter (" joint_state_parallel" ))
100
+ ros_node_-> declare_parameter (" joint_state_parallel" , std::vector<std::string>{});
96
101
97
102
// Read the state vector of the robot
98
103
// Defines the order in which the actuators are ordered
99
104
try {
100
105
std::string aParameterName (" state_vector_map" );
101
- if (!get_parameter (aParameterName, stateVectorMap_)) {
106
+ if (!ros_node_-> get_parameter (aParameterName, stateVectorMap_)) {
102
107
logic_error aLogicError (
103
108
" SotLoaderBasic::readSotVectorStateParam : State_vector_map is "
104
109
" empty" );
105
110
throw aLogicError;
106
111
}
107
- RCLCPP_INFO (get_logger (), " state_vector_map parameter size %ld" ,
112
+ RCLCPP_INFO (ros_node_-> get_logger (), " state_vector_map parameter size %ld" ,
108
113
stateVectorMap_.size ());
109
114
} catch (exception& e) {
110
115
std::throw_with_nested (std::logic_error (" Unable to call get_parameter" ));
@@ -119,7 +124,7 @@ int SotLoaderBasic::readSotVectorStateParam() {
119
124
120
125
std::string prefix (" joint_state_parallel" );
121
126
std::map<std::string, rclcpp::Parameter> joint_state_parallel;
122
- get_parameters (prefix, joint_state_parallel);
127
+ ros_node_-> get_parameters (prefix, joint_state_parallel);
123
128
124
129
// Iterates over the map joint_state_parallel
125
130
for (std::map<std::string, rclcpp::Parameter>::iterator it_map_expression =
@@ -202,7 +207,9 @@ void SotLoaderBasic::loadController() {
202
207
sotRobotControllerLibrary_ =
203
208
dlopen (dynamicLibraryName_.c_str (), RTLD_LAZY | RTLD_GLOBAL);
204
209
if (!sotRobotControllerLibrary_) {
205
- std::cerr << " Cannot load library: " << dlerror () << ' \n ' ;
210
+ RCLCPP_ERROR (rclcpp::get_logger (" dynamic_graph_bridge" ),
211
+ " Cannot load library: %s" ,
212
+ dlerror ());
206
213
return ;
207
214
}
208
215
@@ -215,14 +222,17 @@ void SotLoaderBasic::loadController() {
215
222
dlsym (sotRobotControllerLibrary_, " createSotExternalInterface" )));
216
223
const char * dlsym_error = dlerror ();
217
224
if (dlsym_error) {
218
- std::cerr << " Cannot load symbol create: " << dlsym_error << " from "
219
- << dynamicLibraryName_ << ' \n ' ;
225
+ RCLCPP_ERROR (rclcpp::get_logger (" dynamic_graph_bridge" ),
226
+ " Cannot load symbol create: %s from %s" ,
227
+ dlsym_error,
228
+ dynamicLibraryName_.c_str () );
220
229
return ;
221
230
}
222
231
223
232
// Create robot-controller
224
233
sotController_ = createSot ();
225
- cout << " Went out from loadController." << endl;
234
+ RCLCPP_INFO (rclcpp::get_logger (" dynamic_graph_bridge" ),
235
+ " Went out from loadController." );
226
236
}
227
237
228
238
void SotLoaderBasic::CleanUp () {
@@ -269,13 +279,13 @@ void SotLoaderBasic::stop_dg(
269
279
}
270
280
271
281
bool SotLoaderBasic::parameter_server_read_robot_description () {
272
- if (!has_parameter (" robot_description" )) {
273
- declare_parameter (" robot_description" , std::string (" " ));
282
+ if (!ros_node_-> has_parameter (" robot_description" )) {
283
+ ros_node_-> declare_parameter (" robot_description" , std::string (" " ));
274
284
}
275
285
276
286
std::string robot_description;
277
287
std::string parameter_name (" robot_description" );
278
- get_parameter (parameter_name, robot_description);
288
+ ros_node_-> get_parameter (parameter_name, robot_description);
279
289
if (robot_description.empty ()) {
280
290
RCLCPP_FATAL (rclcpp::get_logger (" dynamic_graph_bridge" ),
281
291
" Parameter robot_description is empty" );
0 commit comments