complete_test.cpp
Go to the documentation of this file.
1 // Copyright 1996-2020 Cyberbotics Ltd.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <geometry_msgs/Twist.h>
16 #include <geometry_msgs/WrenchStamped.h>
17 #include <sensor_msgs/Illuminance.h>
18 #include <sensor_msgs/Image.h>
19 #include <sensor_msgs/Imu.h>
20 #include <sensor_msgs/MagneticField.h>
21 #include <sensor_msgs/NavSatFix.h>
22 #include <sensor_msgs/Range.h>
23 #include <signal.h>
24 #include <std_msgs/Float32MultiArray.h>
25 #include <std_msgs/Float64.h>
26 #include <std_msgs/Float64MultiArray.h>
27 #include <std_msgs/String.h>
28 #include <std_msgs/UInt16.h>
29 #include <std_msgs/UInt8MultiArray.h>
30 #include <webots_ros/BoolStamped.h>
31 #include <webots_ros/Float64Stamped.h>
32 #include <webots_ros/Int32Stamped.h>
33 #include <webots_ros/Int8Stamped.h>
34 #include <webots_ros/RadarTarget.h>
35 #include <webots_ros/RecognitionObject.h>
36 #include <webots_ros/StringStamped.h>
37 #include <cstdlib>
38 #include "ros/ros.h"
39 
40 #include <webots_ros/get_bool.h>
41 #include <webots_ros/get_float.h>
42 #include <webots_ros/get_float_array.h>
43 #include <webots_ros/get_int.h>
44 #include <webots_ros/get_string.h>
45 #include <webots_ros/get_uint64.h>
46 #include <webots_ros/get_urdf.h>
47 #include <webots_ros/set_bool.h>
48 #include <webots_ros/set_float.h>
49 #include <webots_ros/set_float_array.h>
50 #include <webots_ros/set_int.h>
51 #include <webots_ros/set_string.h>
52 
53 #include <webots_ros/camera_get_focus_info.h>
54 #include <webots_ros/camera_get_info.h>
55 #include <webots_ros/camera_get_zoom_info.h>
56 #include <webots_ros/display_draw_line.h>
57 #include <webots_ros/display_draw_oval.h>
58 #include <webots_ros/display_draw_pixel.h>
59 #include <webots_ros/display_draw_polygon.h>
60 #include <webots_ros/display_draw_rectangle.h>
61 #include <webots_ros/display_draw_text.h>
62 #include <webots_ros/display_get_info.h>
63 #include <webots_ros/display_image_copy.h>
64 #include <webots_ros/display_image_delete.h>
65 #include <webots_ros/display_image_load.h>
66 #include <webots_ros/display_image_new.h>
67 #include <webots_ros/display_image_paste.h>
68 #include <webots_ros/display_image_save.h>
69 #include <webots_ros/display_set_font.h>
70 #include <webots_ros/field_get_bool.h>
71 #include <webots_ros/field_get_color.h>
72 #include <webots_ros/field_get_count.h>
73 #include <webots_ros/field_get_float.h>
74 #include <webots_ros/field_get_int32.h>
75 #include <webots_ros/field_get_node.h>
76 #include <webots_ros/field_get_rotation.h>
77 #include <webots_ros/field_get_string.h>
78 #include <webots_ros/field_get_type.h>
79 #include <webots_ros/field_get_type_name.h>
80 #include <webots_ros/field_get_vec2f.h>
81 #include <webots_ros/field_get_vec3f.h>
82 #include <webots_ros/field_import_node.h>
83 #include <webots_ros/field_remove.h>
84 #include <webots_ros/field_set_bool.h>
85 #include <webots_ros/field_set_color.h>
86 #include <webots_ros/field_set_float.h>
87 #include <webots_ros/field_set_int32.h>
88 #include <webots_ros/field_set_rotation.h>
89 #include <webots_ros/field_set_string.h>
90 #include <webots_ros/field_set_vec2f.h>
91 #include <webots_ros/field_set_vec3f.h>
92 #include <webots_ros/lidar_get_frequency_info.h>
93 #include <webots_ros/lidar_get_info.h>
94 #include <webots_ros/motor_set_control_pid.h>
95 #include <webots_ros/node_add_force_or_torque.h>
96 #include <webots_ros/node_add_force_with_offset.h>
97 #include <webots_ros/node_get_center_of_mass.h>
98 #include <webots_ros/node_get_contact_point.h>
99 #include <webots_ros/node_get_field.h>
100 #include <webots_ros/node_get_id.h>
101 #include <webots_ros/node_get_name.h>
102 #include <webots_ros/node_get_number_of_contact_points.h>
103 #include <webots_ros/node_get_orientation.h>
104 #include <webots_ros/node_get_parent_node.h>
105 #include <webots_ros/node_get_position.h>
106 #include <webots_ros/node_get_static_balance.h>
107 #include <webots_ros/node_get_status.h>
108 #include <webots_ros/node_get_type.h>
109 #include <webots_ros/node_get_velocity.h>
110 #include <webots_ros/node_remove.h>
111 #include <webots_ros/node_reset_functions.h>
112 #include <webots_ros/node_set_velocity.h>
113 #include <webots_ros/node_set_visibility.h>
114 #include <webots_ros/pen_set_ink_color.h>
115 #include <webots_ros/range_finder_get_info.h>
116 #include <webots_ros/receiver_get_emitter_direction.h>
117 #include <webots_ros/robot_get_device_list.h>
118 #include <webots_ros/robot_set_mode.h>
119 #include <webots_ros/robot_wait_for_user_input_event.h>
120 #include <webots_ros/save_image.h>
121 #include <webots_ros/speaker_play_sound.h>
122 #include <webots_ros/speaker_speak.h>
123 #include <webots_ros/supervisor_get_from_def.h>
124 #include <webots_ros/supervisor_get_from_id.h>
125 #include <webots_ros/supervisor_movie_start_recording.h>
126 #include <webots_ros/supervisor_set_label.h>
127 #include <webots_ros/supervisor_virtual_reality_headset_get_orientation.h>
128 #include <webots_ros/supervisor_virtual_reality_headset_get_position.h>
129 
130 #define TIME_STEP 32
131 
132 using namespace std;
133 
134 static int model_count;
135 static vector<string> model_list;
136 static vector<unsigned char> imageColor;
137 static vector<float> imageRangeFinder;
138 static int connectorPresence = 0;
139 static double accelerometerValues[3] = {0, 0, 0};
140 static double compassValues[3] = {0, 0, 0};
141 static double GPSValues[3] = {0, 0, 0};
142 static double GyroValues[3] = {0, 0, 0};
143 static double inertialUnitValues[4] = {0, 0, 0, 0};
144 static double touchSensorValues[3] = {0, 0, 0};
145 static bool callbackCalled = false;
146 
148 webots_ros::set_int time_step_srv;
149 
150 void modelNameCallback(const std_msgs::String::ConstPtr &name) {
151  model_count++;
152  model_list.push_back(name->data);
153  ROS_INFO("Model #%d: %s.", model_count, model_list.back().c_str());
154  callbackCalled = true;
155 }
156 
157 void cameraCallback(const sensor_msgs::Image::ConstPtr &values) {
158  int i = 0;
159  imageColor.resize(values->step * values->height);
160  for (std::vector<unsigned char>::const_iterator it = values->data.begin(); it != values->data.end(); ++it) {
161  imageColor[i] = *it;
162  i++;
163  }
164  callbackCalled = true;
165 }
166 
167 void cameraRecognitionCallback(const webots_ros::RecognitionObject::ConstPtr &object) {
168  ROS_INFO("Camera recognition saw a '%s' (time: %d:%d).", object->model.c_str(), object->header.stamp.sec,
169  object->header.stamp.nsec);
170  callbackCalled = true;
171 }
172 
173 void joystickCallback(const webots_ros::Int8Stamped::ConstPtr &value) {
174  ROS_INFO("Joystick button pressed: %d (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
175  callbackCalled = true;
176 }
177 
178 void keyboardCallback(const webots_ros::Int32Stamped::ConstPtr &value) {
179  ROS_INFO("Keyboard key pressed: %d (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
180  callbackCalled = true;
181 }
182 
183 void radarTargetsCallback(const webots_ros::RadarTarget::ConstPtr &target) {
184  ROS_INFO("Received a radar target with distance=%lf received power=%lf speed=%lf azimuth=%lf (time: %d:%d).",
185  target->distance, target->receivedPower, target->speed, target->azimuth, target->header.stamp.sec,
186  target->header.stamp.nsec);
187  callbackCalled = true;
188 }
189 
190 void radarTargetsNumberCallback(const webots_ros::Int8Stamped::ConstPtr &value) {
191  ROS_INFO("Number of target seen by the radar: %d (time: %d:%d).", value->data, value->header.stamp.sec,
192  value->header.stamp.nsec);
193  callbackCalled = true;
194 }
195 
196 void rangeFinderCallback(const sensor_msgs::Image::ConstPtr &image) {
197  int size = image->width * image->height;
198  imageRangeFinder.resize(size);
199 
200  const float *depth_data = reinterpret_cast<const float *>(&image->data[0]);
201  for (int i = 0; i < size; ++i)
202  imageRangeFinder[i] = depth_data[i];
203  callbackCalled = true;
204 }
205 
206 void lidarCallback(const sensor_msgs::Image::ConstPtr &image) {
207  callbackCalled = true;
208 }
209 
210 void connectorCallback(const webots_ros::Int8Stamped::ConstPtr &value) {
211  connectorPresence = value->data;
212 
213  ROS_INFO("Connector presence: %d (time: %d:%d).", connectorPresence, value->header.stamp.sec, value->header.stamp.nsec);
214  callbackCalled = true;
215 }
216 
217 void accelerometerCallback(const sensor_msgs::Imu::ConstPtr &values) {
218  accelerometerValues[0] = values->linear_acceleration.x;
219  accelerometerValues[1] = values->linear_acceleration.y;
220  accelerometerValues[2] = values->linear_acceleration.z;
221 
222  ROS_INFO("Accelerometer values are x=%f y=%f z=%f (time: %d:%d).", accelerometerValues[0], accelerometerValues[1],
223  accelerometerValues[2], values->header.stamp.sec, values->header.stamp.nsec);
224  callbackCalled = true;
225 }
226 
227 void battery_sensorCallback(const webots_ros::Float64Stamped::ConstPtr &value) {
228  ROS_INFO("Battery level is %f (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
229  callbackCalled = true;
230 }
231 
232 void compassCallback(const sensor_msgs::MagneticField::ConstPtr &values) {
233  compassValues[0] = values->magnetic_field.x;
234  compassValues[1] = values->magnetic_field.y;
235  compassValues[2] = values->magnetic_field.z;
236 
237  ROS_INFO("Compass values are x=%f y=%f z=%f (time: %d:%d).", compassValues[0], compassValues[1], compassValues[2],
238  values->header.stamp.sec, values->header.stamp.nsec);
239  callbackCalled = true;
240 }
241 
242 void distance_sensorCallback(const sensor_msgs::Range::ConstPtr &value) {
243  ROS_INFO("Distance from object is %f (time: %d:%d).", value->range, value->header.stamp.sec, value->header.stamp.nsec);
244  callbackCalled = true;
245 }
246 
247 void GPSCallback(const sensor_msgs::NavSatFix::ConstPtr &values) {
248  GPSValues[0] = values->latitude;
249  GPSValues[1] = values->altitude;
250  GPSValues[2] = values->longitude;
251 
252  ROS_INFO("GPS values are x=%f y=%f z=%f (time: %d:%d).", GPSValues[0], GPSValues[1], GPSValues[2], values->header.stamp.sec,
253  values->header.stamp.nsec);
254  callbackCalled = true;
255 }
256 
257 void GPSSpeedCallback(const webots_ros::Float64Stamped::ConstPtr &value) {
258  ROS_INFO("GPS speed is: %fkm/h (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
259  callbackCalled = true;
260 }
261 
262 void gyroCallback(const sensor_msgs::Imu::ConstPtr &values) {
263  GyroValues[0] = values->angular_velocity.x;
264  GyroValues[1] = values->angular_velocity.y;
265  GyroValues[2] = values->angular_velocity.z;
266 
267  ROS_INFO("Gyro values are x=%f y=%f z=%f (time: %d:%d).", GyroValues[0], GyroValues[1], GyroValues[2],
268  values->header.stamp.sec, values->header.stamp.nsec);
269  callbackCalled = true;
270 }
271 
272 void inertialUnitCallback(const sensor_msgs::Imu::ConstPtr &values) {
273  inertialUnitValues[0] = values->orientation.x;
274  inertialUnitValues[1] = values->orientation.y;
275  inertialUnitValues[2] = values->orientation.z;
276  inertialUnitValues[3] = values->orientation.w;
277 
278  ROS_INFO("Inertial unit values (quaternions) are x=%f y=%f z=%f w=%f (time: %d:%d).", inertialUnitValues[0],
279  inertialUnitValues[1], inertialUnitValues[2], inertialUnitValues[2], values->header.stamp.sec,
280  values->header.stamp.nsec);
281  callbackCalled = true;
282 }
283 
284 void lightSensorCallback(const sensor_msgs::Illuminance::ConstPtr &value) {
285  ROS_INFO("Light intensity is %f.", value->illuminance);
286  callbackCalled = true;
287 }
288 
289 void motorSensorCallback(const webots_ros::Float64Stamped::ConstPtr &value) {
290  ROS_INFO("Motor sensor sent value %f.", value->data);
291  callbackCalled = true;
292 }
293 
294 void positionSensorCallback(const webots_ros::Float64Stamped::ConstPtr &value) {
295  ROS_INFO("Position sensor sent value %f (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
296  callbackCalled = true;
297 }
298 
299 void touchSensorCallback(const webots_ros::Float64Stamped::ConstPtr &value) {
300  ROS_INFO("Touch sensor sent value %f (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
301  callbackCalled = true;
302 }
303 
304 void touchSensorBumperCallback(const webots_ros::BoolStamped::ConstPtr &value) {
305  ROS_INFO("Touch sensor sent value %d (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
306  callbackCalled = true;
307 }
308 
309 void touchSensor3DCallback(const geometry_msgs::WrenchStamped::ConstPtr &values) {
310  touchSensorValues[0] = values->wrench.force.x;
311  touchSensorValues[1] = values->wrench.force.y;
312  touchSensorValues[2] = values->wrench.force.z;
313 
314  ROS_INFO("Touch sensor values are x = %f, y = %f and z = %f (time: %d:%d).", touchSensorValues[0], touchSensorValues[1],
315  touchSensorValues[2], values->header.stamp.sec, values->header.stamp.nsec);
316  callbackCalled = true;
317 }
318 
319 void receiverCallback(const webots_ros::StringStamped::ConstPtr &value) {
320  char *message = const_cast<char *>(value->data.c_str());
321  ROS_INFO("Received a message %s.", message);
322  callbackCalled = true;
323 }
324 
325 void quit(int sig) {
326  time_step_srv.request.value = 0;
327  time_step_client.call(time_step_srv);
328  ROS_INFO("User stopped the 'complete_test' node.");
329  ros::shutdown();
330  exit(0);
331 }
332 
333 int main(int argc, char **argv) {
334  string model_name = "my_robot";
335 
336  ros::init(argc, argv, "complete_test", ros::init_options::AnonymousName);
338 
339  signal(SIGINT, quit);
340 
341  ros::Subscriber name_sub = n.subscribe("model_name", 100, modelNameCallback);
342  while (model_count == 0 || model_count < name_sub.getNumPublishers()) {
343  ros::spinOnce();
344  ros::spinOnce();
345  ros::spinOnce();
346  }
347  ros::spinOnce();
348  name_sub.shutdown();
349 
351  // ROBOT METHODS TEST //
353 
354  int mode = 0;
355  string model;
356  string path;
357  string data;
358  vector<string> device_list;
359 
360  time_step_client = n.serviceClient<webots_ros::set_int>(model_name + "/robot/time_step");
361  time_step_srv.request.value = TIME_STEP;
362 
363  if (time_step_client.call(time_step_srv) && time_step_srv.response.success)
364  ROS_INFO("time_step service works.");
365  else
366  ROS_ERROR("Failed to call service time_step to update robot's time step.");
367 
368  ros::ServiceClient get_number_of_devices_client =
369  n.serviceClient<webots_ros::get_int>(model_name + "/robot/get_number_of_devices");
370  webots_ros::get_int get_number_of_devices_srv;
371 
372  if (get_number_of_devices_client.call(get_number_of_devices_srv)) {
373  int number_of_devices = get_number_of_devices_srv.response.value;
374  ROS_INFO("%s has %d devices.", model_name.c_str(), number_of_devices);
375  } else
376  ROS_ERROR("Failed to call service get_number_of_devices.");
377 
378  get_number_of_devices_client.shutdown();
379  time_step_client.call(time_step_srv);
380 
381  ros::ServiceClient device_list_client =
382  n.serviceClient<webots_ros::robot_get_device_list>(model_name + "/robot/get_device_list");
383  webots_ros::robot_get_device_list device_list_srv;
384 
385  if (device_list_client.call(device_list_srv)) {
386  device_list = device_list_srv.response.list;
387  for (unsigned int i = 0; i < device_list.size(); i++)
388  ROS_INFO("Device [%d]: %s.", i, device_list[i].c_str());
389  } else
390  ROS_ERROR("Failed to call service device_list.");
391 
392  device_list_client.shutdown();
393  time_step_client.call(time_step_srv);
394 
395  ros::ServiceClient urdf_client = n.serviceClient<webots_ros::get_urdf>(model_name + "/robot/get_urdf");
396  webots_ros::get_urdf urdf_srv;
397  urdf_srv.request.prefix = "unique_robot_prefix_name_";
398 
399  if (urdf_client.call(urdf_srv)) {
400  std::string urdf = urdf_srv.response.value;
401  if (urdf.find(urdf_srv.request.prefix) == std::string::npos)
402  ROS_ERROR("Invalid response from get_urdf.");
403  else
404  ROS_INFO("URDF has been successfully obtained.");
405  } else
406  ROS_ERROR("Failed to call service get_urdf.");
407 
408  urdf_client.shutdown();
409  time_step_client.call(time_step_srv);
410 
411  ros::ServiceClient get_basic_time_step_client =
412  n.serviceClient<webots_ros::get_float>(model_name + "/robot/get_basic_time_step");
413  webots_ros::get_float get_basic_time_step_srv;
414 
415  if (get_basic_time_step_client.call(get_basic_time_step_srv)) {
416  double basic_time_step = get_basic_time_step_srv.response.value;
417  ROS_INFO("%s has a basic time step of %f.", model_name.c_str(), basic_time_step);
418  } else
419  ROS_ERROR("Failed to call service get_basic_time_step.");
420 
421  get_basic_time_step_client.shutdown();
422  time_step_client.call(time_step_srv);
423 
424  ros::ServiceClient robot_get_custom_data_client =
425  n.serviceClient<webots_ros::get_string>(model_name + "/robot/get_custom_data");
426  webots_ros::get_string robot_get_custom_data_srv;
427 
428  if (robot_get_custom_data_client.call(robot_get_custom_data_srv)) {
429  data = robot_get_custom_data_srv.response.value;
430  ROS_INFO("Data of %s is %s.", model_name.c_str(), data.c_str());
431  } else
432  ROS_ERROR("Failed to call service robot_get_custom_data.");
433 
434  robot_get_custom_data_client.shutdown();
435  time_step_client.call(time_step_srv);
436 
437  ros::ServiceClient get_mode_client = n.serviceClient<webots_ros::get_int>(model_name + "/robot/get_mode");
438  webots_ros::get_int get_mode_srv;
439 
440  if (get_mode_client.call(get_mode_srv)) {
441  mode = get_mode_srv.response.value;
442  ROS_INFO("Mode of %s is %d.", model_name.c_str(), mode);
443  } else
444  ROS_ERROR("Failed to call service get_mode.");
445 
446  get_mode_client.shutdown();
447  time_step_client.call(time_step_srv);
448 
449  ros::ServiceClient get_model_client = n.serviceClient<webots_ros::get_string>(model_name + "/robot/get_model");
450  webots_ros::get_string get_model_srv;
451 
452  if (get_model_client.call(get_model_srv)) {
453  model = get_model_srv.response.value;
454  ROS_INFO("Model of %s is %s.", model_name.c_str(), model.c_str());
455  } else
456  ROS_ERROR("Failed to call service get_model.");
457 
458  get_model_client.shutdown();
459  time_step_client.call(time_step_srv);
460 
461  ros::ServiceClient get_project_path_client = n.serviceClient<webots_ros::get_string>(model_name + "/robot/get_project_path");
462  webots_ros::get_string get_project_path_srv;
463 
464  if (get_project_path_client.call(get_project_path_srv)) {
465  path = get_project_path_srv.response.value;
466  ROS_INFO("World path of %s is %s.", model_name.c_str(), path.c_str());
467  } else
468  ROS_ERROR("Failed to call service get_project_path.");
469 
470  get_project_path_client.shutdown();
471  time_step_client.call(time_step_srv);
472 
473  // robot_get_world_path
474  ros::ServiceClient get_world_path_client = n.serviceClient<webots_ros::get_string>(model_name + "/robot/get_world_path");
475  webots_ros::get_string get_world_path_srv;
476 
477  if (get_world_path_client.call(get_world_path_srv)) {
478  path = get_world_path_srv.response.value;
479  ROS_INFO("Project path of %s is %s.", model_name.c_str(), path.c_str());
480  } else
481  ROS_ERROR("Failed to call service get_project_path.");
482 
483  get_world_path_client.shutdown();
484  time_step_client.call(time_step_srv);
485 
486  ros::ServiceClient get_supervisor_client = n.serviceClient<webots_ros::get_bool>(model_name + "/robot/get_supervisor");
487  webots_ros::get_bool get_supervisor_srv;
488 
489  if (get_supervisor_client.call(get_supervisor_srv)) {
490  if (get_supervisor_srv.response.value)
491  ROS_INFO("%s is a supervisor.", model_name.c_str());
492  else
493  ROS_ERROR("%s isn't a supervisor.", model_name.c_str());
494  } else
495  ROS_ERROR("Failed to call service get_synchronization.");
496 
497  get_supervisor_client.shutdown();
498  time_step_client.call(time_step_srv);
499 
500  ros::ServiceClient get_synchronization_client =
501  n.serviceClient<webots_ros::get_bool>(model_name + "/robot/get_synchronization");
502  webots_ros::get_bool get_synchronization_srv;
503 
504  if (get_synchronization_client.call(get_synchronization_srv)) {
505  bool synchronization = get_synchronization_srv.response.value;
506  if (synchronization)
507  ROS_INFO("%s is sync.", model_name.c_str());
508  else
509  ROS_INFO("%s isn't sync.", model_name.c_str());
510  } else
511  ROS_ERROR("Failed to call service get_synchronization.");
512 
513  get_synchronization_client.shutdown();
514  time_step_client.call(time_step_srv);
515 
516  ros::ServiceClient get_time_client = n.serviceClient<webots_ros::get_float>(model_name + "/robot/get_time");
517  webots_ros::get_float get_time_srv;
518 
519  if (get_time_client.call(get_time_srv)) {
520  double time = get_time_srv.response.value;
521  ROS_INFO("Time for %s is %f.", model_name.c_str(), time);
522  } else
523  ROS_ERROR("Failed to call service get_time.");
524 
525  get_time_client.shutdown();
526  time_step_client.call(time_step_srv);
527 
528  ros::ServiceClient get_type_client = n.serviceClient<webots_ros::get_int>(model_name + "/robot/get_type");
529  webots_ros::get_int get_type_srv;
530 
531  if (get_type_client.call(get_type_srv)) {
532  int type = get_type_srv.response.value;
533  ROS_INFO("Type of %s is %d.", model_name.c_str(), type);
534  } else
535  ROS_ERROR("Failed to call service get_type.");
536 
537  get_type_client.shutdown();
538  time_step_client.call(time_step_srv);
539 
540  ros::ServiceClient robot_set_custom_data_client =
541  n.serviceClient<webots_ros::set_string>(model_name + "/robot/set_custom_data");
542  webots_ros::set_string robot_set_custom_data_srv;
543 
544  robot_set_custom_data_srv.request.value = "OVERWRITTEN";
545  if (robot_set_custom_data_client.call(robot_set_custom_data_srv)) {
546  if (robot_set_custom_data_srv.response.success)
547  ROS_INFO("Data of %s has been set to %s.", model_name.c_str(), data.c_str());
548  } else
549  ROS_ERROR("Failed to call service robot_set_custom_data.");
550 
551  robot_set_custom_data_client.shutdown();
552  time_step_client.call(time_step_srv);
553 
554  ros::ServiceClient set_mode_client = n.serviceClient<webots_ros::robot_set_mode>(model_name + "/robot/set_mode");
555  webots_ros::robot_set_mode set_mode_srv;
556 
557  set_mode_srv.request.mode = mode;
558  if (set_mode_client.call(set_mode_srv)) {
559  if (set_mode_srv.response.success == 1)
560  ROS_INFO("Mode of %s has been set to %d.", model_name.c_str(), mode);
561  } else
562  ROS_ERROR("Failed to call service set_mode.");
563 
564  set_mode_client.shutdown();
565  time_step_client.call(time_step_srv);
566 
567  ros::ServiceClient enable_keyboard_client = n.serviceClient<webots_ros::set_int>(model_name + "/keyboard/enable");
568  webots_ros::set_int enable_keyboard_srv;
569  ros::Subscriber sub_keyboard;
570 
571  enable_keyboard_srv.request.value = 32;
572  if (enable_keyboard_client.call(enable_keyboard_srv) && enable_keyboard_srv.response.success) {
573  ROS_INFO("Keyboard of %s has been enabled.", model_name.c_str());
574  sub_keyboard = n.subscribe(model_name + "/keyboard/key", 1, keyboardCallback);
575  ROS_INFO("Topics for keyboard initialized.");
576  callbackCalled = false;
577  while (sub_keyboard.getNumPublishers() == 0 && !callbackCalled) {
578  ros::spinOnce();
579  time_step_client.call(time_step_srv);
580  }
581  ROS_INFO("Topics for keyboard connected.");
582  } else
583  ROS_ERROR("Failed to enable keyboard.");
584 
585  ros::ServiceClient wait_for_user_input_event_client =
586  n.serviceClient<webots_ros::robot_wait_for_user_input_event>(model_name + "/robot/wait_for_user_input_event");
587  webots_ros::robot_wait_for_user_input_event wait_for_user_input_event_srv;
588 
589  wait_for_user_input_event_srv.request.eventType = 4; // WB_EVENT_KEYBOARD
590  wait_for_user_input_event_srv.request.timeout = 20;
591  if (wait_for_user_input_event_client.call(wait_for_user_input_event_srv))
592  ROS_INFO("Detected user input event: %d.", wait_for_user_input_event_srv.response.event);
593  else
594  ROS_ERROR("Failed to call service wait_for_user_input_event.");
595 
596  wait_for_user_input_event_client.shutdown();
597  time_step_client.call(time_step_srv);
598 
599  sub_keyboard.shutdown();
600  enable_keyboard_client.shutdown();
601  time_step_client.call(time_step_srv);
602 
604  // BREAK METHODS TEST //
606 
607  // brake_set_damping_constant
608  ros::ServiceClient brake_set_client = n.serviceClient<webots_ros::set_float>(model_name + "/my_brake/set_damping_constant");
609  webots_ros::set_float brake_set_srv;
610  brake_set_srv.request.value = 0.55;
611  if (brake_set_client.call(brake_set_srv) && brake_set_srv.response.success)
612  ROS_INFO("Brake damping constant set to 0.55.");
613  else
614  ROS_ERROR("Failed to call service brake_set_damping_constant.");
615 
616  brake_set_client.shutdown();
617  time_step_client.call(time_step_srv);
618 
619  // brake_get_motor_name
620  ros::ServiceClient brake_get_motor_name_client =
621  n.serviceClient<webots_ros::get_string>(model_name + "/my_brake/get_motor_name");
622  webots_ros::get_string brake_get_motor_name_srv;
623  if (brake_get_motor_name_client.call(brake_get_motor_name_srv)) {
624  ROS_INFO("Linear motor name returned from Brake API %s.", brake_get_motor_name_srv.response.value.c_str());
625  if (brake_get_motor_name_srv.response.value.compare("linear_motor") != 0)
626  ROS_ERROR("Failed to call service brake_get_motor_name: received '%s' instead of 'linear_motor'",
627  brake_get_motor_name_srv.response.value.c_str());
628  } else
629  ROS_ERROR("Failed to call service brake_get_motor_name.");
630 
631  brake_get_motor_name_client.shutdown();
632  time_step_client.call(time_step_srv);
633 
635  // CAMERA METHODS TEST //
637 
638  // camera_set_focal_distance
639  double focal_distance = 0.33;
640  ros::ServiceClient camera_set_client = n.serviceClient<webots_ros::set_float>(model_name + "/camera/set_focal_distance");
641  webots_ros::set_float camera_set_focal_distance_srv;
642  camera_set_focal_distance_srv.request.value = focal_distance;
643  if (camera_set_client.call(camera_set_focal_distance_srv) && camera_set_focal_distance_srv.response.success)
644  ROS_INFO("Camera focal distance set to %f.", focal_distance);
645  else
646  ROS_ERROR("Failed to call service camera_set_focal_distance.");
647 
648  camera_set_client.shutdown();
649  time_step_client.call(time_step_srv);
650 
651  // camera_set_fov
652  double fov = 1.33;
653  camera_set_client = n.serviceClient<webots_ros::set_float>(model_name + "/camera/set_fov");
654  webots_ros::set_float camera_set_fov_srv;
655  camera_set_fov_srv.request.value = fov;
656  if (camera_set_client.call(camera_set_fov_srv) && camera_set_fov_srv.response.success)
657  ROS_INFO("Camera fov set to %f.", fov);
658  else
659  ROS_ERROR("Failed to call service camera_set_fov.");
660 
661  camera_set_client.shutdown();
662  time_step_client.call(time_step_srv);
663 
664  // camera enable
665  ros::ServiceClient enable_camera_client;
666  webots_ros::set_int camera_srv;
667  ros::Subscriber sub_camera_color;
668 
669  enable_camera_client = n.serviceClient<webots_ros::set_int>(model_name + "/camera/enable");
670  camera_srv.request.value = TIME_STEP;
671  if (enable_camera_client.call(camera_srv) && camera_srv.response.success) {
672  ROS_INFO("Camera enabled.");
673  sub_camera_color = n.subscribe(model_name + "/camera/image", 1, cameraCallback);
674  ROS_INFO("Topic for camera color initialized.");
675  callbackCalled = false;
676  while (sub_camera_color.getNumPublishers() == 0 && !callbackCalled) {
677  ros::spinOnce();
678  time_step_client.call(time_step_srv);
679  }
680  ROS_INFO("Topic for camera color connected.");
681  } else {
682  if (camera_srv.response.success == -1)
683  ROS_ERROR("Sampling period is not valid.");
684  ROS_ERROR("Failed to enable camera.");
685  return 1;
686  }
687 
688  sub_camera_color.shutdown();
689  enable_camera_client.shutdown();
690  time_step_client.call(time_step_srv);
691 
692  // camera_get_info
693  ros::ServiceClient get_info_client = n.serviceClient<webots_ros::camera_get_info>(model_name + "/camera/get_info");
694  webots_ros::camera_get_info get_info_srv;
695  if (get_info_client.call(get_info_srv))
696  ROS_INFO("Camera of %s has a width of %d, a height of %d, a field of view of %f, a near range of %f.", model_name.c_str(),
697  get_info_srv.response.width, get_info_srv.response.height, get_info_srv.response.Fov,
698  get_info_srv.response.nearRange);
699  else
700  ROS_ERROR("Failed to call service camera_get_info.");
701  if (get_info_srv.response.Fov != fov)
702  ROS_ERROR("Failed to set camera fov.");
703 
704  get_info_client.shutdown();
705  time_step_client.call(time_step_srv);
706 
707  // camera_get_focus_info
708  get_info_client = n.serviceClient<webots_ros::camera_get_focus_info>(model_name + "/camera/get_focus_info");
709  webots_ros::camera_get_focus_info camera_get_focus_info_srv;
710  if (get_info_client.call(camera_get_focus_info_srv))
711  ROS_INFO("Camera of %s has focalLength %f, focalDistance %f, maxFocalDistance %f, and minFocalDistance %f.",
712  model_name.c_str(), camera_get_focus_info_srv.response.focalLength,
713  camera_get_focus_info_srv.response.focalDistance, camera_get_focus_info_srv.response.maxFocalDistance,
714  camera_get_focus_info_srv.response.minFocalDistance);
715  else
716  ROS_ERROR("Failed to call service camera_get_focus_info.");
717  if (camera_get_focus_info_srv.response.focalDistance != focal_distance)
718  ROS_ERROR("Failed to set camera focal distance.");
719 
720  get_info_client.shutdown();
721  time_step_client.call(time_step_srv);
722 
723  // camera_get_zoom_info
724  get_info_client = n.serviceClient<webots_ros::camera_get_zoom_info>(model_name + "/camera/get_zoom_info");
725  webots_ros::camera_get_zoom_info camera_get_zoom_info_srv;
726  if (get_info_client.call(camera_get_zoom_info_srv))
727  ROS_INFO("Camera of %s has min fov %f, anf max fov %f.", model_name.c_str(), camera_get_zoom_info_srv.response.minFov,
728  camera_get_zoom_info_srv.response.maxFov);
729  else
730  ROS_ERROR("Failed to call service camera_get_zoom_info.");
731 
732  get_info_client.shutdown();
733  time_step_client.call(time_step_srv);
734 
735  // check presence of recognition capability
736  get_info_client = n.serviceClient<webots_ros::get_bool>(model_name + "/camera/has_recognition");
737  webots_ros::get_bool camera_has_recognition_srv;
738  if (get_info_client.call(camera_has_recognition_srv))
739  if (camera_has_recognition_srv.response.value)
740  ROS_INFO("Recognition capability of camera of %s found.", model_name.c_str());
741  else
742  ROS_ERROR("Recognition capability of camera of %s not found.", model_name.c_str());
743  else
744  ROS_ERROR("Failed to call service camera_get_zoom_info.");
745 
746  get_info_client.shutdown();
747  time_step_client.call(time_step_srv);
748 
749  // camera recognition enable
750  ros::ServiceClient enable_camera_recognition_client;
751  webots_ros::set_int camera_recognition_srv;
752  ros::Subscriber sub_camera_recognition;
753 
754  enable_camera_recognition_client = n.serviceClient<webots_ros::set_int>(model_name + "/camera/recognition_enable");
755  camera_recognition_srv.request.value = TIME_STEP;
756  if (enable_camera_recognition_client.call(camera_recognition_srv) && camera_recognition_srv.response.success) {
757  ROS_INFO("Camera recognition enabled.");
758  sub_camera_recognition = n.subscribe(model_name + "/camera/recognition_objects", 1, cameraRecognitionCallback);
759  ROS_INFO("Topic for camera recognition initialized.");
760  callbackCalled = false;
761  while (sub_camera_recognition.getNumPublishers() == 0 && !callbackCalled) {
762  ros::spinOnce();
763  time_step_client.call(time_step_srv);
764  }
765  ROS_INFO("Topic for camera recognition connected.");
766  } else {
767  if (camera_recognition_srv.response.success == -1)
768  ROS_ERROR("Sampling period is not valid.");
769  ROS_ERROR("Failed to enable camera recognition.");
770  return 1;
771  }
772 
773  sub_camera_recognition.shutdown();
774  enable_camera_recognition_client.shutdown();
775  time_step_client.call(time_step_srv);
776 
777  // camera_save_image
778  ros::ServiceClient save_image_client = n.serviceClient<webots_ros::save_image>(model_name + "/camera/save_image");
779  webots_ros::save_image save_image_srv;
780  save_image_srv.request.filename = std::string(getenv("HOME")) + std::string("/test_image_camera.png");
781  save_image_srv.request.quality = 100;
782 
783  if (save_image_client.call(save_image_srv) && save_image_srv.response.success == 1)
784  ROS_INFO("Image saved.");
785  else
786  ROS_ERROR("Failed to call service save_image.");
787 
788  save_image_client.shutdown();
789  time_step_client.call(time_step_srv);
790 
791  ROS_INFO("Camera disabled.");
792 
794  // DEVICE METHODS TEST //
796 
797  // device_get_name
798  ros::ServiceClient device_get_name_client = n.serviceClient<webots_ros::get_string>(model_name + "/camera/get_name");
799  webots_ros::get_string device_get_name_srv;
800  if (device_get_name_client.call(device_get_name_srv))
801  ROS_INFO("Camera device name: %s.", device_get_name_srv.response.value.c_str());
802  else
803  ROS_ERROR("Failed to call service get_name.");
804 
805  device_get_name_client.shutdown();
806  time_step_client.call(time_step_srv);
807 
808  // device_get_name
809  ros::ServiceClient device_get_model_client = n.serviceClient<webots_ros::get_string>(model_name + "/camera/get_model");
810  webots_ros::get_string device_get_model_srv;
811  if (device_get_model_client.call(device_get_model_srv))
812  ROS_INFO("Camera device model: %s.", device_get_model_srv.response.value.c_str());
813  else
814  ROS_ERROR("Failed to call service get_model.");
815 
816  device_get_model_client.shutdown();
817  time_step_client.call(time_step_srv);
818 
820  // ACCELEROMETER METHODS TEST //
822 
823  ros::ServiceClient set_accelerometer_client;
824  webots_ros::set_int accelerometer_srv;
825  ros::Subscriber sub_accelerometer_32;
826  ros::Subscriber sub_accelerometer_64;
827 
828  set_accelerometer_client = n.serviceClient<webots_ros::set_int>(model_name + "/accelerometer/enable");
829 
830  accelerometer_srv.request.value = 64;
831  if (set_accelerometer_client.call(accelerometer_srv) && accelerometer_srv.response.success) {
832  sub_accelerometer_64 = n.subscribe(model_name + "/accelerometer/values", 1, accelerometerCallback);
833  callbackCalled = false;
834  while (sub_accelerometer_64.getNumPublishers() == 0 && !callbackCalled) {
835  ros::spinOnce();
836  time_step_client.call(time_step_srv);
837  }
838  } else {
839  if (accelerometer_srv.response.success == -1)
840  ROS_ERROR("Sampling period is not valid.");
841  ROS_ERROR("Failed to enable accelerometer.");
842  return 1;
843  }
844 
845  sub_accelerometer_64.shutdown();
846  time_step_client.call(time_step_srv);
847 
848  ros::ServiceClient sampling_period_accelerometer_client;
849  webots_ros::get_int sampling_period_accelerometer_srv;
850 
851  sampling_period_accelerometer_client =
852  n.serviceClient<webots_ros::get_int>(model_name + "/accelerometer/get_sampling_period");
853  sampling_period_accelerometer_client.call(sampling_period_accelerometer_srv);
854  ROS_INFO("Accelerometer is enabled with a sampling period of %d.", sampling_period_accelerometer_srv.response.value);
855 
856  accelerometer_srv.request.value = 32;
857  if (set_accelerometer_client.call(accelerometer_srv) && accelerometer_srv.response.success) {
858  sub_accelerometer_32 = n.subscribe(model_name + "/accelerometer/values", 1, accelerometerCallback);
859  callbackCalled = false;
860  while (sub_accelerometer_32.getNumPublishers() == 0 && !callbackCalled) {
861  ros::spinOnce();
862  time_step_client.call(time_step_srv);
863  }
864  } else {
865  if (accelerometer_srv.response.success == -1)
866  ROS_ERROR("Sampling period is not valid.");
867  ROS_ERROR("Failed to enable accelerometer.");
868  return 1;
869  }
870 
871  ros::ServiceClient lookup_table_accelerometer_client;
872  webots_ros::get_float_array lookup_table_accelerometer_srv;
873  lookup_table_accelerometer_client =
874  n.serviceClient<webots_ros::get_float_array>(model_name + "/accelerometer/get_lookup_table");
875  if (lookup_table_accelerometer_client.call(lookup_table_accelerometer_srv))
876  ROS_INFO("Accelerometer lookup table size = %lu.", lookup_table_accelerometer_srv.response.value.size());
877  else
878  ROS_ERROR("Failed to get the lookup table of 'accelerometer'.");
879  if (lookup_table_accelerometer_srv.response.value.size() != 0)
880  ROS_ERROR("Size of lookup table of 'accelerometer' is wrong.");
881  lookup_table_accelerometer_client.shutdown();
882 
883  sub_accelerometer_32.shutdown();
884  set_accelerometer_client.shutdown();
885  time_step_client.call(time_step_srv);
886 
887  sampling_period_accelerometer_client.call(sampling_period_accelerometer_srv);
888  ROS_INFO("Accelerometer is enabled with a sampling period of %d.", sampling_period_accelerometer_srv.response.value);
889 
890  // wait for webots to detect shutdown of topics and to disable the sensor afterwards
891  time_step_client.call(time_step_srv);
892  time_step_client.call(time_step_srv);
893  time_step_client.call(time_step_srv);
894 
895  sampling_period_accelerometer_client.call(sampling_period_accelerometer_srv);
896  ROS_INFO("Accelerometer is disabled (sampling period is %d).", sampling_period_accelerometer_srv.response.value);
897 
898  sampling_period_accelerometer_client.shutdown();
899  time_step_client.call(time_step_srv);
900 
902  // BATTERY SENSOR METHODS TEST //
904 
905  ros::ServiceClient set_battery_sensor_client;
906  webots_ros::set_int battery_sensor_srv;
907  ros::Subscriber sub_battery_sensor_32;
908  set_battery_sensor_client = n.serviceClient<webots_ros::set_int>(model_name + "/battery_sensor/enable");
909 
910  ros::ServiceClient sampling_period_battery_sensor_client;
911  webots_ros::get_int sampling_period_battery_sensor_srv;
912  sampling_period_battery_sensor_client =
913  n.serviceClient<webots_ros::get_int>(model_name + "/battery_sensor/get_sampling_period");
914 
915  battery_sensor_srv.request.value = 32;
916  if (set_battery_sensor_client.call(battery_sensor_srv) && battery_sensor_srv.response.success) {
917  ROS_INFO("Battery_sensor enabled.");
918  sub_battery_sensor_32 = n.subscribe(model_name + "/battery_sensor/value", 1, battery_sensorCallback);
919  callbackCalled = false;
920  while (sub_battery_sensor_32.getNumPublishers() == 0 && !callbackCalled) {
921  ros::spinOnce();
922  time_step_client.call(time_step_srv);
923  }
924  } else {
925  if (!battery_sensor_srv.response.success)
926  ROS_ERROR("Sampling period is not valid.");
927  ROS_ERROR("Failed to enable battery_sensor.");
928  return 1;
929  }
930 
931  sub_battery_sensor_32.shutdown();
932 
933  time_step_client.call(time_step_srv);
934 
935  sampling_period_battery_sensor_client.call(sampling_period_battery_sensor_srv);
936  ROS_INFO("Battery_sensor is enabled with a sampling period of %d.", sampling_period_battery_sensor_srv.response.value);
937 
938  time_step_client.call(time_step_srv);
939 
940  time_step_client.call(time_step_srv);
941  time_step_client.call(time_step_srv);
942  time_step_client.call(time_step_srv);
943 
944  sampling_period_battery_sensor_client.call(sampling_period_battery_sensor_srv);
945  ROS_INFO("Battery_sensor is disabled (sampling period is %d).", sampling_period_battery_sensor_srv.response.value);
946 
947  set_battery_sensor_client.shutdown();
948  sampling_period_battery_sensor_client.shutdown();
949  time_step_client.call(time_step_srv);
950 
952  // COMPASS METHODS TEST //
954 
955  ros::ServiceClient set_compass_client;
956  webots_ros::set_int compass_srv;
957  ros::Subscriber sub_compass_32;
958  set_compass_client = n.serviceClient<webots_ros::set_int>(model_name + "/compass/enable");
959 
960  ros::ServiceClient sampling_period_compass_client;
961  webots_ros::get_int sampling_period_compass_srv;
962  sampling_period_compass_client = n.serviceClient<webots_ros::get_int>(model_name + "/compass/get_sampling_period");
963 
964  compass_srv.request.value = 32;
965  if (set_compass_client.call(compass_srv) && compass_srv.response.success == 1) {
966  ROS_INFO("Compass enabled.");
967  sub_compass_32 = n.subscribe(model_name + "/compass/values", 1, compassCallback);
968  callbackCalled = false;
969  while (sub_compass_32.getNumPublishers() == 0 && !callbackCalled) {
970  ros::spinOnce();
971  time_step_client.call(time_step_srv);
972  }
973  } else {
974  if (compass_srv.response.success == -1)
975  ROS_ERROR("Sampling period is not valid.");
976  ROS_ERROR("Failed to enable compass.");
977  return 1;
978  }
979 
980  ros::ServiceClient lookup_table_compass_client;
981  webots_ros::get_float_array lookup_table_compass_srv;
982  lookup_table_compass_client = n.serviceClient<webots_ros::get_float_array>(model_name + "/compass/get_lookup_table");
983  if (lookup_table_compass_client.call(lookup_table_compass_srv))
984  ROS_INFO("Compass lookup table size = %lu.", lookup_table_compass_srv.response.value.size());
985  else
986  ROS_ERROR("Failed to get the lookup table of 'compass'.");
987  if (lookup_table_compass_srv.response.value.size() != 0)
988  ROS_ERROR("Size of lookup table of 'compass' is wrong.");
989  lookup_table_compass_client.shutdown();
990 
991  sub_compass_32.shutdown();
992 
993  time_step_client.call(time_step_srv);
994 
995  sampling_period_compass_client.call(sampling_period_compass_srv);
996  ROS_INFO("Compass is enabled with a sampling period of %d.", sampling_period_compass_srv.response.value);
997 
998  time_step_client.call(time_step_srv);
999 
1000  time_step_client.call(time_step_srv);
1001  time_step_client.call(time_step_srv);
1002  time_step_client.call(time_step_srv);
1003 
1004  sampling_period_compass_client.call(sampling_period_compass_srv);
1005  ROS_INFO("Compass is disabled (sampling period is %d).", sampling_period_compass_srv.response.value);
1006 
1007  set_compass_client.shutdown();
1008  sampling_period_compass_client.shutdown();
1009  time_step_client.call(time_step_srv);
1010 
1012  // CONNECTOR METHODS TEST //
1014 
1015  ros::ServiceClient connector_enable_presence_client;
1016  webots_ros::set_int connector_srv;
1017  ros::Subscriber sub_connector;
1018  connector_enable_presence_client = n.serviceClient<webots_ros::set_int>(model_name + "/connector/presence_sensor/enable");
1019 
1020  connector_srv.request.value = 32;
1021  if (connector_enable_presence_client.call(connector_srv) && connector_srv.response.success) {
1022  ROS_INFO("Connector's presence sensor enabled.");
1023  sub_connector = n.subscribe(model_name + "/connector/presence", 1, connectorCallback);
1024  callbackCalled = false;
1025  while (sub_connector.getNumPublishers() == 0 && !callbackCalled) {
1026  ros::spinOnce();
1027  time_step_client.call(time_step_srv);
1028  }
1029  } else {
1030  if (!connector_srv.response.success)
1031  ROS_ERROR("Sampling period is not valid.");
1032  ROS_ERROR("Failed to enable connector's presence sensor.");
1033  return 1;
1034  }
1035 
1036  sub_connector.shutdown();
1037 
1038  time_step_client.call(time_step_srv);
1039  time_step_client.call(time_step_srv);
1040  time_step_client.call(time_step_srv);
1041 
1042  connector_srv.request.value = 0;
1043  if (connector_enable_presence_client.call(connector_srv) && connector_srv.response.success)
1044  ROS_INFO("Connector's presence sensor disabled.");
1045  else {
1046  if (!connector_srv.response.success)
1047  ROS_ERROR("Sampling period is not valid.");
1048  ROS_ERROR("Failed to disable connector's presence sensor.");
1049  return 1;
1050  }
1051 
1052  ros::ServiceClient connector_lock_client;
1053  webots_ros::set_bool connector_lock_srv;
1054  connector_lock_client = n.serviceClient<webots_ros::set_bool>(model_name + "/connector/lock");
1055 
1056  connector_lock_srv.request.value = true;
1057  if (connector_lock_client.call(connector_lock_srv) && connector_lock_srv.response.success)
1058  ROS_INFO("Connector has been locked.");
1059  else
1060  ROS_INFO("Failed to lock connector.");
1061 
1062  connector_lock_client.shutdown();
1063  connector_enable_presence_client.shutdown();
1064  time_step_client.call(time_step_srv);
1065 
1067  // DISPLAY METHODS TEST //
1069 
1070  ros::ServiceClient display_get_info_client;
1071  webots_ros::display_get_info display_get_info_srv;
1072  display_get_info_client = n.serviceClient<webots_ros::display_get_info>(model_name + "/display/get_info");
1073 
1074  display_get_info_client.call(display_get_info_srv);
1075  ROS_INFO("Display's width is %d and its height is %d.", display_get_info_srv.response.width,
1076  display_get_info_srv.response.height);
1077 
1078  display_get_info_client.shutdown();
1079  time_step_client.call(time_step_srv);
1080 
1081  ros::ServiceClient display_set_color_client;
1082  webots_ros::set_int display_set_color_srv;
1083  display_set_color_client = n.serviceClient<webots_ros::set_int>(model_name + "/display/set_color");
1084 
1085  display_set_color_srv.request.value = 0xFF0000;
1086  if (display_set_color_client.call(display_set_color_srv) && display_set_color_srv.response.success)
1087  ROS_INFO("Display's color has been updated.");
1088  else
1089  ROS_ERROR("Failed to call service display_set_color. Success = %d.", display_set_color_srv.response.success);
1090 
1091  display_set_color_client.shutdown();
1092  time_step_client.call(time_step_srv);
1093 
1094  ros::ServiceClient display_set_alpha_client;
1095  webots_ros::set_float display_set_alpha_srv;
1096  display_set_alpha_client = n.serviceClient<webots_ros::set_float>(model_name + "/display/set_alpha");
1097 
1098  display_set_alpha_srv.request.value = 1.0;
1099  if (display_set_alpha_client.call(display_set_alpha_srv) && display_set_alpha_srv.response.success)
1100  ROS_INFO("Display's alpha has been updated.");
1101  else
1102  ROS_ERROR("Failed to call service display_set_alpha.");
1103 
1104  display_set_alpha_client.shutdown();
1105  time_step_client.call(time_step_srv);
1106 
1107  ros::ServiceClient display_set_opacity_client;
1108  webots_ros::set_float display_set_opacity_srv;
1109  display_set_opacity_client = n.serviceClient<webots_ros::set_float>(model_name + "/display/set_opacity");
1110 
1111  display_set_opacity_srv.request.value = 1.0;
1112  if (display_set_opacity_client.call(display_set_opacity_srv) && display_set_opacity_srv.response.success)
1113  ROS_INFO("Display's opacity has been updated.");
1114  else
1115  ROS_ERROR("Failed to call service display_set_opacity.");
1116 
1117  display_set_opacity_client.shutdown();
1118  time_step_client.call(time_step_srv);
1119 
1120  ros::ServiceClient display_set_font_client;
1121  webots_ros::display_set_font display_set_font_srv;
1122  display_set_font_client = n.serviceClient<webots_ros::display_set_font>(model_name + "/display/set_font");
1123 
1124  display_set_font_srv.request.font = "Arial";
1125  display_set_font_srv.request.size = 8;
1126  display_set_font_srv.request.antiAliasing = 0;
1127  if (display_set_font_client.call(display_set_font_srv) && display_set_font_srv.response.success == 1)
1128  ROS_INFO("Display's font has been updated.");
1129  else
1130  ROS_ERROR("Failed to call service display_set_font. Success = %d.", display_set_font_srv.response.success);
1131 
1132  display_set_font_client.shutdown();
1133  time_step_client.call(time_step_srv);
1134 
1135  ros::ServiceClient display_draw_pixel_client;
1136  webots_ros::display_draw_pixel display_draw_pixel_srv;
1137  display_draw_pixel_client = n.serviceClient<webots_ros::display_draw_pixel>(model_name + "/display/draw_pixel");
1138 
1139  display_draw_pixel_srv.request.x1 = 10;
1140  display_draw_pixel_srv.request.y1 = 10;
1141  if (display_draw_pixel_client.call(display_draw_pixel_srv) && display_draw_pixel_srv.response.success == 1)
1142  ROS_INFO("Pixel drawn at x =32 and y = 32 on the display.");
1143  else
1144  ROS_ERROR("Failed to call service display_draw_pixel. Success = %d.", display_draw_pixel_srv.response.success);
1145 
1146  display_draw_pixel_client.shutdown();
1147  time_step_client.call(time_step_srv);
1148 
1149  ros::ServiceClient display_draw_line_client;
1150  webots_ros::display_draw_line display_draw_line_srv;
1151  display_draw_line_client = n.serviceClient<webots_ros::display_draw_line>(model_name + "/display/draw_line");
1152 
1153  display_draw_line_srv.request.x1 = 32;
1154  display_draw_line_srv.request.x2 = 63;
1155  display_draw_line_srv.request.y1 = 32;
1156  display_draw_line_srv.request.y2 = 42;
1157  if (display_draw_line_client.call(display_draw_line_srv) && display_draw_line_srv.response.success == 1)
1158  ROS_INFO("Line drawn at x =32 and y = 32 on the display.");
1159  else
1160  ROS_ERROR("Failed to call service display_draw_line. Success = %d.", display_draw_line_srv.response.success);
1161 
1162  display_draw_line_client.shutdown();
1163  time_step_client.call(time_step_srv);
1164 
1165  ros::ServiceClient display_draw_rectangle_client;
1166  webots_ros::display_draw_rectangle display_draw_rectangle_srv;
1167  display_draw_rectangle_client = n.serviceClient<webots_ros::display_draw_rectangle>(model_name + "/display/draw_rectangle");
1168 
1169  display_draw_rectangle_srv.request.x = 2;
1170  display_draw_rectangle_srv.request.y = 32;
1171  display_draw_rectangle_srv.request.width = 10;
1172  display_draw_rectangle_srv.request.height = 5;
1173  if (display_draw_rectangle_client.call(display_draw_rectangle_srv) && display_draw_rectangle_srv.response.success == 1)
1174  ROS_INFO("Rectangle drawn at x =32 and y = 32 with width = 10 and height = 5 on the display.");
1175  else
1176  ROS_ERROR("Failed to call service display_draw_rectangle. Success = %d.", display_draw_rectangle_srv.response.success);
1177 
1178  display_draw_rectangle_client.shutdown();
1179  time_step_client.call(time_step_srv);
1180 
1181  ros::ServiceClient display_draw_oval_client;
1182  webots_ros::display_draw_oval display_draw_oval_srv;
1183  display_draw_oval_client = n.serviceClient<webots_ros::display_draw_oval>(model_name + "/display/draw_oval");
1184 
1185  display_draw_oval_srv.request.cx = 32;
1186  display_draw_oval_srv.request.cy = 6;
1187  display_draw_oval_srv.request.a = 10;
1188  display_draw_oval_srv.request.b = 5;
1189 
1190  if (display_draw_oval_client.call(display_draw_oval_srv) && display_draw_oval_srv.response.success == 1)
1191  ROS_INFO("Oval drawn at x =32 and y = 6 and axes a = 10 and b = 5 on the display.");
1192  else
1193  ROS_ERROR("Failed to call service display_draw_oval. Success = %d.", display_draw_oval_srv.response.success);
1194 
1195  display_draw_oval_client.shutdown();
1196  time_step_client.call(time_step_srv);
1197 
1198  ros::ServiceClient display_draw_polygon_client;
1199  webots_ros::display_draw_polygon display_draw_polygon_srv;
1200  display_draw_polygon_client = n.serviceClient<webots_ros::display_draw_polygon>(model_name + "/display/draw_polygon");
1201 
1202  display_draw_polygon_srv.request.x.push_back(55);
1203  display_draw_polygon_srv.request.y.push_back(55);
1204  display_draw_polygon_srv.request.x.push_back(50);
1205  display_draw_polygon_srv.request.y.push_back(50);
1206  display_draw_polygon_srv.request.x.push_back(45);
1207  display_draw_polygon_srv.request.y.push_back(45);
1208  display_draw_polygon_srv.request.x.push_back(45);
1209  display_draw_polygon_srv.request.y.push_back(55);
1210  display_draw_polygon_srv.request.x.push_back(40);
1211  display_draw_polygon_srv.request.y.push_back(50);
1212  display_draw_polygon_srv.request.size = 5;
1213  if (display_draw_polygon_client.call(display_draw_polygon_srv) && display_draw_polygon_srv.response.success == 1)
1214  ROS_INFO("Polygon drawn on the display.");
1215  else
1216  ROS_ERROR("Failed to call service display_draw_polygon. Success = %d.", display_draw_polygon_srv.response.success);
1217 
1218  display_draw_polygon_client.shutdown();
1219  time_step_client.call(time_step_srv);
1220 
1221  ros::ServiceClient display_draw_text_client;
1222  webots_ros::display_draw_text display_draw_text_srv;
1223  display_draw_text_client = n.serviceClient<webots_ros::display_draw_text>(model_name + "/display/draw_text");
1224 
1225  display_draw_text_srv.request.x = 10;
1226  display_draw_text_srv.request.y = 52;
1227  display_draw_text_srv.request.text = "hello world";
1228  if (display_draw_text_client.call(display_draw_text_srv) && display_draw_text_srv.response.success == 1)
1229  ROS_INFO("Hello World written at x =10 and y = 52 on the display.");
1230  else
1231  ROS_ERROR("Failed to call service display_draw_text. Success = %d.", display_draw_text_srv.response.success);
1232 
1233  display_draw_text_client.shutdown();
1234  time_step_client.call(time_step_srv);
1235 
1236  ros::ServiceClient display_fill_rectangle_client;
1237  webots_ros::display_draw_rectangle display_fill_rectangle_srv;
1238  display_fill_rectangle_client = n.serviceClient<webots_ros::display_draw_rectangle>(model_name + "/display/fill_rectangle");
1239 
1240  display_fill_rectangle_srv.request.x = 2;
1241  display_fill_rectangle_srv.request.y = 32;
1242  display_fill_rectangle_srv.request.width = 10;
1243  display_fill_rectangle_srv.request.height = 5;
1244  if (display_fill_rectangle_client.call(display_fill_rectangle_srv) && display_fill_rectangle_srv.response.success == 1)
1245  ROS_INFO("Rectangle filled at x =32 and y = 32 with width = 10 and height = 5 on the display.");
1246  else
1247  ROS_ERROR("Failed to call service display_fill_rectangle. Success = %d.", display_fill_rectangle_srv.response.success);
1248 
1249  display_fill_rectangle_client.shutdown();
1250  time_step_client.call(time_step_srv);
1251 
1252  ros::ServiceClient display_fill_oval_client;
1253  webots_ros::display_draw_oval display_fill_oval_srv;
1254  display_fill_oval_client = n.serviceClient<webots_ros::display_draw_oval>(model_name + "/display/fill_oval");
1255 
1256  display_fill_oval_srv.request.cx = 32;
1257  display_fill_oval_srv.request.cy = 6;
1258  display_fill_oval_srv.request.a = 10;
1259  display_fill_oval_srv.request.b = 5;
1260 
1261  if (display_fill_oval_client.call(display_fill_oval_srv) && display_fill_oval_srv.response.success == 1)
1262  ROS_INFO("Oval filled at x =32 and y = 6 and axes a = 10 and b = 5 on the display.");
1263  else
1264  ROS_ERROR("Failed to call service display_fill_oval. Success = %d.", display_fill_oval_srv.response.success);
1265 
1266  display_fill_oval_client.shutdown();
1267  time_step_client.call(time_step_srv);
1268 
1269  ros::ServiceClient display_fill_polygon_client;
1270  webots_ros::display_draw_polygon display_fill_polygon_srv;
1271  display_fill_polygon_client = n.serviceClient<webots_ros::display_draw_polygon>(model_name + "/display/fill_polygon");
1272 
1273  display_fill_polygon_srv.request.x.push_back(55);
1274  display_fill_polygon_srv.request.y.push_back(55);
1275  display_fill_polygon_srv.request.x.push_back(50);
1276  display_fill_polygon_srv.request.y.push_back(50);
1277  display_fill_polygon_srv.request.x.push_back(45);
1278  display_fill_polygon_srv.request.y.push_back(45);
1279  display_fill_polygon_srv.request.x.push_back(45);
1280  display_fill_polygon_srv.request.y.push_back(55);
1281  display_fill_polygon_srv.request.x.push_back(40);
1282  display_fill_polygon_srv.request.y.push_back(50);
1283  display_fill_polygon_srv.request.size = 5;
1284  if (display_fill_polygon_client.call(display_fill_polygon_srv) && display_fill_polygon_srv.response.success == 1)
1285  ROS_INFO("Polygon filled on the display.");
1286  else
1287  ROS_ERROR("Failed to call service display_fill_polygon. Success = %d.", display_fill_polygon_srv.response.success);
1288 
1289  display_fill_polygon_client.shutdown();
1290  time_step_client.call(time_step_srv);
1291  time_step_client.call(time_step_srv);
1292  time_step_client.call(time_step_srv);
1293 
1294  ros::ServiceClient display_image_new_client;
1295  webots_ros::display_image_new display_image_new_srv;
1296  display_image_new_client = n.serviceClient<webots_ros::display_image_new>(model_name + "/display/image_new");
1297 
1298  display_image_new_srv.request.format = 3;
1299  display_image_new_srv.request.width = 10;
1300  display_image_new_srv.request.height = 5;
1301  display_image_new_srv.request.data.push_back(1);
1302  display_image_new_srv.request.data.push_back(2);
1303  display_image_new_srv.request.data.push_back(5);
1304  display_image_new_srv.request.data.push_back(3);
1305  display_image_new_srv.request.data.push_back(4);
1306  display_image_new_client.call(display_image_new_srv);
1307  ROS_INFO("New image created.");
1308  uint64_t new_image = display_image_new_srv.response.ir;
1309 
1310  display_image_new_client.shutdown();
1311  time_step_client.call(time_step_srv);
1312 
1313  ros::ServiceClient display_image_copy_client;
1314  webots_ros::display_image_copy display_image_copy_srv;
1315  display_image_copy_client = n.serviceClient<webots_ros::display_image_copy>(model_name + "/display/image_copy");
1316 
1317  display_image_copy_srv.request.x = 0;
1318  display_image_copy_srv.request.y = 32;
1319  display_image_copy_srv.request.width = 64;
1320  display_image_copy_srv.request.height = 32;
1321  display_image_copy_client.call(display_image_copy_srv);
1322  ROS_INFO("Image copied.");
1323  uint64_t copy_image = display_image_copy_srv.response.ir;
1324 
1325  display_image_copy_client.shutdown();
1326  time_step_client.call(time_step_srv);
1327 
1328  ros::ServiceClient display_image_paste_client;
1329  webots_ros::display_image_paste display_image_paste_srv;
1330  display_image_paste_client = n.serviceClient<webots_ros::display_image_paste>(model_name + "/display/image_paste");
1331 
1332  display_image_paste_srv.request.ir = copy_image;
1333  display_image_paste_srv.request.x = 0;
1334  display_image_paste_srv.request.y = 0;
1335  display_image_paste_srv.request.blend = 1;
1336  if (display_image_paste_client.call(display_image_paste_srv) && display_image_paste_srv.response.success == 1)
1337  ROS_INFO("Image successfully copy/paste.");
1338  else
1339  ROS_ERROR("Failed to call service display_image_paste to paste image.");
1340 
1341  display_image_paste_client.shutdown();
1342  time_step_client.call(time_step_srv);
1343  time_step_client.call(time_step_srv);
1344  time_step_client.call(time_step_srv);
1345 
1346  ros::ServiceClient display_image_save_client;
1347  webots_ros::display_image_save display_image_save_srv;
1348  display_image_save_client = n.serviceClient<webots_ros::display_image_save>(model_name + "/display/image_save");
1349 
1350  display_image_save_srv.request.ir = copy_image;
1351  display_image_save_srv.request.filename = std::string(getenv("HOME")) + std::string("/copy_image.png");
1352  if (display_image_save_client.call(display_image_save_srv) && display_image_save_srv.response.success == 1)
1353  ROS_INFO("Image successfully saved.");
1354  else
1355  ROS_ERROR("Failed to call service display_image_save to save image.");
1356 
1357  display_image_save_client.shutdown();
1358  time_step_client.call(time_step_srv);
1359 
1360  ros::ServiceClient display_image_load_client;
1361  webots_ros::display_image_load display_image_load_srv;
1362  display_image_load_client = n.serviceClient<webots_ros::display_image_load>(model_name + "/display/image_load");
1363 
1364  display_image_load_srv.request.filename = std::string(getenv("HOME")) + std::string("/test_image_camera.png");
1365  display_image_load_client.call(display_image_load_srv);
1366  ROS_INFO("Image successfully loaded to clipboard.");
1367  uint64_t loaded_image = display_image_load_srv.response.ir;
1368 
1369  display_image_paste_srv.request.ir = loaded_image;
1370  if (display_image_paste_client.call(display_image_paste_srv) && display_image_paste_srv.response.success == 1)
1371  ROS_INFO("Image successfully load and paste.");
1372  else
1373  ROS_ERROR("Failed to call service display_image_paste to paste image.");
1374 
1375  display_image_load_client.shutdown();
1376  time_step_client.call(time_step_srv);
1377 
1378  ros::ServiceClient display_image_delete_client;
1379  webots_ros::display_image_delete display_image_delete_srv;
1380  display_image_delete_client = n.serviceClient<webots_ros::display_image_delete>(model_name + "/display/image_delete");
1381 
1382  display_image_delete_srv.request.ir = loaded_image;
1383  if (display_image_delete_client.call(display_image_delete_srv) && display_image_delete_srv.response.success == 1)
1384  ROS_INFO("Loaded image has been deleted.");
1385  else
1386  ROS_ERROR("Failed to call service display_image_delete.");
1387 
1388  display_image_delete_srv.request.ir = copy_image;
1389  if (display_image_delete_client.call(display_image_delete_srv) && display_image_delete_srv.response.success == 1)
1390  ROS_INFO("Copy image has been deleted.");
1391  else
1392  ROS_ERROR("Failed to call service display_image_delete.");
1393 
1394  display_image_delete_srv.request.ir = new_image;
1395  if (display_image_delete_client.call(display_image_delete_srv) && display_image_delete_srv.response.success == 1)
1396  ROS_INFO("New image has been deleted.");
1397  else
1398  ROS_ERROR("Failed to call service display_image_delete.");
1399 
1400  display_image_delete_client.shutdown();
1401  time_step_client.call(time_step_srv);
1402 
1404  // DISTANCE SENSOR METHODS TEST //
1406 
1407  ros::ServiceClient set_distance_sensor_client;
1408  webots_ros::set_int distance_sensor_srv;
1409  ros::Subscriber sub_distance_sensor_32;
1410  set_distance_sensor_client = n.serviceClient<webots_ros::set_int>(model_name + "/distance_sensor/enable");
1411 
1412  ros::ServiceClient sampling_period_distance_sensor_client;
1413  webots_ros::get_int sampling_period_distance_sensor_srv;
1414  sampling_period_distance_sensor_client =
1415  n.serviceClient<webots_ros::get_int>(model_name + "/distance_sensor/get_sampling_period");
1416 
1417  ros::ServiceClient min_value_distance_sensor_client;
1418  webots_ros::get_float min_value_distance_sensor_srv;
1419  min_value_distance_sensor_client = n.serviceClient<webots_ros::get_float>(model_name + "/distance_sensor/get_min_value");
1420  if (min_value_distance_sensor_client.call(min_value_distance_sensor_srv))
1421  ROS_INFO("Distance_sensor min value = %g.", min_value_distance_sensor_srv.response.value);
1422  else
1423  ROS_ERROR("Failed to get the minimum value of 'distance_sensor'.");
1424  min_value_distance_sensor_client.shutdown();
1425 
1426  ros::ServiceClient max_value_distance_sensor_client;
1427  webots_ros::get_float max_value_distance_sensor_srv;
1428  max_value_distance_sensor_client = n.serviceClient<webots_ros::get_float>(model_name + "/distance_sensor/get_max_value");
1429  if (max_value_distance_sensor_client.call(max_value_distance_sensor_srv))
1430  ROS_INFO("Distance_sensor max value = %g.", max_value_distance_sensor_srv.response.value);
1431  else
1432  ROS_ERROR("Failed to get the maximum value of 'distance_sensor'.");
1433  max_value_distance_sensor_client.shutdown();
1434 
1435  ros::ServiceClient aperture_distance_sensor_client;
1436  webots_ros::get_float aperture_distance_sensor_srv;
1437  aperture_distance_sensor_client = n.serviceClient<webots_ros::get_float>(model_name + "/distance_sensor/get_aperture");
1438  if (aperture_distance_sensor_client.call(aperture_distance_sensor_srv))
1439  ROS_INFO("Distance_sensor aperture = %g.", aperture_distance_sensor_srv.response.value);
1440  else
1441  ROS_ERROR("Failed to get the aperture of 'distance_sensor'.");
1442  aperture_distance_sensor_client.shutdown();
1443 
1444  ros::ServiceClient lookup_table_distance_sensor_client;
1445  webots_ros::get_float_array lookup_table_distance_sensor_srv;
1446  lookup_table_distance_sensor_client =
1447  n.serviceClient<webots_ros::get_float_array>(model_name + "/distance_sensor/get_lookup_table");
1448  if (lookup_table_distance_sensor_client.call(lookup_table_distance_sensor_srv))
1449  ROS_INFO("Distance_sensor lookup table size = %lu.", lookup_table_distance_sensor_srv.response.value.size());
1450  else
1451  ROS_ERROR("Failed to get the lookup table of 'distance_sensor'.");
1452  if (lookup_table_distance_sensor_srv.response.value.size() != 6)
1453  ROS_ERROR("Size of lookup table of 'distance_sensor' is wrong, expected 0 got %lu.",
1454  lookup_table_distance_sensor_srv.response.value.size());
1455  lookup_table_distance_sensor_client.shutdown();
1456 
1457  distance_sensor_srv.request.value = 32;
1458  if (set_distance_sensor_client.call(distance_sensor_srv) && distance_sensor_srv.response.success) {
1459  ROS_INFO("Distance_sensor enabled.");
1460  sub_distance_sensor_32 = n.subscribe(model_name + "/distance_sensor/value", 1, distance_sensorCallback);
1461  callbackCalled = false;
1462  while (sub_distance_sensor_32.getNumPublishers() == 0 && !callbackCalled) {
1463  ros::spinOnce();
1464  time_step_client.call(time_step_srv);
1465  }
1466  } else {
1467  if (!distance_sensor_srv.response.success)
1468  ROS_ERROR("Sampling period is not valid.");
1469  ROS_ERROR("Failed to enable distance_sensor.");
1470  return 1;
1471  }
1472 
1473  sub_distance_sensor_32.shutdown();
1474 
1475  time_step_client.call(time_step_srv);
1476 
1477  sampling_period_distance_sensor_client.call(sampling_period_distance_sensor_srv);
1478  ROS_INFO("Distance_sensor is enabled with a sampling period of %d.", sampling_period_distance_sensor_srv.response.value);
1479 
1480  time_step_client.call(time_step_srv);
1481 
1482  time_step_client.call(time_step_srv);
1483  time_step_client.call(time_step_srv);
1484  time_step_client.call(time_step_srv);
1485 
1486  sampling_period_distance_sensor_client.call(sampling_period_distance_sensor_srv);
1487  ROS_INFO("Distance_sensor is disabled (sampling period is %d).", sampling_period_distance_sensor_srv.response.value);
1488 
1489  set_distance_sensor_client.shutdown();
1490  sampling_period_distance_sensor_client.shutdown();
1491  time_step_client.call(time_step_srv);
1492 
1494  // EMITTER METHODS TEST //
1496 
1497  ros::ServiceClient emitter_send_client;
1498  webots_ros::set_string emitter_send_srv;
1499  emitter_send_client = n.serviceClient<webots_ros::set_string>(model_name + "/emitter/send");
1500 
1501  emitter_send_srv.request.value = "abc";
1502 
1503  if (emitter_send_client.call(emitter_send_srv) && emitter_send_srv.response.success)
1504  ROS_INFO("Emitter has sent data.");
1505  else
1506  ROS_ERROR("Failed to call service emitter_send to send data.");
1507 
1508  emitter_send_client.shutdown();
1509  time_step_client.call(time_step_srv);
1510 
1511  ros::ServiceClient emitter_get_buffer_size_client;
1512  webots_ros::get_int emitter_get_buffer_size_srv;
1513  emitter_get_buffer_size_client = n.serviceClient<webots_ros::get_int>(model_name + "/emitter/get_buffer_size");
1514 
1515  emitter_get_buffer_size_client.call(emitter_get_buffer_size_srv);
1516  ROS_INFO("Emitter's buffer is of size %d.", emitter_get_buffer_size_srv.response.value);
1517 
1518  emitter_get_buffer_size_client.shutdown();
1519  time_step_client.call(time_step_srv);
1520 
1521  ros::ServiceClient emitter_set_channel_client;
1522  webots_ros::set_int emitter_set_channel_srv;
1523  emitter_set_channel_client = n.serviceClient<webots_ros::set_int>(model_name + "/emitter/set_channel");
1524 
1525  emitter_set_channel_srv.request.value = 1;
1526 
1527  if (emitter_set_channel_client.call(emitter_set_channel_srv) && emitter_set_channel_srv.response.success)
1528  ROS_INFO("Emitter has update the channel.");
1529  else
1530  ROS_ERROR("Failed to call service emitter_set_channel to update channel.");
1531 
1532  emitter_set_channel_client.shutdown();
1533  time_step_client.call(time_step_srv);
1534 
1535  ros::ServiceClient emitter_set_range_client;
1536  webots_ros::set_float emitter_set_range_srv;
1537  emitter_set_range_client = n.serviceClient<webots_ros::set_float>(model_name + "/emitter/set_range");
1538 
1539  emitter_set_range_srv.request.value = 50;
1540 
1541  if (emitter_set_range_client.call(emitter_set_range_srv) && emitter_set_range_srv.response.success)
1542  ROS_INFO("Emitter has update the range.");
1543  else
1544  ROS_ERROR("Failed to call service emitter_set_range to update range.");
1545 
1546  emitter_set_range_client.shutdown();
1547  time_step_client.call(time_step_srv);
1548 
1549  ros::ServiceClient emitter_get_channel_client;
1550  webots_ros::get_int emitter_get_channel_srv;
1551  emitter_get_channel_client = n.serviceClient<webots_ros::get_int>(model_name + "/emitter/get_channel");
1552 
1553  emitter_get_channel_client.call(emitter_get_channel_srv);
1554  ROS_INFO("Emitter uses channel %d.", emitter_get_channel_srv.response.value);
1555 
1556  emitter_get_channel_client.shutdown();
1557  time_step_client.call(time_step_srv);
1558 
1559  ros::ServiceClient emitter_get_range_client;
1560  webots_ros::get_float emitter_get_range_srv;
1561  emitter_get_range_client = n.serviceClient<webots_ros::get_float>(model_name + "/emitter/get_range");
1562 
1563  emitter_get_range_client.call(emitter_get_range_srv);
1564  ROS_INFO("Emitter has a range of %f.", emitter_get_range_srv.response.value);
1565 
1566  emitter_get_range_client.shutdown();
1567  time_step_client.call(time_step_srv);
1568 
1570  // GPS METHODS TEST //
1572 
1573  ros::ServiceClient set_GPS_client;
1574  webots_ros::set_int GPS_srv;
1575  ros::Subscriber sub_GPS_32;
1576  ros::Subscriber sub_GPS_speed;
1577  set_GPS_client = n.serviceClient<webots_ros::set_int>(model_name + "/gps/enable");
1578 
1579  ros::ServiceClient sampling_period_GPS_client;
1580  webots_ros::get_int sampling_period_GPS_srv;
1581  sampling_period_GPS_client = n.serviceClient<webots_ros::get_int>(model_name + "/gps/get_sampling_period");
1582 
1583  GPS_srv.request.value = 32;
1584  if (set_GPS_client.call(GPS_srv) && GPS_srv.response.success) {
1585  ROS_INFO("GPS enabled.");
1586  sub_GPS_32 = n.subscribe(model_name + "/gps/values", 1, GPSCallback);
1587  callbackCalled = false;
1588  while (sub_GPS_32.getNumPublishers() == 0 && !callbackCalled) {
1589  ros::spinOnce();
1590  time_step_client.call(time_step_srv);
1591  }
1592  sub_GPS_32.shutdown();
1593  time_step_client.call(time_step_srv);
1594 
1595  sub_GPS_speed = n.subscribe(model_name + "/gps/speed", 1, GPSSpeedCallback);
1596  callbackCalled = false;
1597  while (sub_GPS_speed.getNumPublishers() == 0 && !callbackCalled) {
1598  ros::spinOnce();
1599  time_step_client.call(time_step_srv);
1600  }
1601  } else {
1602  if (!GPS_srv.response.success)
1603  ROS_ERROR("Sampling period is not valid.");
1604  ROS_ERROR("Failed to enable GPS.");
1605  return 1;
1606  }
1607 
1608  sub_GPS_speed.shutdown();
1609  time_step_client.call(time_step_srv);
1610 
1611  sampling_period_GPS_client.call(sampling_period_GPS_srv);
1612  ROS_INFO("GPS is enabled with a sampling period of %d.", sampling_period_GPS_srv.response.value);
1613 
1614  ros::ServiceClient gps_get_coordinate_system_client;
1615  webots_ros::get_int gps_get_coordinate_system_srv;
1616  gps_get_coordinate_system_client = n.serviceClient<webots_ros::get_int>(model_name + "/gps/get_coordinate_system");
1617 
1618  gps_get_coordinate_system_client.call(gps_get_coordinate_system_srv);
1619  ROS_INFO("GPS coordinate system type is: %d.", gps_get_coordinate_system_srv.response.value);
1620 
1621  time_step_client.call(time_step_srv);
1622 
1623  sampling_period_GPS_client.call(sampling_period_GPS_srv);
1624  ROS_INFO("GPS is disabled (sampling period is %d).", sampling_period_GPS_srv.response.value);
1625 
1626  set_GPS_client.shutdown();
1627  sampling_period_GPS_client.shutdown();
1628  gps_get_coordinate_system_client.shutdown();
1629  time_step_client.call(time_step_srv);
1630 
1632  // GYRO METHODS TEST //
1634 
1635  ros::ServiceClient set_gyro_client;
1636  webots_ros::set_int gyro_srv;
1637  ros::Subscriber sub_gyro_32;
1638  set_gyro_client = n.serviceClient<webots_ros::set_int>(model_name + "/gyro/enable");
1639 
1640  ros::ServiceClient sampling_period_gyro_client;
1641  webots_ros::get_int sampling_period_gyro_srv;
1642  sampling_period_gyro_client = n.serviceClient<webots_ros::get_int>(model_name + "/gyro/get_sampling_period");
1643 
1644  gyro_srv.request.value = 32;
1645  if (set_gyro_client.call(gyro_srv) && gyro_srv.response.success) {
1646  ROS_INFO("Gyro enabled.");
1647  sub_gyro_32 = n.subscribe(model_name + "/gyro/values", 1, gyroCallback);
1648  callbackCalled = false;
1649  while (sub_gyro_32.getNumPublishers() == 0 && !callbackCalled) {
1650  ros::spinOnce();
1651  time_step_client.call(time_step_srv);
1652  }
1653  } else {
1654  if (!gyro_srv.response.success)
1655  ROS_ERROR("Sampling period is not valid.");
1656  ROS_ERROR("Failed to enable gyro.");
1657  return 1;
1658  }
1659  sub_gyro_32.shutdown();
1660 
1661  ros::ServiceClient lookup_table_gyro_client;
1662  webots_ros::get_float_array lookup_table_gyro_srv;
1663  lookup_table_gyro_client = n.serviceClient<webots_ros::get_float_array>(model_name + "/gyro/get_lookup_table");
1664  if (lookup_table_gyro_client.call(lookup_table_gyro_srv))
1665  ROS_INFO("Gyro lookup table size = %lu.", lookup_table_gyro_srv.response.value.size());
1666  else
1667  ROS_ERROR("Failed to get the lookup table of 'gyro'.");
1668  if (lookup_table_gyro_srv.response.value.size() != 0)
1669  ROS_ERROR("Size of lookup table of 'gyro' is wrong.");
1670  lookup_table_gyro_client.shutdown();
1671 
1672  time_step_client.call(time_step_srv);
1673 
1674  sampling_period_gyro_client.call(sampling_period_gyro_srv);
1675  ROS_INFO("Gyro is enabled with a sampling period of %d.", sampling_period_gyro_srv.response.value);
1676 
1677  time_step_client.call(time_step_srv);
1678 
1679  sampling_period_gyro_client.call(sampling_period_gyro_srv);
1680  ROS_INFO("Gyro is disabled (sampling period is %d).", sampling_period_gyro_srv.response.value);
1681 
1682  set_gyro_client.shutdown();
1683  sampling_period_gyro_client.shutdown();
1684  time_step_client.call(time_step_srv);
1685 
1687  // INERTIAL_UNIT METHODS TEST //
1689 
1690  ros::ServiceClient set_inertial_unit_client;
1691  webots_ros::set_int inertial_unit_srv;
1692  ros::Subscriber sub_inertial_unit_32;
1693  set_inertial_unit_client = n.serviceClient<webots_ros::set_int>(model_name + "/inertial_unit/enable");
1694 
1695  ros::ServiceClient sampling_period_inertial_unit_client;
1696  webots_ros::get_int sampling_period_inertial_unit_srv;
1697  sampling_period_inertial_unit_client =
1698  n.serviceClient<webots_ros::get_int>(model_name + "/inertial_unit/get_sampling_period");
1699 
1700  inertial_unit_srv.request.value = 32;
1701  if (set_inertial_unit_client.call(inertial_unit_srv) && inertial_unit_srv.response.success) {
1702  ROS_INFO("Inertial_unit enabled.");
1703  sub_inertial_unit_32 = n.subscribe(model_name + "/inertial_unit/roll_pitch_yaw", 1, inertialUnitCallback);
1704  callbackCalled = false;
1705  while (sub_inertial_unit_32.getNumPublishers() == 0 && !callbackCalled) {
1706  ros::spinOnce();
1707  time_step_client.call(time_step_srv);
1708  }
1709  } else {
1710  if (!inertial_unit_srv.response.success)
1711  ROS_ERROR("Sampling period is not valid.");
1712  ROS_ERROR("Failed to enable inertial_unit.");
1713  return 1;
1714  }
1715 
1716  sub_inertial_unit_32.shutdown();
1717 
1718  ros::ServiceClient lookup_table_inertial_unit_client;
1719  webots_ros::get_float_array lookup_table_inertial_unit_srv;
1720  lookup_table_inertial_unit_client =
1721  n.serviceClient<webots_ros::get_float_array>(model_name + "/inertial_unit/get_lookup_table");
1722  if (lookup_table_inertial_unit_client.call(lookup_table_inertial_unit_srv))
1723  ROS_INFO("Inertial unit lookup table size = %lu.", lookup_table_inertial_unit_srv.response.value.size());
1724  else
1725  ROS_ERROR("Failed to get the lookup table of 'inertial_unit'.");
1726  if (lookup_table_inertial_unit_srv.response.value.size() != 0)
1727  ROS_ERROR("Size of lookup table of 'inertial_unit' is wrong.");
1728  lookup_table_inertial_unit_client.shutdown();
1729 
1730  time_step_client.call(time_step_srv);
1731 
1732  sampling_period_inertial_unit_client.call(sampling_period_inertial_unit_srv);
1733  ROS_INFO("Inertial_unit is enabled with a sampling period of %d.", sampling_period_inertial_unit_srv.response.value);
1734 
1735  time_step_client.call(time_step_srv);
1736 
1737  sampling_period_inertial_unit_client.call(sampling_period_inertial_unit_srv);
1738  ROS_INFO("Inertial_unit is disabled (sampling period is %d).", sampling_period_inertial_unit_srv.response.value);
1739 
1740  set_inertial_unit_client.shutdown();
1741  sampling_period_inertial_unit_client.shutdown();
1742  time_step_client.call(time_step_srv);
1743 
1745  // JOYSTICK METHODS TEST //
1747 
1748  ros::ServiceClient enable_joystick_client = n.serviceClient<webots_ros::set_int>(model_name + "/joystick/enable");
1749  webots_ros::set_int enable_joystick_srv;
1750  ros::Subscriber sub_joystick;
1751 
1752  enable_joystick_srv.request.value = 32;
1753  if (enable_joystick_client.call(enable_joystick_srv) && enable_joystick_srv.response.success) {
1754  ROS_INFO("Joystick of %s has been enabled.", model_name.c_str());
1755  sub_joystick = n.subscribe(model_name + "/joystick/pressed_button", 1, joystickCallback);
1756  callbackCalled = false;
1757  ROS_INFO("Topics for joystick initialized.");
1758 
1759  while (sub_joystick.getNumPublishers() == 0 && !callbackCalled) {
1760  ros::spinOnce();
1761  time_step_client.call(time_step_srv);
1762  }
1763  ROS_INFO("Topics for joystick connected.");
1764  } else
1765  ROS_ERROR("Failed to enable joystick.");
1766 
1767  sub_joystick.shutdown();
1768 
1769  enable_joystick_client.shutdown();
1770  time_step_client.call(time_step_srv);
1771 
1772  ros::ServiceClient joystick_get_model_client;
1773  webots_ros::get_string joystick_get_model_srv;
1774  joystick_get_model_client = n.serviceClient<webots_ros::get_string>(model_name + "/joystick/get_model");
1775  joystick_get_model_client.call(joystick_get_model_srv);
1776  ROS_INFO("Got josytick model: %s.", joystick_get_model_srv.response.value.c_str());
1777 
1778  joystick_get_model_client.shutdown();
1779  time_step_client.call(time_step_srv);
1780 
1782  // LED METHODS TEST //
1784 
1785  ros::ServiceClient set_led_client;
1786  webots_ros::set_int set_led_srv;
1787  set_led_client = n.serviceClient<webots_ros::set_int>(model_name + "/led/set_led");
1788 
1789  set_led_srv.request.value = 1;
1790  if (set_led_client.call(set_led_srv) && set_led_srv.response.success)
1791  ROS_INFO("LED set to 1.");
1792  else
1793  ROS_ERROR("Failed to call service set_led.");
1794 
1795  enable_joystick_client.shutdown();
1796  set_led_client.call(time_step_srv);
1797 
1798  ros::ServiceClient get_led_client;
1799  webots_ros::get_int get_led_srv;
1800  get_led_client = n.serviceClient<webots_ros::get_int>(model_name + "/led/get_led");
1801 
1802  get_led_client.call(get_led_srv);
1803  ROS_INFO("LED value is %d.", get_led_srv.response.value);
1804 
1805  set_led_srv.request.value = 0;
1806  if (set_led_client.call(set_led_srv) && set_led_srv.response.success)
1807  ROS_INFO("LED set to 0.");
1808  else
1809  ROS_ERROR("Failed to call service set_led.");
1810 
1811  set_led_client.shutdown();
1812  get_led_client.shutdown();
1813  time_step_client.call(time_step_srv);
1814 
1816  // LIDAR METHODS TEST //
1818 
1819  // lidar enable
1820  ros::ServiceClient set_lidar_client;
1821  webots_ros::set_int lidar_srv;
1822  ros::Subscriber sub_lidar;
1823 
1824  set_lidar_client = n.serviceClient<webots_ros::set_int>(model_name + "/lidar/enable");
1825  lidar_srv.request.value = TIME_STEP;
1826  if (set_lidar_client.call(lidar_srv) && lidar_srv.response.success) {
1827  ROS_INFO("Lidar enabled.");
1828  sub_lidar = n.subscribe(model_name + "/lidar/range_image", 1, lidarCallback);
1829  callbackCalled = false;
1830  ROS_INFO("Topic for lidar initialized.");
1831 
1832  while (sub_lidar.getNumPublishers() == 0 && !callbackCalled) {
1833  ros::spinOnce();
1834  time_step_client.call(time_step_srv);
1835  }
1836  ROS_INFO("Topic for lidar color connected.");
1837  } else {
1838  if (!lidar_srv.response.success)
1839  ROS_ERROR("Sampling period is not valid.");
1840  ROS_ERROR("Failed to enable lidar.");
1841  return 1;
1842  }
1843 
1844  sub_lidar.shutdown();
1845  set_lidar_client.shutdown();
1846  time_step_client.call(time_step_srv);
1847 
1848  // lidar_get_info
1849  get_info_client = n.serviceClient<webots_ros::lidar_get_info>(model_name + "/lidar/get_info");
1850  webots_ros::lidar_get_info get_lidar_info_srv;
1851  if (get_info_client.call(get_lidar_info_srv))
1852  ROS_INFO("Lidar of %s has a horizontal resolution of %d, %d layers, a field of view of %f, a min range of %f and a max "
1853  "range of %f.",
1854  model_name.c_str(), get_lidar_info_srv.response.horizontalResolution, get_lidar_info_srv.response.numberOfLayers,
1855  get_lidar_info_srv.response.fov, get_lidar_info_srv.response.minRange, get_lidar_info_srv.response.maxRange);
1856  else
1857  ROS_ERROR("Failed to call service lidar_get_info.");
1858 
1859  get_info_client.shutdown();
1860  time_step_client.call(time_step_srv);
1861 
1862  // lidar_get_frequency_info
1863  get_info_client = n.serviceClient<webots_ros::lidar_get_frequency_info>(model_name + "/lidar/get_frequency_info");
1864  webots_ros::lidar_get_frequency_info get_lidar_frequency_info_srv;
1865  if (get_info_client.call(get_lidar_frequency_info_srv))
1866  ROS_INFO("Lidar %s current frequency is %f, maximum frequency is %f and minimum frequency is %f.", model_name.c_str(),
1867  get_lidar_frequency_info_srv.response.frequency, get_lidar_frequency_info_srv.response.maxFrequency,
1868  get_lidar_frequency_info_srv.response.minFrequency);
1869  else
1870  ROS_ERROR("Failed to call service lidar_get_frequency_info.");
1871 
1872  get_info_client.shutdown();
1873  time_step_client.call(time_step_srv);
1874 
1875  ROS_INFO("Lidar disabled.");
1876 
1878  // LIGHT SENSOR METHODS TEST //
1880 
1881  ros::ServiceClient set_light_sensor_client;
1882  webots_ros::set_int light_sensor_srv;
1883  ros::Subscriber sub_light_sensor_32;
1884  set_light_sensor_client = n.serviceClient<webots_ros::set_int>(model_name + "/light_sensor/enable");
1885 
1886  ros::ServiceClient sampling_period_light_sensor_client;
1887  webots_ros::get_int sampling_period_light_sensor_srv;
1888  sampling_period_light_sensor_client = n.serviceClient<webots_ros::get_int>(model_name + "/light_sensor/get_sampling_period");
1889 
1890  light_sensor_srv.request.value = 32;
1891  if (set_light_sensor_client.call(light_sensor_srv) && light_sensor_srv.response.success) {
1892  ROS_INFO("Light_sensor enabled.");
1893  sub_light_sensor_32 = n.subscribe(model_name + "/light_sensor/value", 1, lightSensorCallback);
1894  callbackCalled = false;
1895  while (sub_light_sensor_32.getNumPublishers() == 0 && !callbackCalled) {
1896  ros::spinOnce();
1897  time_step_client.call(time_step_srv);
1898  }
1899  } else {
1900  if (!light_sensor_srv.response.success)
1901  ROS_ERROR("Sampling period is not valid.");
1902  ROS_ERROR("Failed to enable light_sensor.");
1903  return 1;
1904  }
1905 
1906  sub_light_sensor_32.shutdown();
1907 
1908  ros::ServiceClient lookup_table_light_sensor_client;
1909  webots_ros::get_float_array lookup_table_light_sensor_srv;
1910  lookup_table_light_sensor_client =
1911  n.serviceClient<webots_ros::get_float_array>(model_name + "/light_sensor/get_lookup_table");
1912  if (lookup_table_light_sensor_client.call(lookup_table_light_sensor_srv))
1913  ROS_INFO("Light sensor lookup table size = %lu.", lookup_table_light_sensor_srv.response.value.size());
1914  else
1915  ROS_ERROR("Failed to get the lookup table of 'light_sensor'.");
1916  if (lookup_table_light_sensor_srv.response.value.size() != 6)
1917  ROS_ERROR("Size of lookup table of 'light_sensor' is wrong.");
1918  lookup_table_light_sensor_client.shutdown();
1919 
1920  time_step_client.call(time_step_srv);
1921 
1922  sampling_period_light_sensor_client.call(sampling_period_light_sensor_srv);
1923  ROS_INFO("Light_sensor is enabled with a sampling period of %d.", sampling_period_light_sensor_srv.response.value);
1924 
1925  time_step_client.call(time_step_srv);
1926 
1927  sampling_period_light_sensor_client.call(sampling_period_light_sensor_srv);
1928  ROS_INFO("Light_sensor is disabled (sampling period is %d).", sampling_period_light_sensor_srv.response.value);
1929 
1930  set_light_sensor_client.shutdown();
1931  sampling_period_light_sensor_client.shutdown();
1932  time_step_client.call(time_step_srv);
1933 
1935  // MOTOR METHODS TEST //
1937 
1938  ros::ServiceClient motor_get_type_client;
1939  webots_ros::get_int motor_get_type_srv;
1940  motor_get_type_client = n.serviceClient<webots_ros::get_int>(model_name + "/rotational_motor/get_type");
1941  motor_get_type_client.call(motor_get_type_srv);
1942  ROS_INFO("Rotational_motor is of type %d.", motor_get_type_srv.response.value);
1943 
1944  motor_get_type_client.shutdown();
1945  time_step_client.call(time_step_srv);
1946 
1947  ros::ServiceClient linear_motor_get_type_client;
1948  webots_ros::get_int linear_motor_get_type_srv;
1949  linear_motor_get_type_client = n.serviceClient<webots_ros::get_int>(model_name + "/linear_motor/get_type");
1950  linear_motor_get_type_client.call(linear_motor_get_type_srv);
1951  ROS_INFO("Linear_motor is of type %d.", linear_motor_get_type_srv.response.value);
1952 
1953  linear_motor_get_type_client.shutdown();
1954  time_step_client.call(time_step_srv);
1955 
1956  // motor_get_brake_name
1957  ros::ServiceClient motor_get_brake_name_client;
1958  webots_ros::get_string motor_get_brake_name_srv;
1959  motor_get_brake_name_client = n.serviceClient<webots_ros::get_string>(model_name + "/linear_motor/get_brake_name");
1960  if (motor_get_brake_name_client.call(motor_get_brake_name_srv)) {
1961  ROS_INFO("Brake name returned from Motor API: %s.", motor_get_brake_name_srv.response.value.c_str());
1962  if (motor_get_brake_name_srv.response.value.compare("my_brake") != 0)
1963  ROS_ERROR("Failed to call service motor_get_brake_name: received '%s' instead of 'my_brake'",
1964  motor_get_brake_name_srv.response.value.c_str());
1965  } else
1966  ROS_ERROR("Failed to call service motor_get_brake_name.");
1967 
1968  motor_get_brake_name_client.shutdown();
1969  time_step_client.call(time_step_srv);
1970 
1971  ros::ServiceClient set_acceleration_client;
1972  webots_ros::set_float set_acceleration_srv;
1973  set_acceleration_client = n.serviceClient<webots_ros::set_float>(model_name + "/rotational_motor/set_acceleration");
1974 
1975  set_acceleration_srv.request.value = 0.5;
1976  if (set_acceleration_client.call(set_acceleration_srv) && set_acceleration_srv.response.success)
1977  ROS_INFO("Acceleration set to 0.5.");
1978  else
1979  ROS_ERROR("Failed to call service set_acceleration on motor.");
1980 
1981  set_acceleration_client.shutdown();
1982  time_step_client.call(time_step_srv);
1983 
1984  ros::ServiceClient set_velocity_client;
1985  webots_ros::set_float set_velocity_srv;
1986  set_velocity_client = n.serviceClient<webots_ros::set_float>(model_name + "/rotational_motor/set_velocity");
1987 
1988  set_velocity_srv.request.value = 0.9;
1989  if (set_velocity_client.call(set_velocity_srv) && set_velocity_srv.response.success)
1990  ROS_INFO("Velocity set to 0.9.");
1991  else
1992  ROS_ERROR("Failed to call service set_velocity on motor.");
1993 
1994  set_velocity_client.shutdown();
1995  time_step_client.call(time_step_srv);
1996 
1997  ros::ServiceClient set_force_client;
1998  webots_ros::set_float set_force_srv;
1999  set_force_client = n.serviceClient<webots_ros::set_float>(model_name + "/linear_motor/set_force");
2000 
2001  set_force_srv.request.value = 0.2;
2002  if (set_force_client.call(set_force_srv) && set_force_srv.response.success)
2003  ROS_INFO("Force set to 0.2.");
2004  else
2005  ROS_ERROR("Failed to call service set_force on motor.");
2006 
2007  set_force_client.shutdown();
2008  time_step_client.call(time_step_srv);
2009 
2010  ros::ServiceClient set_torque_client;
2011  webots_ros::set_float set_torque_srv;
2012  set_torque_client = n.serviceClient<webots_ros::set_float>(model_name + "/rotational_motor/set_torque");
2013 
2014  set_torque_srv.request.value = 0.5;
2015  if (set_torque_client.call(set_torque_srv) && set_torque_srv.response.success)
2016  ROS_INFO("Torque set to 0.5.");
2017  else
2018  ROS_ERROR("Failed to call service set_torque on motor.");
2019 
2020  set_torque_client.shutdown();
2021  time_step_client.call(time_step_srv);
2022 
2023  ros::ServiceClient set_available_force_client;
2024  webots_ros::set_float set_available_force_srv;
2025  set_available_force_client = n.serviceClient<webots_ros::set_float>(model_name + "/linear_motor/set_available_force");
2026 
2027  set_available_force_srv.request.value = 0.8;
2028  if (set_available_force_client.call(set_available_force_srv) && set_available_force_srv.response.success)
2029  ROS_INFO("Available_force set to 0.8.");
2030  else
2031  ROS_ERROR("Failed to call service set_available_force on motor.");
2032 
2033  set_available_force_client.shutdown();
2034  time_step_client.call(time_step_srv);
2035 
2036  ros::ServiceClient set_available_torque_client;
2037  webots_ros::set_float set_available_torque_srv;
2038  set_available_torque_client = n.serviceClient<webots_ros::set_float>(model_name + "/rotational_motor/set_available_torque");
2039 
2040  set_available_torque_srv.request.value = 0.8;
2041  if (set_available_torque_client.call(set_available_torque_srv) && set_available_torque_srv.response.success)
2042  ROS_INFO("Available_torque set to 0.8.");
2043  else
2044  ROS_ERROR("Failed to call service set_available_torque on motor.");
2045 
2046  set_available_torque_client.shutdown();
2047  time_step_client.call(time_step_srv);
2048 
2049  ros::ServiceClient set_control_pid_client;
2050  webots_ros::motor_set_control_pid set_control_pid_srv;
2051  set_control_pid_client = n.serviceClient<webots_ros::motor_set_control_pid>(model_name + "/rotational_motor/set_control_pid");
2052 
2053  set_control_pid_srv.request.controlp = 1;
2054  if (set_control_pid_client.call(set_control_pid_srv) && set_control_pid_srv.response.success == 1)
2055  ROS_INFO("Control p set to 1.");
2056  else
2057  ROS_ERROR("Failed to call service set_controlp on motor.");
2058 
2059  set_control_pid_client.shutdown();
2060  time_step_client.call(time_step_srv);
2061  time_step_client.call(time_step_srv);
2062 
2063  ros::ServiceClient set_linear_control_pid_client;
2064  webots_ros::motor_set_control_pid set_linear_control_pid_srv;
2065  set_linear_control_pid_client =
2066  n.serviceClient<webots_ros::motor_set_control_pid>(model_name + "/linear_motor/set_control_pid");
2067 
2068  set_linear_control_pid_srv.request.controlp = 1;
2069  if (set_linear_control_pid_client.call(set_linear_control_pid_srv) && set_linear_control_pid_srv.response.success == 1)
2070  ROS_INFO("Control p set to 1 for linear_motor.");
2071  else
2072  ROS_ERROR("Failed to call service set_controlp on linear_motor.");
2073 
2074  set_linear_control_pid_client.shutdown();
2075  time_step_client.call(time_step_srv);
2076  time_step_client.call(time_step_srv);
2077 
2078  ros::ServiceClient set_position_client;
2079  webots_ros::set_float set_position_srv;
2080  set_position_client = n.serviceClient<webots_ros::set_float>(model_name + "/rotational_motor/set_position");
2081 
2082  set_position_srv.request.value = 1.5;
2083  if (set_position_client.call(set_position_srv) && set_position_srv.response.success)
2084  ROS_INFO("Position set to 1.5.");
2085  else
2086  ROS_ERROR("Failed to call service set_position on motor.");
2087 
2088  set_position_client.shutdown();
2089  time_step_client.call(time_step_srv);
2090  time_step_client.call(time_step_srv);
2091 
2092  ros::ServiceClient set_linear_position_client;
2093  webots_ros::set_float set_linear_position_srv;
2094  set_linear_position_client = n.serviceClient<webots_ros::set_float>(model_name + "/linear_motor/set_position");
2095 
2096  set_linear_position_srv.request.value = 0.3;
2097  if (set_linear_position_client.call(set_linear_position_srv) && set_linear_position_srv.response.success)
2098  ROS_INFO("Position set to 0.3 for linear_motor.");
2099  else
2100  ROS_ERROR("Failed to call service set_position on linear_motor.");
2101 
2102  set_linear_position_client.shutdown();
2103  time_step_client.call(time_step_srv);
2104 
2105  ros::ServiceClient get_target_position_client;
2106  webots_ros::get_float get_target_position_srv;
2107  get_target_position_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_target_position");
2108 
2109  get_target_position_client.call(get_target_position_srv);
2110  ROS_INFO("Target position for rotational_motor is %f.", get_target_position_srv.response.value);
2111 
2112  get_target_position_client.shutdown();
2113  time_step_client.call(time_step_srv);
2114 
2115  ros::ServiceClient get_min_position_client;
2116  webots_ros::get_float get_min_position_srv;
2117  get_min_position_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_min_position");
2118 
2119  get_min_position_client.call(get_min_position_srv);
2120  ROS_INFO("Min position for rotational_motor is %f.", get_min_position_srv.response.value);
2121 
2122  get_min_position_client.shutdown();
2123  time_step_client.call(time_step_srv);
2124 
2125  ros::ServiceClient get_max_position_client;
2126  webots_ros::get_float get_max_position_srv;
2127  get_max_position_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_max_position");
2128 
2129  get_max_position_client.call(get_max_position_srv);
2130  ROS_INFO("Max position for rotational_motor is %f.", get_max_position_srv.response.value);
2131 
2132  get_max_position_client.shutdown();
2133  time_step_client.call(time_step_srv);
2134 
2135  ros::ServiceClient get_velocity_client;
2136  webots_ros::get_float get_velocity_srv;
2137  get_velocity_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_velocity");
2138 
2139  get_velocity_client.call(get_velocity_srv);
2140  ROS_INFO("Velocity for rotational_motor is %f.", get_velocity_srv.response.value);
2141 
2142  get_velocity_client.shutdown();
2143  time_step_client.call(time_step_srv);
2144 
2145  ros::ServiceClient get_max_velocity_client;
2146  webots_ros::get_float get_max_velocity_srv;
2147  get_max_velocity_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_max_velocity");
2148 
2149  get_max_velocity_client.call(get_max_velocity_srv);
2150  ROS_INFO("Max velocity for rotational_motor is %f.", get_max_velocity_srv.response.value);
2151 
2152  get_max_velocity_client.shutdown();
2153  time_step_client.call(time_step_srv);
2154 
2155  ros::ServiceClient get_acceleration_client;
2156  webots_ros::get_float get_acceleration_srv;
2157  get_acceleration_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_acceleration");
2158 
2159  get_acceleration_client.call(get_acceleration_srv);
2160  ROS_INFO("Acceleration for rotational_motor is %f.", get_acceleration_srv.response.value);
2161 
2162  get_acceleration_client.shutdown();
2163  time_step_client.call(time_step_srv);
2164 
2165  ros::ServiceClient get_available_force_client;
2166  webots_ros::get_float get_available_force_srv;
2167  get_available_force_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_available_force");
2168 
2169  get_available_force_client.call(get_available_force_srv);
2170  ROS_INFO("Available force for rotational_motor is %f.", get_available_force_srv.response.value);
2171 
2172  get_available_force_client.shutdown();
2173  time_step_client.call(time_step_srv);
2174 
2175  ros::ServiceClient get_max_force_client;
2176  webots_ros::get_float get_max_force_srv;
2177  get_max_force_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_max_force");
2178 
2179  get_max_force_client.call(get_max_force_srv);
2180  ROS_INFO("Max force for rotational_motor is %f.", get_max_force_srv.response.value);
2181 
2182  get_max_force_client.shutdown();
2183  time_step_client.call(time_step_srv);
2184 
2185  ros::ServiceClient get_available_torque_client;
2186  webots_ros::get_float get_available_torque_srv;
2187  get_available_torque_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_available_torque");
2188 
2189  get_available_torque_client.call(get_available_torque_srv);
2190  ROS_INFO("Available torque for rotational_motor is %f.", get_available_torque_srv.response.value);
2191 
2192  get_available_torque_client.shutdown();
2193  time_step_client.call(time_step_srv);
2194 
2195  ros::ServiceClient get_max_torque_client;
2196  webots_ros::get_float get_max_torque_srv;
2197  get_max_torque_client = n.serviceClient<webots_ros::get_float>(model_name + "/rotational_motor/get_max_torque");
2198 
2199  get_max_torque_client.call(get_max_torque_srv);
2200  ROS_INFO("Max torque for rotational_motor is %f.", get_max_torque_srv.response.value);
2201 
2202  get_max_torque_client.shutdown();
2203  time_step_client.call(time_step_srv);
2204 
2205  ros::ServiceClient set_motor_feedback_client;
2206  webots_ros::set_int motor_feedback_srv;
2207  ros::Subscriber sub_motor_feedback_32;
2208  set_motor_feedback_client =
2209  n.serviceClient<webots_ros::set_int>(model_name + "/rotational_motor/torque_feedback_sensor/enable");
2210 
2211  ros::ServiceClient sampling_period_motor_feedback_client;
2212  webots_ros::get_int sampling_period_motor_feedback_srv;
2213  sampling_period_motor_feedback_client =
2214  n.serviceClient<webots_ros::get_int>(model_name + "/rotational_motor/torque_feedback_sensor/get_sampling_period");
2215 
2216  motor_feedback_srv.request.value = 32;
2217  if (set_motor_feedback_client.call(motor_feedback_srv) && motor_feedback_srv.response.success) {
2218  ROS_INFO("Motor feedback enabled.");
2219  sub_motor_feedback_32 = n.subscribe(model_name + "/rotational_motor/torque_feedback", 1, motorSensorCallback);
2220  callbackCalled = false;
2221  while (sub_motor_feedback_32.getNumPublishers() == 0 && !callbackCalled) {
2222  ros::spinOnce();
2223  time_step_client.call(time_step_srv);
2224  }
2225  } else {
2226  if (!motor_feedback_srv.response.success)
2227  ROS_ERROR("Sampling period is not valid.");
2228  ROS_ERROR("Failed to enable motor_feedback.");
2229  return 1;
2230  }
2231 
2232  sub_motor_feedback_32.shutdown();
2233 
2234  time_step_client.call(time_step_srv);
2235 
2236  sampling_period_motor_feedback_client.call(sampling_period_motor_feedback_srv);
2237  ROS_INFO("Motor feedback is enabled with a sampling period of %d.", sampling_period_motor_feedback_srv.response.value);
2238 
2239  time_step_client.call(time_step_srv);
2240 
2241  sampling_period_motor_feedback_client.call(sampling_period_motor_feedback_srv);
2242  ROS_INFO("Motor feedback is disabled (sampling period is %d).", sampling_period_motor_feedback_srv.response.value);
2243 
2244  set_motor_feedback_client.shutdown();
2245  sampling_period_motor_feedback_client.shutdown();
2246  time_step_client.call(time_step_srv);
2247  time_step_client.call(time_step_srv);
2248 
2250  // PEN METHODS TEST //
2252 
2253  ros::ServiceClient set_ink_color_client;
2254  webots_ros::pen_set_ink_color set_ink_color_srv;
2255  set_ink_color_client = n.serviceClient<webots_ros::pen_set_ink_color>(model_name + "/pen/set_ink_color");
2256 
2257  set_ink_color_srv.request.color = 0x00FF08;
2258  if (set_ink_color_client.call(set_ink_color_srv) && set_ink_color_srv.response.success == 1)
2259  ROS_INFO("Ink color set to turquoise.");
2260  else
2261  ROS_ERROR("Failed to call service set_ink_color.");
2262 
2263  set_ink_color_client.shutdown();
2264  time_step_client.call(time_step_srv);
2265 
2266  ros::ServiceClient pen_write_client;
2267  webots_ros::set_bool pen_write_srv;
2268  pen_write_client = n.serviceClient<webots_ros::set_bool>(model_name + "/pen/write");
2269 
2270  pen_write_srv.request.value = true;
2271  if (pen_write_client.call(pen_write_srv) && pen_write_srv.response.success)
2272  ROS_INFO("Pen is now writing.");
2273  else
2274  ROS_ERROR("Failed to call service pen_write.");
2275 
2276  pen_write_client.shutdown();
2277  time_step_client.call(time_step_srv);
2278  time_step_client.call(time_step_srv);
2279 
2281  // POSITION SENSOR METHODS TEST //
2283 
2284  ros::ServiceClient set_position_sensor_client;
2285  webots_ros::set_int position_sensor_srv;
2286  ros::Subscriber sub_position_sensor_32;
2287  set_position_sensor_client = n.serviceClient<webots_ros::set_int>(model_name + "/position_sensor/enable");
2288 
2289  ros::ServiceClient sampling_period_position_sensor_client;
2290  webots_ros::get_int sampling_period_position_sensor_srv;
2291  sampling_period_position_sensor_client =
2292  n.serviceClient<webots_ros::get_int>(model_name + "/position_sensor/get_sampling_period");
2293 
2294  position_sensor_srv.request.value = 32;
2295  if (set_position_sensor_client.call(position_sensor_srv) && position_sensor_srv.response.success) {
2296  ROS_INFO("Position_sensor enabled.");
2297  sub_position_sensor_32 = n.subscribe(model_name + "/position_sensor/value", 1, positionSensorCallback);
2298  callbackCalled = false;
2299  while (sub_position_sensor_32.getNumPublishers() == 0 && !callbackCalled) {
2300  ros::spinOnce();
2301  time_step_client.call(time_step_srv);
2302  }
2303  } else {
2304  if (!position_sensor_srv.response.success)
2305  ROS_ERROR("Sampling period is not valid.");
2306  ROS_ERROR("Failed to enable position_sensor.");
2307  return 1;
2308  }
2309 
2310  sub_position_sensor_32.shutdown();
2311 
2312  time_step_client.call(time_step_srv);
2313 
2314  sampling_period_position_sensor_client.call(sampling_period_position_sensor_srv);
2315  ROS_INFO("Position_sensor is enabled with a sampling period of %d.", sampling_period_position_sensor_srv.response.value);
2316 
2317  time_step_client.call(time_step_srv);
2318 
2319  ros::ServiceClient position_sensor_get_type_client;
2320  webots_ros::get_int position_sensor_get_type_srv;
2321  position_sensor_get_type_client = n.serviceClient<webots_ros::get_int>(model_name + "/position_sensor/get_type");
2322 
2323  position_sensor_get_type_client.call(position_sensor_get_type_srv);
2324  ROS_INFO("Position_sensor is of type %d.", position_sensor_get_type_srv.response.value);
2325 
2326  position_sensor_get_type_client.shutdown();
2327  time_step_client.call(time_step_srv);
2328 
2329  sampling_period_position_sensor_client.call(sampling_period_position_sensor_srv);
2330  ROS_INFO("Position_sensor is disabled (sampling period is %d).", sampling_period_position_sensor_srv.response.value);
2331 
2332  set_position_sensor_client.shutdown();
2333  sampling_period_position_sensor_client.shutdown();
2334  time_step_client.call(time_step_srv);
2335 
2337  // RADAR METHODS TEST //
2339 
2340  // radar enable
2341  ros::ServiceClient set_radar_client;
2342  webots_ros::set_int radar_srv;
2343  ros::Subscriber sub_radar_target;
2344  ros::Subscriber sub_radar_target_number;
2345 
2346  set_radar_client = n.serviceClient<webots_ros::set_int>(model_name + "/radar/enable");
2347  radar_srv.request.value = TIME_STEP;
2348  if (set_radar_client.call(radar_srv) && radar_srv.response.success) {
2349  ROS_INFO("Radar enabled.");
2350  sub_radar_target = n.subscribe(model_name + "/radar/targets", 1, radarTargetsCallback);
2351  sub_radar_target_number = n.subscribe(model_name + "/radar/number_of_targets", 1, radarTargetsNumberCallback);
2352  callbackCalled = false;
2353  ROS_INFO("Topics for radar initialized.");
2354 
2355  while (sub_radar_target.getNumPublishers() == 0 && sub_radar_target_number.getNumPublishers() == 0 && !callbackCalled) {
2356  ros::spinOnce();
2357  time_step_client.call(time_step_srv);
2358  }
2359  ROS_INFO("Topics for radar connected.");
2360  } else {
2361  if (!radar_srv.response.success)
2362  ROS_ERROR("Sampling period is not valid.");
2363  ROS_ERROR("Failed to enable radar.");
2364  return 1;
2365  }
2366 
2367  sub_radar_target.shutdown();
2368  sub_radar_target_number.shutdown();
2369  set_radar_client.shutdown();
2370  time_step_client.call(time_step_srv);
2371 
2372  // get max and min range
2373  ros::ServiceClient radar_range_client = n.serviceClient<webots_ros::get_float>(model_name + "/radar/get_max_range");
2374  webots_ros::get_float radar_get_max_range_srv;
2375  if (radar_range_client.call(radar_get_max_range_srv)) {
2376  if (radar_get_max_range_srv.response.value == 2.0)
2377  ROS_INFO("Received correct radar max range.");
2378  else
2379  ROS_ERROR("Received wrong radar max range.");
2380  } else
2381  ROS_ERROR("Failed to call service radar_get_max_range.");
2382 
2383  radar_range_client.shutdown();
2384  time_step_client.call(time_step_srv);
2385 
2386  radar_range_client = n.serviceClient<webots_ros::get_float>(model_name + "/radar/get_min_range");
2387  webots_ros::get_float radar_get_min_range_srv;
2388  if (radar_range_client.call(radar_get_min_range_srv)) {
2389  if (radar_get_min_range_srv.response.value == 1.0)
2390  ROS_INFO("Received correct radar min range.");
2391  else
2392  ROS_ERROR("Received wrong radar min range.");
2393  } else
2394  ROS_ERROR("Failed to call service radar_get_min_range.");
2395 
2396  radar_range_client.shutdown();
2397  time_step_client.call(time_step_srv);
2398 
2399  ROS_INFO("Radar disabled.");
2400 
2402  // RANGE-FINDER METHODS TEST //
2404 
2405  // range-finder enable
2406  ros::ServiceClient set_range_finder_client;
2407  webots_ros::set_int range_finder_srv;
2408  ros::Subscriber sub_range_finder_color;
2409 
2410  set_range_finder_client = n.serviceClient<webots_ros::set_int>(model_name + "/range_finder/enable");
2411  range_finder_srv.request.value = TIME_STEP;
2412  if (set_range_finder_client.call(range_finder_srv) && range_finder_srv.response.success) {
2413  ROS_INFO("Range-finder enabled.");
2414  sub_range_finder_color = n.subscribe(model_name + "/range_finder/range_image", 1, rangeFinderCallback);
2415  callbackCalled = false;
2416  ROS_INFO("Topic for range-finder initialized.");
2417 
2418  while (sub_range_finder_color.getNumPublishers() == 0 && !callbackCalled) {
2419  ros::spinOnce();
2420  time_step_client.call(time_step_srv);
2421  }
2422  ROS_INFO("Topic for range-finder connected.");
2423  } else {
2424  if (!range_finder_srv.response.success)
2425  ROS_ERROR("Sampling period is not valid.");
2426  ROS_ERROR("Failed to enable range-finder.");
2427  return 1;
2428  }
2429 
2430  sub_range_finder_color.shutdown();
2431  set_range_finder_client.shutdown();
2432  time_step_client.call(time_step_srv);
2433 
2434  // range_finder_get_info
2435  get_info_client = n.serviceClient<webots_ros::range_finder_get_info>(model_name + "/range_finder/get_info");
2436  webots_ros::range_finder_get_info get_range_finder_info_srv;
2437  if (get_info_client.call(get_range_finder_info_srv))
2438  ROS_INFO(
2439  "Range-finder of %s has a width of %d, a height of %d, a field of view of %f, a min range of %f and a max range of %f.",
2440  model_name.c_str(), get_range_finder_info_srv.response.width, get_range_finder_info_srv.response.height,
2441  get_range_finder_info_srv.response.Fov, get_range_finder_info_srv.response.minRange,
2442  get_range_finder_info_srv.response.maxRange);
2443  else
2444  ROS_ERROR("Failed to call service range_finder_get_info.");
2445 
2446  get_info_client.shutdown();
2447  time_step_client.call(time_step_srv);
2448 
2449  // range_finder_save_image
2450  save_image_client = n.serviceClient<webots_ros::save_image>(model_name + "/range_finder/save_image");
2451  webots_ros::save_image save_range_image_srv;
2452  save_range_image_srv.request.filename = std::string(getenv("HOME")) + std::string("/test_image_range_finder.png");
2453  save_range_image_srv.request.quality = 100;
2454 
2455  if (save_image_client.call(save_range_image_srv) && save_range_image_srv.response.success == 1)
2456  ROS_INFO("Image saved.");
2457  else
2458  ROS_ERROR("Failed to call service save_image.");
2459 
2460  save_image_client.shutdown();
2461  time_step_client.call(time_step_srv);
2462 
2463  ROS_INFO("Range-finder disabled.");
2464 
2466  // RECEIVER METHODS TEST //
2468 
2469  ros::ServiceClient set_receiver_client;
2470  webots_ros::set_int receiver_srv;
2471  ros::Subscriber sub_receiver_32;
2472  set_receiver_client = n.serviceClient<webots_ros::set_int>(model_name + "/receiver/enable");
2473 
2474  ros::ServiceClient sampling_period_receiver_client;
2475  webots_ros::get_int sampling_period_receiver_srv;
2476  sampling_period_receiver_client = n.serviceClient<webots_ros::get_int>(model_name + "/receiver/get_sampling_period");
2477 
2478  receiver_srv.request.value = 32;
2479  if (set_receiver_client.call(receiver_srv) && receiver_srv.response.success) {
2480  ROS_INFO("Receiver enabled.");
2481  sub_receiver_32 = n.subscribe(model_name + "/receiver/data", 1, receiverCallback);
2482  callbackCalled = false;
2483  while (sub_receiver_32.getNumPublishers() == 0 && !callbackCalled) {
2484  ros::spinOnce();
2485  time_step_client.call(time_step_srv);
2486  }
2487  } else {
2488  if (!receiver_srv.response.success)
2489  ROS_ERROR("Sampling period is not valid.");
2490  ROS_ERROR("Failed to enable receiver.");
2491  return 1;
2492  }
2493 
2494  sub_receiver_32.shutdown();
2495  set_receiver_client.shutdown();
2496  time_step_client.call(time_step_srv);
2497 
2498  sampling_period_receiver_client.call(sampling_period_receiver_srv);
2499  ROS_INFO("Receiver is enabled with a sampling period of %d.", sampling_period_receiver_srv.response.value);
2500 
2501  time_step_client.call(time_step_srv);
2502  time_step_client.call(time_step_srv);
2503 
2504  // test receiver_get_data_size
2505  // An error message will probably appear since no data has been sent to the receiver.
2506  ros::ServiceClient receiver_get_data_size_client;
2507  webots_ros::get_int receiver_get_data_size_srv;
2508  receiver_get_data_size_client = n.serviceClient<webots_ros::get_int>(model_name + "/receiver/get_data_size");
2509 
2510  receiver_get_data_size_client.call(receiver_get_data_size_srv);
2511  if (receiver_get_data_size_srv.response.value != -1)
2512  ROS_INFO("Emitter's buffer is of size %d.", receiver_get_data_size_srv.response.value);
2513  else
2514  ROS_INFO("No message received by emitter, impossible to get buffer size.");
2515 
2516  receiver_get_data_size_client.shutdown();
2517  time_step_client.call(time_step_srv);
2518  time_step_client.call(time_step_srv);
2519 
2520  ros::ServiceClient receiver_set_channel_client;
2521  webots_ros::set_int receiver_set_channel_srv;
2522  receiver_set_channel_client = n.serviceClient<webots_ros::set_int>(model_name + "/receiver/set_channel");
2523 
2524  receiver_set_channel_srv.request.value = 1;
2525 
2526  if (receiver_set_channel_client.call(receiver_set_channel_srv) && receiver_set_channel_srv.response.success)
2527  ROS_INFO("Receiver has update the channel.");
2528  else
2529  ROS_ERROR("Failed to call service receiver_set_channel to update channel.");
2530 
2531  receiver_set_channel_client.shutdown();
2532  time_step_client.call(time_step_srv);
2533 
2534  // test receiver_get_channel
2535  ros::ServiceClient receiver_get_channel_client;
2536  webots_ros::get_int receiver_get_channel_srv;
2537  receiver_get_channel_client = n.serviceClient<webots_ros::get_int>(model_name + "/receiver/get_channel");
2538 
2539  receiver_get_channel_client.call(receiver_get_channel_srv);
2540  ROS_INFO("Receiver uses channel %d.", receiver_get_channel_srv.response.value);
2541 
2542  receiver_get_channel_client.shutdown();
2543  time_step_client.call(time_step_srv);
2544 
2545  // test receiver_get_queue_length
2546  ros::ServiceClient receiver_get_queue_length_client;
2547  webots_ros::get_int receiver_get_queue_length_srv;
2548  receiver_get_queue_length_client = n.serviceClient<webots_ros::get_int>(model_name + "/receiver/get_queue_length");
2549 
2550  receiver_get_queue_length_client.call(receiver_get_queue_length_srv);
2551  ROS_INFO("Length of receiver queue is %d.", receiver_get_queue_length_srv.response.value);
2552 
2553  receiver_get_queue_length_client.shutdown();
2554  time_step_client.call(time_step_srv);
2555 
2556  // test receiver_get_signal_strength
2557  // An error message will probably appear since no signal has been sent to the receiver.
2558  ros::ServiceClient receiver_get_signal_strength_client;
2559  webots_ros::get_float receiver_get_signal_strength_srv;
2560  receiver_get_signal_strength_client = n.serviceClient<webots_ros::get_float>(model_name + "/receiver/get_signal_strength");
2561 
2562  receiver_get_signal_strength_client.call(receiver_get_signal_strength_srv);
2563  if (receiver_get_signal_strength_srv.response.value != -1.0)
2564  ROS_INFO("Strength of the signal is %lf.", receiver_get_signal_strength_srv.response.value);
2565  else
2566  ROS_INFO("No message received by emitter, impossible to get signal strength.");
2567 
2568  receiver_get_signal_strength_client.shutdown();
2569  time_step_client.call(time_step_srv);
2570 
2571  // test receiver_get_emitter_direction
2572  // An error message will probably appear since no signal has been sent to the receiver
2573  ros::ServiceClient receiver_get_emitter_direction_client;
2574  webots_ros::receiver_get_emitter_direction receiver_get_emitter_direction_srv;
2575  receiver_get_emitter_direction_client =
2576  n.serviceClient<webots_ros::receiver_get_emitter_direction>(model_name + "/receiver/get_emitter_direction");
2577 
2578  receiver_get_emitter_direction_client.call(receiver_get_emitter_direction_srv);
2579  if (receiver_get_emitter_direction_srv.response.direction[0] != 0 ||
2580  receiver_get_emitter_direction_srv.response.direction[1] != 0 ||
2581  receiver_get_emitter_direction_srv.response.direction[2] != 0)
2582  ROS_INFO("Signal from emitter comes from direction {%f. %f, %f}.", receiver_get_emitter_direction_srv.response.direction[0],
2583  receiver_get_emitter_direction_srv.response.direction[1],
2584  receiver_get_emitter_direction_srv.response.direction[2]);
2585  else
2586  ROS_INFO("No message received by emitter, impossible to get signal direction.");
2587 
2588  receiver_get_emitter_direction_client.shutdown();
2589  time_step_client.call(time_step_srv);
2590 
2591  // test receiver_next_packet
2592  // An error message will probably appear since there is no packet to read
2593  ros::ServiceClient receiver_next_packet_client;
2594  webots_ros::get_bool receiver_next_packet_srv;
2595  receiver_next_packet_client = n.serviceClient<webots_ros::get_bool>(model_name + "/receiver/next_packet");
2596 
2597  if (receiver_next_packet_client.call(receiver_next_packet_srv) && receiver_next_packet_srv.response.value)
2598  ROS_INFO("Next packet is ready to be read.");
2599  else if (!receiver_next_packet_srv.response.value)
2600  ROS_INFO("No message received by emitter, impossible to get next packet.");
2601  else
2602  ROS_ERROR("Failed to call service receiver_next_packet.");
2603 
2604  receiver_next_packet_client.shutdown();
2605  time_step_client.call(time_step_srv);
2606 
2607  sampling_period_receiver_client.call(sampling_period_receiver_srv);
2608  ROS_INFO("Receiver is disabled (sampling period is %d).", sampling_period_receiver_srv.response.value);
2609 
2610  sampling_period_receiver_client.shutdown();
2611  time_step_client.call(time_step_srv);
2612 
2614  // TOUCH SENSOR METHODS TEST //
2616 
2617  ros::ServiceClient set_touch_sensor_client;
2618  webots_ros::set_int touch_sensor_srv;
2619  ros::Subscriber sub_touch_sensor_32;
2620  set_touch_sensor_client = n.serviceClient<webots_ros::set_int>(model_name + "/touch_sensor/enable");
2621 
2622  ros::ServiceClient sampling_period_touch_sensor_client;
2623  webots_ros::get_int sampling_period_touch_sensor_srv;
2624  sampling_period_touch_sensor_client = n.serviceClient<webots_ros::get_int>(model_name + "/touch_sensor/get_sampling_period");
2625 
2626  ros::ServiceClient touch_sensor_get_type_client;
2627  webots_ros::get_int touch_sensor_get_type_srv;
2628  touch_sensor_get_type_client = n.serviceClient<webots_ros::get_int>(model_name + "/touch_sensor/get_type");
2629 
2630  touch_sensor_get_type_client.call(touch_sensor_get_type_srv);
2631  ROS_INFO("Touch_sensor is of type %d.", touch_sensor_get_type_srv.response.value);
2632 
2633  touch_sensor_get_type_client.shutdown();
2634  time_step_client.call(time_step_srv);
2635 
2636  touch_sensor_srv.request.value = 32;
2637  if (set_touch_sensor_client.call(touch_sensor_srv) && touch_sensor_srv.response.success) {
2638  ROS_INFO("Touch_sensor enabled.");
2639  if (touch_sensor_get_type_srv.response.value == 0)
2640  sub_touch_sensor_32 = n.subscribe(model_name + "/touch_sensor/value", 1, touchSensorBumperCallback);
2641  else if (touch_sensor_get_type_srv.response.value == 1)
2642  sub_touch_sensor_32 = n.subscribe(model_name + "/touch_sensor/value", 1, touchSensorCallback);
2643  else
2644  sub_touch_sensor_32 = n.subscribe(model_name + "/touch_sensor/values", 1, touchSensor3DCallback);
2645  callbackCalled = false;
2646  while (sub_touch_sensor_32.getNumPublishers() == 0 && !callbackCalled) {
2647  ros::spinOnce();
2648  time_step_client.call(time_step_srv);
2649  }
2650  } else {
2651  if (!touch_sensor_srv.response.success)
2652  ROS_ERROR("Sampling period is not valid.");
2653  ROS_ERROR("Failed to enable touch_sensor.");
2654  return 1;
2655  }
2656 
2657  sub_touch_sensor_32.shutdown();
2658 
2659  ros::ServiceClient lookup_table_touch_sensor_client;
2660  webots_ros::get_float_array lookup_table_touch_sensor_srv;
2661  lookup_table_touch_sensor_client =
2662  n.serviceClient<webots_ros::get_float_array>(model_name + "/touch_sensor/get_lookup_table");
2663  if (lookup_table_touch_sensor_client.call(lookup_table_touch_sensor_srv))
2664  ROS_INFO("Touch sensor lookup table size = %lu.", lookup_table_touch_sensor_srv.response.value.size());
2665  else
2666  ROS_ERROR("Failed to get the lookup table of 'touch_sensor'.");
2667  if (lookup_table_touch_sensor_srv.response.value.size() != 6)
2668  ROS_ERROR("Size of lookup table of 'touch_sensor' is wrong.");
2669  lookup_table_touch_sensor_client.shutdown();
2670 
2671  time_step_client.call(time_step_srv);
2672 
2673  sampling_period_touch_sensor_client.call(sampling_period_touch_sensor_srv);
2674  ROS_INFO("Touch_sensor is enabled with a sampling period of %d.", sampling_period_touch_sensor_srv.response.value);
2675 
2676  time_step_client.call(time_step_srv);
2677 
2678  sampling_period_touch_sensor_client.call(sampling_period_touch_sensor_srv);
2679  ROS_INFO("Touch_sensor is disabled (sampling period is %d).", sampling_period_touch_sensor_srv.response.value);
2680 
2681  set_touch_sensor_client.shutdown();
2682  sampling_period_touch_sensor_client.shutdown();
2683  time_step_client.call(time_step_srv);
2684 
2686  // SUPERVISOR METHODS TEST //
2688 
2689  ros::ServiceClient supervisor_simulation_reset_physics_client;
2690  webots_ros::get_bool supervisor_simulation_reset_physics_srv;
2691  supervisor_simulation_reset_physics_client =
2692  n.serviceClient<webots_ros::get_bool>(model_name + "/supervisor/simulation_reset_physics");
2693 
2694  if (supervisor_simulation_reset_physics_client.call(supervisor_simulation_reset_physics_srv) &&
2695  supervisor_simulation_reset_physics_srv.response.value)
2696  ROS_INFO("Simulation has reset_physics successfully.");
2697  else
2698  ROS_ERROR("Failed to call service simulation_reset_physics.");
2699 
2700  supervisor_simulation_reset_physics_client.shutdown();
2701  time_step_client.call(time_step_srv);
2702 
2703  ros::ServiceClient supervisor_export_image_client;
2704  webots_ros::save_image supervisor_export_image_srv;
2705  supervisor_export_image_client = n.serviceClient<webots_ros::save_image>(model_name + "/supervisor/export_image");
2706 
2707  supervisor_export_image_srv.request.filename = std::string(getenv("HOME")) + std::string("/main_window_test.jpg");
2708  supervisor_export_image_srv.request.quality = 100;
2709  if (supervisor_export_image_client.call(supervisor_export_image_srv) && supervisor_export_image_srv.response.success == 1)
2710  ROS_INFO("Image from main window saved successfully.");
2711  else
2712  ROS_ERROR("Failed to call service export_image.");
2713 
2714  supervisor_export_image_client.shutdown();
2715  time_step_client.call(time_step_srv);
2716 
2717  ros::ServiceClient supervisor_set_label_client;
2718  webots_ros::supervisor_set_label supervisor_set_label_srv;
2719  supervisor_set_label_client = n.serviceClient<webots_ros::supervisor_set_label>(model_name + "/supervisor/set_label");
2720 
2721  supervisor_set_label_srv.request.id = 1;
2722  supervisor_set_label_srv.request.label = "This is a label";
2723  supervisor_set_label_srv.request.xpos = 0.02;
2724  supervisor_set_label_srv.request.ypos = 0.2;
2725  supervisor_set_label_srv.request.size = 0.1;
2726  supervisor_set_label_srv.request.color = 0XFF0000;
2727  supervisor_set_label_srv.request.transparency = 0;
2728  supervisor_set_label_srv.request.font = "Lucida Console";
2729  if (supervisor_set_label_client.call(supervisor_set_label_srv) && supervisor_set_label_srv.response.success == 1)
2730  ROS_INFO("Label set successfully.");
2731  else
2732  ROS_ERROR("Failed to call service set_label.");
2733 
2734  time_step_client.call(time_step_srv);
2735 
2736  ros::ServiceClient supervisor_get_root_client;
2737  webots_ros::get_uint64 supervisor_get_root_srv;
2738  supervisor_get_root_client = n.serviceClient<webots_ros::get_uint64>(model_name + "/supervisor/get_root");
2739 
2740  supervisor_get_root_client.call(supervisor_get_root_srv);
2741  ROS_INFO("Got root node: %lu.", supervisor_get_root_srv.response.value);
2742  uint64_t root_node = supervisor_get_root_srv.response.value;
2743 
2744  supervisor_get_root_client.shutdown();
2745  time_step_client.call(time_step_srv);
2746 
2747  ros::ServiceClient supervisor_get_self_client;
2748  webots_ros::get_uint64 supervisor_get_self_srv;
2749  supervisor_get_self_client = n.serviceClient<webots_ros::get_uint64>(model_name + "/supervisor/get_self");
2750 
2751  supervisor_get_self_client.call(supervisor_get_self_srv);
2752  ROS_INFO("Got self node: %lu.", supervisor_get_self_srv.response.value);
2753  uint64_t self_node = supervisor_get_self_srv.response.value;
2754 
2755  supervisor_get_self_client.shutdown();
2756  time_step_client.call(time_step_srv);
2757 
2758  ros::ServiceClient supervisor_get_from_def_client;
2759  webots_ros::supervisor_get_from_def supervisor_get_from_def_srv;
2760  supervisor_get_from_def_client =
2761  n.serviceClient<webots_ros::supervisor_get_from_def>(model_name + "/supervisor/get_from_def");
2762 
2763  supervisor_get_from_def_srv.request.name = "TEST";
2764  supervisor_get_from_def_client.call(supervisor_get_from_def_srv);
2765  uint64_t from_def_node = 0;
2766  if (supervisor_get_from_def_srv.response.node != 0) {
2767  ROS_INFO("Got from DEF node: %ld.", supervisor_get_from_def_srv.response.node);
2768  from_def_node = supervisor_get_from_def_srv.response.node;
2769  } else
2770  ROS_ERROR("Could not get node from DEF.");
2771 
2772  time_step_client.call(time_step_srv);
2773 
2774  ros::ServiceClient supervisor_node_get_type_client;
2775  webots_ros::node_get_type supervisor_node_get_type_srv;
2776  supervisor_node_get_type_client = n.serviceClient<webots_ros::node_get_type>(model_name + "/supervisor/node/get_type");
2777 
2778  supervisor_node_get_type_srv.request.node = from_def_node;
2779  supervisor_node_get_type_client.call(supervisor_node_get_type_srv);
2780  ROS_INFO("Got node type: %d.", supervisor_node_get_type_srv.response.type);
2781 
2782  supervisor_node_get_type_client.shutdown();
2783  time_step_client.call(time_step_srv);
2784 
2785  ros::ServiceClient supervisor_node_get_type_name_client;
2786  webots_ros::node_get_name supervisor_node_get_type_name_srv;
2787  supervisor_node_get_type_name_client =
2788  n.serviceClient<webots_ros::node_get_name>(model_name + "/supervisor/node/get_type_name");
2789 
2790  supervisor_node_get_type_name_srv.request.node = from_def_node;
2791  supervisor_node_get_type_name_client.call(supervisor_node_get_type_name_srv);
2792  ROS_INFO("Got node type name: %s.", supervisor_node_get_type_name_srv.response.name.c_str());
2793 
2794  supervisor_node_get_type_name_srv.request.node = root_node;
2795  supervisor_node_get_type_name_client.call(supervisor_node_get_type_name_srv);
2796  ROS_INFO("Got type name of root node: %s.", supervisor_node_get_type_name_srv.response.name.c_str());
2797 
2798  supervisor_node_get_type_name_srv.request.node = self_node;
2799  supervisor_node_get_type_name_client.call(supervisor_node_get_type_name_srv);
2800  ROS_INFO("Got type name of self node: %s.", supervisor_node_get_type_name_srv.response.name.c_str());
2801 
2802  supervisor_get_from_def_srv.request.name = "GROUND";
2803  supervisor_get_from_def_client.call(supervisor_get_from_def_srv);
2804  uint64_t ground_node = 0;
2805  if (supervisor_get_from_def_srv.response.node != 0) {
2806  ROS_INFO("Got from DEF GROUND node: %ld.", supervisor_get_from_def_srv.response.node);
2807  ground_node = supervisor_get_from_def_srv.response.node;
2808  } else
2809  ROS_ERROR("Could not get node from DEF GROUND.");
2810 
2811  supervisor_node_get_type_name_srv.request.node = ground_node;
2812  supervisor_node_get_type_name_client.call(supervisor_node_get_type_name_srv);
2813  ROS_INFO("Got type name of GROUND node: %s.", supervisor_node_get_type_name_srv.response.name.c_str());
2814 
2815  time_step_client.call(time_step_srv);
2816 
2817  ros::ServiceClient supervisor_node_get_base_type_name_client;
2818  webots_ros::node_get_name supervisor_node_get_base_type_name_srv;
2819  supervisor_node_get_base_type_name_client =
2820  n.serviceClient<webots_ros::node_get_name>(model_name + "/supervisor/node/get_base_type_name");
2821  supervisor_node_get_base_type_name_srv.request.node = ground_node;
2822  supervisor_node_get_base_type_name_client.call(supervisor_node_get_base_type_name_srv);
2823  ROS_INFO("Got base type name of GROUND node: %s.", supervisor_node_get_base_type_name_srv.response.name.c_str());
2824 
2825  supervisor_node_get_base_type_name_client.shutdown();
2826  time_step_client.call(time_step_srv);
2827 
2828  ros::ServiceClient supervisor_node_get_def_client;
2829  webots_ros::node_get_name supervisor_node_get_def_srv;
2830  supervisor_node_get_def_client = n.serviceClient<webots_ros::node_get_name>(model_name + "/supervisor/node/get_def");
2831  supervisor_node_get_def_srv.request.node = ground_node;
2832  supervisor_node_get_def_client.call(supervisor_node_get_def_srv);
2833  ROS_INFO("Got DEF name of GROUND node: %s.", supervisor_node_get_def_srv.response.name.c_str());
2834 
2835  supervisor_node_get_def_client.shutdown();
2836  time_step_client.call(time_step_srv);
2837 
2838  ros::ServiceClient supervisor_node_get_position_client;
2839  webots_ros::node_get_position supervisor_node_get_position_srv;
2840  supervisor_node_get_position_client =
2841  n.serviceClient<webots_ros::node_get_position>(model_name + "/supervisor/node/get_position");
2842 
2843  supervisor_node_get_position_srv.request.node = from_def_node;
2844  supervisor_node_get_position_client.call(supervisor_node_get_position_srv);
2845  ROS_INFO("From_def node got position: x = %f y = %f z = %f.", supervisor_node_get_position_srv.response.position.x,
2846  supervisor_node_get_position_srv.response.position.y, supervisor_node_get_position_srv.response.position.z);
2847 
2848  supervisor_node_get_position_client.shutdown();
2849  time_step_client.call(time_step_srv);
2850 
2851  ros::ServiceClient supervisor_node_get_orientation_client;
2852  webots_ros::node_get_orientation supervisor_node_get_orientation_srv;
2853  supervisor_node_get_orientation_client =
2854  n.serviceClient<webots_ros::node_get_orientation>(model_name + "/supervisor/node/get_orientation");
2855 
2856  supervisor_node_get_orientation_srv.request.node = from_def_node;
2857  supervisor_node_get_orientation_client.call(supervisor_node_get_orientation_srv);
2858  ROS_INFO(
2859  "From_def orientation quaternion is:\nw=%f x=%f y=%f z=%f.", supervisor_node_get_orientation_srv.response.orientation.w,
2860  supervisor_node_get_orientation_srv.response.orientation.x, supervisor_node_get_orientation_srv.response.orientation.y,
2861  supervisor_node_get_orientation_srv.response.orientation.z);
2862 
2863  supervisor_node_get_orientation_client.shutdown();
2864  time_step_client.call(time_step_srv);
2865 
2866  ros::ServiceClient supervisor_node_get_center_of_mass_client;
2867  webots_ros::node_get_center_of_mass supervisor_node_get_center_of_mass_srv;
2868  supervisor_node_get_center_of_mass_client =
2869  n.serviceClient<webots_ros::node_get_center_of_mass>(model_name + "/supervisor/node/get_center_of_mass");
2870 
2871  supervisor_node_get_center_of_mass_srv.request.node = from_def_node;
2872  supervisor_node_get_center_of_mass_client.call(supervisor_node_get_center_of_mass_srv);
2873  ROS_INFO("From_def node's center of mass coordinates are: x = %f y = %f z = %f.",
2874  supervisor_node_get_center_of_mass_srv.response.centerOfMass.x,
2875  supervisor_node_get_center_of_mass_srv.response.centerOfMass.y,
2876  supervisor_node_get_center_of_mass_srv.response.centerOfMass.z);
2877 
2878  supervisor_node_get_center_of_mass_client.shutdown();
2879  time_step_client.call(time_step_srv);
2880 
2881  ros::ServiceClient supervisor_node_get_number_of_contact_points_client;
2882  webots_ros::node_get_number_of_contact_points supervisor_node_get_number_of_contact_points_srv;
2883  supervisor_node_get_number_of_contact_points_client = n.serviceClient<webots_ros::node_get_number_of_contact_points>(
2884  model_name + "/supervisor/node/get_number_of_contact_points");
2885 
2886  supervisor_node_get_number_of_contact_points_srv.request.node = from_def_node;
2887  supervisor_node_get_number_of_contact_points_client.call(supervisor_node_get_number_of_contact_points_srv);
2888  ROS_INFO("From_def node got %d contact points.",
2889  supervisor_node_get_number_of_contact_points_srv.response.numberOfContactPoints);
2890 
2891  supervisor_node_get_number_of_contact_points_client.shutdown();
2892  time_step_client.call(time_step_srv);
2893 
2894  ros::ServiceClient supervisor_node_get_contact_point_client;
2895  webots_ros::node_get_contact_point supervisor_node_get_contact_point_srv;
2896  supervisor_node_get_contact_point_client =
2897  n.serviceClient<webots_ros::node_get_contact_point>(model_name + "/supervisor/node/get_contact_point");
2898 
2899  supervisor_node_get_contact_point_srv.request.node = from_def_node;
2900  supervisor_node_get_contact_point_srv.request.index = 0;
2901  supervisor_node_get_contact_point_client.call(supervisor_node_get_contact_point_srv);
2902  ROS_INFO("From_def_node first contact point is at x = %f, y = %f z = %f.",
2903  supervisor_node_get_contact_point_srv.response.point.x, supervisor_node_get_contact_point_srv.response.point.y,
2904  supervisor_node_get_contact_point_srv.response.point.z);
2905 
2906  supervisor_node_get_contact_point_client.shutdown();
2907  time_step_client.call(time_step_srv);
2908 
2909  // test get_static_balance
2910  // if the node isn't a top Solid webots will throw a warning but still return true to ros
2911  ros::ServiceClient supervisor_node_get_static_balance_client;
2912  webots_ros::node_get_static_balance supervisor_node_get_static_balance_srv;
2913  supervisor_node_get_static_balance_client =
2914  n.serviceClient<webots_ros::node_get_static_balance>(model_name + "/supervisor/node/get_static_balance");
2915 
2916  supervisor_node_get_static_balance_srv.request.node = from_def_node;
2917  supervisor_node_get_static_balance_client.call(supervisor_node_get_static_balance_srv);
2918  ROS_INFO("From_def node balance is %d.", supervisor_node_get_static_balance_srv.response.balance);
2919 
2920  supervisor_node_get_static_balance_client.shutdown();
2921  time_step_client.call(time_step_srv);
2922 
2923  // test reset_physics
2924  // if the node isn't a top Solid webots will throw a warning but still return true to ros
2925  ros::ServiceClient supervisor_node_reset_physics_client =
2926  n.serviceClient<webots_ros::node_reset_functions>(model_name + "/supervisor/node/reset_physics");
2927  webots_ros::node_reset_functions supervisor_node_reset_physics_srv;
2928 
2929  supervisor_node_reset_physics_srv.request.node = from_def_node;
2930  if (supervisor_node_reset_physics_client.call(supervisor_node_reset_physics_srv) &&
2931  supervisor_node_reset_physics_srv.response.success == 1)
2932  ROS_INFO("Node physics has been reset successfully.");
2933  else
2934  ROS_ERROR("Failed to call service node_reset_physics.");
2935 
2936  supervisor_node_reset_physics_client.shutdown();
2937  time_step_client.call(time_step_srv);
2938 
2939  // test restart_controller
2940  ros::ServiceClient supervisor_node_restart_controller_client =
2941  n.serviceClient<webots_ros::node_reset_functions>(model_name + "/supervisor/node/restart_controller");
2942  webots_ros::node_reset_functions supervisor_node_restart_controller_srv;
2943 
2944  supervisor_node_restart_controller_srv.request.node = from_def_node;
2945  if (supervisor_node_restart_controller_client.call(supervisor_node_restart_controller_srv) &&
2946  supervisor_node_restart_controller_srv.response.success == 1)
2947  ROS_INFO("Robot controller has been restarted successfully.");
2948  else
2949  ROS_ERROR("Failed to call service node_restart_controller.");
2950 
2951  supervisor_node_restart_controller_client.shutdown();
2952  time_step_client.call(time_step_srv);
2953 
2954  ros::ServiceClient supervisor_node_get_field_client;
2955  webots_ros::node_get_field supervisor_node_get_field_srv;
2956  supervisor_node_get_field_client = n.serviceClient<webots_ros::node_get_field>(model_name + "/supervisor/node/get_field");
2957 
2958  supervisor_node_get_field_srv.request.node = root_node;
2959  supervisor_node_get_field_srv.request.fieldName = "children";
2960  supervisor_node_get_field_srv.request.proto = 0;
2961  supervisor_node_get_field_client.call(supervisor_node_get_field_srv);
2962  uint64_t field = supervisor_node_get_field_srv.response.field;
2963 
2964  supervisor_node_get_field_client.shutdown();
2965  time_step_client.call(time_step_srv);
2966 
2967  ros::ServiceClient supervisor_field_get_type_client;
2968  webots_ros::field_get_type supervisor_field_get_type_srv;
2969  supervisor_field_get_type_client = n.serviceClient<webots_ros::field_get_type>(model_name + "/supervisor/field/get_type");
2970 
2971  supervisor_field_get_type_srv.request.field = field;
2972  supervisor_field_get_type_client.call(supervisor_field_get_type_srv);
2973  ROS_INFO("World's children field is of type %d.", supervisor_field_get_type_srv.response.type);
2974 
2975  supervisor_field_get_type_client.shutdown();
2976  time_step_client.call(time_step_srv);
2977 
2978  ros::ServiceClient supervisor_field_get_type_name_client;
2979  webots_ros::field_get_type_name supervisor_field_get_type_name_srv;
2980  supervisor_field_get_type_name_client =
2981  n.serviceClient<webots_ros::field_get_type_name>(model_name + "/supervisor/field/get_type_name");
2982 
2983  supervisor_field_get_type_name_srv.request.field = field;
2984  supervisor_field_get_type_name_client.call(supervisor_field_get_type_name_srv);
2985  ROS_INFO("Also known as %s.", supervisor_field_get_type_name_srv.response.name.c_str());
2986 
2987  supervisor_field_get_type_name_client.shutdown();
2988  time_step_client.call(time_step_srv);
2989 
2990  ros::ServiceClient supervisor_field_get_count_client;
2991  webots_ros::field_get_count supervisor_field_get_count_srv;
2992  supervisor_field_get_count_client = n.serviceClient<webots_ros::field_get_count>(model_name + "/supervisor/field/get_count");
2993 
2994  supervisor_field_get_count_srv.request.field = field;
2995  supervisor_field_get_count_client.call(supervisor_field_get_count_srv);
2996  if (supervisor_field_get_count_srv.response.count != -1)
2997  ROS_INFO("There is %d nodes in this field.", supervisor_field_get_count_srv.response.count);
2998  else
2999  ROS_ERROR("Illegal call to Field::getCount() argument must be multiple fields.");
3000 
3001  supervisor_field_get_count_client.shutdown();
3002  time_step_client.call(time_step_srv);
3003 
3004  supervisor_node_get_field_srv.request.node = from_def_node;
3005  supervisor_node_get_field_srv.request.fieldName = "name";
3006  supervisor_node_get_field_client.call(supervisor_node_get_field_srv);
3007  field = supervisor_node_get_field_srv.response.field;
3008 
3009  ros::ServiceClient supervisor_field_set_string_client;
3010  webots_ros::field_set_string supervisor_field_set_string_srv;
3011  supervisor_field_set_string_client =
3012  n.serviceClient<webots_ros::field_set_string>(model_name + "/supervisor/field/set_string");
3013 
3014  supervisor_field_set_string_srv.request.field = field;
3015  supervisor_field_set_string_srv.request.value = "solid_test";
3016  if (supervisor_field_set_string_client.call(supervisor_field_set_string_srv) &&
3017  supervisor_field_set_string_srv.response.success == 1)
3018  ROS_INFO("Field's string updated to: 'solid_test'.");
3019  else
3020  ROS_ERROR("Failed to call service field_set_string.");
3021 
3022  supervisor_field_set_string_client.shutdown();
3023  time_step_client.call(time_step_srv);
3024 
3025  ros::ServiceClient supervisor_field_get_string_client;
3026  webots_ros::field_get_string supervisor_field_get_string_srv;
3027  supervisor_field_get_string_client =
3028  n.serviceClient<webots_ros::field_get_string>(model_name + "/supervisor/field/get_string");
3029 
3030  supervisor_field_get_string_srv.request.field = field;
3031  supervisor_field_get_string_client.call(supervisor_field_get_string_srv);
3032  ROS_INFO("Field contains \"%s\".", supervisor_field_get_string_srv.response.value.c_str());
3033 
3034  supervisor_field_get_string_client.shutdown();
3035  time_step_client.call(time_step_srv);
3036 
3037  supervisor_node_get_field_srv.request.node = root_node;
3038  supervisor_node_get_field_srv.request.fieldName = "children";
3039  supervisor_node_get_field_client.call(supervisor_node_get_field_srv);
3040  field = supervisor_node_get_field_srv.response.field;
3041 
3042  ros::ServiceClient supervisor_field_get_node_client;
3043  webots_ros::field_get_node supervisor_field_get_node_srv;
3044  supervisor_field_get_node_client = n.serviceClient<webots_ros::field_get_node>(model_name + "/supervisor/field/get_node");
3045 
3046  supervisor_field_get_node_srv.request.field = field;
3047  supervisor_field_get_node_srv.request.index = 7;
3048  supervisor_field_get_node_client.call(supervisor_field_get_node_srv);
3049 
3050  supervisor_node_get_type_name_srv.request.node = supervisor_field_get_node_srv.response.node;
3051  supervisor_node_get_type_name_client.call(supervisor_node_get_type_name_srv);
3052  ROS_INFO("Node got from field_get_node is of type %s.", supervisor_node_get_type_name_srv.response.name.c_str());
3053 
3054  // supervisor_node_get_from_id
3055  supervisor_get_from_def_srv.request.name = "CONE";
3056  supervisor_get_from_def_srv.request.proto = 0;
3057  supervisor_get_from_def_client.call(supervisor_get_from_def_srv);
3058  uint64_t cone_node = 0;
3059  if (supervisor_get_from_def_srv.response.node != 0) {
3060  ROS_INFO("Got CONE node from DEF: %lu.", supervisor_get_from_def_srv.response.node);
3061  cone_node = supervisor_get_from_def_srv.response.node;
3062  } else
3063  ROS_ERROR("could not get CONE node from DEF.");
3064 
3065  supervisor_node_get_type_name_client.shutdown();
3066  supervisor_get_from_def_client.shutdown();
3067  supervisor_field_get_node_client.shutdown();
3068  time_step_client.call(time_step_srv);
3069 
3070  ros::ServiceClient node_get_id_client;
3071  webots_ros::node_get_id node_get_id_srv;
3072  node_get_id_client = n.serviceClient<webots_ros::node_get_id>(model_name + "/supervisor/node/get_id");
3073  node_get_id_srv.request.node = cone_node;
3074  node_get_id_client.call(node_get_id_srv);
3075  int cone_node_id = node_get_id_srv.response.id;
3076  if (cone_node_id > 0)
3077  ROS_INFO("Node id got successfully.");
3078  else
3079  ROS_ERROR("Failed to call service node_get_id.");
3080 
3081  node_get_id_client.shutdown();
3082  time_step_client.call(time_step_srv);
3083 
3084  // supervisor_get_from_id
3085  webots_ros::supervisor_get_from_id supervisor_get_from_id_srv;
3086  node_get_id_client = n.serviceClient<webots_ros::supervisor_get_from_id>(model_name + "/supervisor/get_from_id");
3087  supervisor_get_from_id_srv.request.id = cone_node_id;
3088  node_get_id_client.call(supervisor_get_from_id_srv);
3089  uint64_t cone_node_copy = supervisor_get_from_id_srv.response.node;
3090  if (cone_node_copy == cone_node)
3091  ROS_INFO("Cone node got successfully from id.");
3092  else
3093  ROS_ERROR("Failed to call service supervisor_get_from_id.");
3094 
3095  node_get_id_client.shutdown();
3096  time_step_client.call(time_step_srv);
3097 
3098  // node_set_velocity
3099  ros::ServiceClient node_velocity_client;
3100  webots_ros::node_set_velocity node_set_velocity_srv;
3101  node_velocity_client = n.serviceClient<webots_ros::node_set_velocity>(model_name + "/supervisor/node/set_velocity");
3102  node_set_velocity_srv.request.node = cone_node;
3103  node_set_velocity_srv.request.velocity.linear.x = 0.0;
3104  node_set_velocity_srv.request.velocity.linear.y = 0.0;
3105  node_set_velocity_srv.request.velocity.linear.z = 1.0;
3106  node_set_velocity_srv.request.velocity.angular.x = 0.0;
3107  node_set_velocity_srv.request.velocity.angular.y = 0.0;
3108  node_set_velocity_srv.request.velocity.angular.z = 0.0;
3109  if (node_velocity_client.call(node_set_velocity_srv) && node_set_velocity_srv.response.success == 1)
3110  ROS_INFO("Node velocity set successfully.");
3111  else
3112  ROS_ERROR("Failed to call service node_set_velocity.");
3113 
3114  node_velocity_client.shutdown();
3115  time_step_client.call(time_step_srv);
3116 
3117  // node_get_velocity
3118  webots_ros::node_get_velocity node_get_velocity_srv;
3119  node_velocity_client = n.serviceClient<webots_ros::node_get_velocity>(model_name + "/supervisor/node/get_velocity");
3120  node_get_velocity_srv.request.node = cone_node;
3121  node_velocity_client.call(node_get_velocity_srv);
3122  if (node_get_velocity_srv.response.velocity.linear.z > 0.8)
3123  ROS_INFO("Node velocity get successfully.");
3124  else
3125  ROS_ERROR("Failed to call service node_get_velocity.");
3126 
3127  node_velocity_client.shutdown();
3128  time_step_client.call(time_step_srv);
3129 
3130  // node_add_force_or_torque
3131  ros::ServiceClient node_add_force_or_torque_client;
3132  webots_ros::node_add_force_or_torque node_add_force_or_torque_srv;
3133  node_add_force_or_torque_client =
3134  n.serviceClient<webots_ros::node_add_force_or_torque>(model_name + "/supervisor/node/add_torque");
3135  node_add_force_or_torque_srv.request.node = cone_node;
3136  node_add_force_or_torque_srv.request.force.x = 0.0;
3137  node_add_force_or_torque_srv.request.force.y = 0.0;
3138  node_add_force_or_torque_srv.request.force.z = 1.0;
3139  node_add_force_or_torque_srv.request.relative = 0;
3140  if (node_add_force_or_torque_client.call(node_add_force_or_torque_srv) && node_add_force_or_torque_srv.response.success == 1)
3141  ROS_INFO("Node force added successfully.");
3142  else
3143  ROS_ERROR("Failed to call service node_add_force_or_torque.");
3144 
3145  node_add_force_or_torque_client.shutdown();
3146  time_step_client.call(time_step_srv);
3147 
3148  // node_add_force_with_offset
3149  ros::ServiceClient node_add_force_with_offset_client;
3150  webots_ros::node_add_force_with_offset node_add_force_with_offset_srv;
3151  node_add_force_with_offset_client =
3152  n.serviceClient<webots_ros::node_add_force_with_offset>(model_name + "/supervisor/node/add_force_with_offset");
3153  node_add_force_with_offset_srv.request.node = cone_node;
3154  node_add_force_with_offset_srv.request.force.x = 0.0;
3155  node_add_force_with_offset_srv.request.force.y = 0.0;
3156  node_add_force_with_offset_srv.request.force.z = 1.0;
3157  node_add_force_with_offset_srv.request.offset.x = 0.0;
3158  node_add_force_with_offset_srv.request.offset.y = 0.0;
3159  node_add_force_with_offset_srv.request.offset.z = 1.0;
3160  node_add_force_with_offset_srv.request.relative = 0;
3161  if (node_add_force_with_offset_client.call(node_add_force_with_offset_srv) &&
3162  node_add_force_with_offset_srv.response.success == 1)
3163  ROS_INFO("Node force added successfully.");
3164  else
3165  ROS_ERROR("Failed to call service node_add_force_with_offset.");
3166 
3167  node_add_force_with_offset_client.shutdown();
3168  time_step_client.call(time_step_srv);
3169 
3170  // node_get_parent
3171  ros::ServiceClient node_get_parent_node_client;
3172  webots_ros::node_get_parent_node node_get_parent_node_srv;
3173  node_get_parent_node_client =
3174  n.serviceClient<webots_ros::node_get_parent_node>(model_name + "/supervisor/node/get_parent_node");
3175  node_get_parent_node_srv.request.node = cone_node;
3176  node_get_parent_node_client.call(node_get_parent_node_srv);
3177  if (node_get_parent_node_srv.response.node == root_node)
3178  ROS_INFO("Node parent got successfully.");
3179  else
3180  ROS_ERROR("Failed to call service node_get_parent_node.");
3181 
3182  node_get_parent_node_client.shutdown();
3183  time_step_client.call(time_step_srv);
3184 
3185  // movie
3186  ros::ServiceClient supervisor_movie_is_ready_client;
3187  webots_ros::node_get_status supervisor_movie_is_ready_srv;
3188  supervisor_movie_is_ready_client = n.serviceClient<webots_ros::node_get_status>(model_name + "/supervisor/movie_is_ready");
3189 
3190  if (supervisor_movie_is_ready_client.call(supervisor_movie_is_ready_srv) &&
3191  supervisor_movie_is_ready_srv.response.status == 1)
3192  ROS_INFO("Ready to record a movie.");
3193  else
3194  ROS_ERROR("Failed to call service supervisor_movie_is_ready.");
3195 
3196  supervisor_movie_is_ready_client.shutdown();
3197  time_step_client.call(time_step_srv);
3198 
3199  ros::ServiceClient supervisor_movie_start_client;
3200  webots_ros::supervisor_movie_start_recording supervisor_movie_start_srv;
3201  supervisor_movie_start_client =
3202  n.serviceClient<webots_ros::supervisor_movie_start_recording>(model_name + "/supervisor/movie_start_recording");
3203 
3204  supervisor_movie_start_srv.request.filename = std::string(getenv("HOME")) + std::string("/movie_test.mp4");
3205  supervisor_movie_start_srv.request.width = 480;
3206  supervisor_movie_start_srv.request.height = 360;
3207  supervisor_movie_start_srv.request.codec = 1337;
3208  supervisor_movie_start_srv.request.quality = 100;
3209  supervisor_movie_start_srv.request.acceleration = 1;
3210  supervisor_movie_start_srv.request.caption = false;
3211  if (supervisor_movie_start_client.call(supervisor_movie_start_srv) && supervisor_movie_start_srv.response.success == 1)
3212  ROS_INFO("Movie started successfully.");
3213  else
3214  ROS_ERROR("Failed to call service movie_start_recording.");
3215 
3216  supervisor_movie_start_client.shutdown();
3217  for (int i = 0; i < 25; ++i)
3218  time_step_client.call(time_step_srv);
3219 
3220  ros::ServiceClient supervisor_movie_stop_client;
3221  webots_ros::get_bool supervisor_movie_stop_srv;
3222  supervisor_movie_stop_client = n.serviceClient<webots_ros::get_bool>(model_name + "/supervisor/movie_stop_recording");
3223 
3224  if (supervisor_movie_stop_client.call(supervisor_movie_stop_srv) && supervisor_movie_stop_srv.response.value)
3225  ROS_INFO("Movie stopped successfully.");
3226  else
3227  ROS_ERROR("Failed to call service movie_stop_recording.");
3228 
3229  supervisor_movie_stop_client.shutdown();
3230  time_step_client.call(time_step_srv);
3231 
3232  ros::ServiceClient supervisor_movie_failed_client;
3233  webots_ros::node_get_status supervisor_movie_failed_srv;
3234  supervisor_movie_failed_client = n.serviceClient<webots_ros::node_get_status>(model_name + "/supervisor/movie_failed");
3235 
3236  if (supervisor_movie_failed_client.call(supervisor_movie_failed_srv) && supervisor_movie_failed_srv.response.status == 0)
3237  ROS_INFO("Movie recording executing successfully.");
3238  else
3239  ROS_ERROR("Failed movie recording.");
3240 
3241  supervisor_movie_failed_client.shutdown();
3242  time_step_client.call(time_step_srv);
3243 
3244  supervisor_set_label_srv.request.label = "";
3245  supervisor_set_label_client.call(supervisor_set_label_srv);
3246 
3247  supervisor_set_label_client.shutdown();
3248  time_step_client.call(time_step_srv);
3249 
3250  // field_remove
3251  ros::ServiceClient remove_node_client;
3252  webots_ros::field_remove field_remove_srv;
3253  remove_node_client = n.serviceClient<webots_ros::field_remove>(model_name + "/supervisor/field/remove");
3254  field_remove_srv.request.field = field;
3255  field_remove_srv.request.index = 5;
3256  if (remove_node_client.call(field_remove_srv) && field_remove_srv.response.success == 1)
3257  ROS_INFO("Field node removed successfully.");
3258  else
3259  ROS_ERROR("Failed to call service field_remove.");
3260 
3261  remove_node_client.shutdown();
3262  time_step_client.call(time_step_srv);
3263 
3264  // node_remove
3265  webots_ros::node_remove node_remove_srv;
3266  remove_node_client = n.serviceClient<webots_ros::node_remove>(model_name + "/supervisor/node/remove");
3267  node_remove_srv.request.node = cone_node;
3268  remove_node_client.call(node_remove_srv);
3269  int success1 = node_remove_srv.response.success;
3270  if (success1 == 1)
3271  ROS_INFO("Node removed successfully.");
3272  else
3273  ROS_ERROR("Failed to call service node_removed.");
3274 
3275  remove_node_client.shutdown();
3276  time_step_client.call(time_step_srv);
3277 
3278  // html robot window
3279  ros::ServiceClient wwi_send_client;
3280  wwi_send_client = n.serviceClient<webots_ros::set_string>(model_name + "/robot/wwi_send_text");
3281  webots_ros::set_string wwi_send_srv;
3282  wwi_send_srv.request.value = "test wwi functions from complete_test controller.";
3283  if (wwi_send_client.call(wwi_send_srv) && wwi_send_srv.response.success == 1)
3284  ROS_INFO("Text to robot window successfully sent.");
3285  else
3286  ROS_ERROR("Failed to call service robot/wwi_send_text.");
3287 
3288  wwi_send_client.shutdown();
3289  time_step_client.call(time_step_srv);
3290 
3291  ros::ServiceClient wwi_receive_client;
3292  wwi_receive_client = n.serviceClient<webots_ros::get_string>(model_name + "/robot/wwi_receive_text");
3293  webots_ros::get_string wwi_receive_srv;
3294  if (wwi_receive_client.call(wwi_receive_srv) &&
3295  wwi_receive_srv.response.value.compare("Answer: test wwi functions from complete_test controller.") == 0)
3296  ROS_INFO("Text from robot window successfully received.");
3297  else
3298  ROS_ERROR("Failed to call service robot/wwi_receive_text.");
3299 
3300  wwi_receive_client.shutdown();
3301  time_step_client.call(time_step_srv);
3302 
3303  // virtual reality headset
3304  ros::ServiceClient virtual_reality_headset_client;
3305  webots_ros::get_bool supervisor_virtual_reality_headset_is_used_srv;
3306  virtual_reality_headset_client =
3307  n.serviceClient<webots_ros::get_bool>(model_name + "/supervisor/vitual_reality_headset_is_used");
3308  virtual_reality_headset_client.call(supervisor_virtual_reality_headset_is_used_srv);
3309  bool used = supervisor_virtual_reality_headset_is_used_srv.response.value;
3310  // to test this service we assume no virtual reality headset is connected
3311  if (!used)
3312  ROS_INFO("No virtual reality headset connected.");
3313  else
3314  ROS_ERROR("Virtual reality headset wrongly detected.");
3315 
3316  virtual_reality_headset_client.shutdown();
3317  time_step_client.call(time_step_srv);
3318 
3319  // test field_import_node
3320  // this test is disabled as it needs a webots object file but it will work if you export the cone_test solid from the world
3321  // before
3322  // ros::ServiceClient supervisor_field_import_node_client;
3323  // webots_ros::field_import_node supervisor_field_import_node_srv;
3324  // supervisor_field_import_node_client =
3325  // n.serviceClient<webots_ros::field_import_node>(model_name+"/supervisor/field/import_node");
3326  //
3327  // supervisor_field_import_node_srv.request.field = field;
3328  // supervisor_field_import_node_srv.request.position = 6;
3329  // supervisor_field_import_node_srv.request.filename = "cone_test.wbo";
3330  // if (supervisor_field_import_node_client.call(supervisor_field_import_node_srv) &&
3331  // supervisor_field_import_node_srv.response.success == 1)
3332  // ROS_INFO("New cone add in world.");
3333  // else
3334  // ROS_ERROR("Failed to call service field_import_node.");
3335 
3336  // The next 2 tests are commented but works if you want to use them.
3337  // Since they stop simulation we can't use them if we wants to do other tests afterwards
3338 
3339  //~ ros::ServiceClient supervisor_simulation_quit_client;
3340  //~ webots_ros::set_int supervisor_simulation_quit_srv;
3341  //~ supervisor_simulation_quit_client = n.serviceClient<webots_ros::set_int>(model_name+"/supervisor/simulation_quit");
3342  //~
3343  //~ supervisor_simulation_quit_srv.request.value = EXIT_SUCCESS;
3344  //~ if (supervisor_simulation_quit_client.call(supervisor_simulation_quit_srv) &&
3345  //~ supervisor_simulation_quit_srv.response.success)
3346  //~ ROS_INFO("Webots quit successfully.");
3347  //~ else
3348  //~ ROS_ERROR("Failed to call service simulation_quit.");
3349 
3350  //~ ros::ServiceClient supervisor_simulation_revert_client;
3351  //~ webots_ros::get_bool supervisor_simulation_revert_srv;
3352  //~ supervisor_simulation_revert_client = n.serviceClient<webots_ros::get_bool>(model_name+"/supervisor/simulation_revert");
3353  //~
3354  //~ if (supervisor_simulation_revert_client.call(supervisor_simulation_revert_srv) &&
3355  //~ supervisor_simulation_revert_srv.response.value)
3356  //~ ROS_INFO("Simulation has revert successfully.");
3357  //~ else
3358  //~ ROS_ERROR("Failed to call service simulation_revert.");
3359 
3360  // end of tests
3361  time_step_srv.request.value = 0;
3362  if (time_step_client.call(time_step_srv) && time_step_srv.response.success)
3363  ROS_INFO("Robot's time step called to end tests.");
3364  else
3365  ROS_ERROR("Failed to call service time_step to end tests.");
3366 
3367  time_step_client.shutdown();
3368 
3369  ros::shutdown();
3370 
3371  printf("\nTest Completed\n");
3372  return 0;
3373 }
static double compassValues[3]
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void lightSensorCallback(const sensor_msgs::Illuminance::ConstPtr &value)
#define TIME_STEP
static double inertialUnitValues[4]
void joystickCallback(const webots_ros::Int8Stamped::ConstPtr &value)
void gyroCallback(const sensor_msgs::Imu::ConstPtr &values)
void receiverCallback(const webots_ros::StringStamped::ConstPtr &value)
void battery_sensorCallback(const webots_ros::Float64Stamped::ConstPtr &value)
int main(int argc, char **argv)
void lidarCallback(const sensor_msgs::Image::ConstPtr &image)
static double accelerometerValues[3]
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void distance_sensorCallback(const sensor_msgs::Range::ConstPtr &value)
webots_ros::set_int time_step_srv
void keyboardCallback(const webots_ros::Int32Stamped::ConstPtr &value)
static int connectorPresence
static double touchSensorValues[3]
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
void connectorCallback(const webots_ros::Int8Stamped::ConstPtr &value)
void GPSCallback(const sensor_msgs::NavSatFix::ConstPtr &values)
void modelNameCallback(const std_msgs::String::ConstPtr &name)
ros::ServiceClient time_step_client
void accelerometerCallback(const sensor_msgs::Imu::ConstPtr &values)
ros::NodeHandle * n
Definition: pioneer3at.cpp:40
void touchSensorBumperCallback(const webots_ros::BoolStamped::ConstPtr &value)
void rangeFinderCallback(const sensor_msgs::Image::ConstPtr &image)
void cameraRecognitionCallback(const webots_ros::RecognitionObject::ConstPtr &object)
void quit(int sig)
static int model_count
#define ROS_INFO(...)
void touchSensorCallback(const webots_ros::Float64Stamped::ConstPtr &value)
void radarTargetsNumberCallback(const webots_ros::Int8Stamped::ConstPtr &value)
uint32_t getNumPublishers() const
static vector< string > model_list
void motorSensorCallback(const webots_ros::Float64Stamped::ConstPtr &value)
void positionSensorCallback(const webots_ros::Float64Stamped::ConstPtr &value)
void inertialUnitCallback(const sensor_msgs::Imu::ConstPtr &values)
static double GPSValues[3]
static double GyroValues[3]
void cameraCallback(const sensor_msgs::Image::ConstPtr &values)
static vector< unsigned char > imageColor
ROSCPP_DECL void shutdown()
void GPSSpeedCallback(const webots_ros::Float64Stamped::ConstPtr &value)
std::vector< unsigned char > image
Definition: e_puck_line.cpp:87
void touchSensor3DCallback(const geometry_msgs::WrenchStamped::ConstPtr &values)
static bool callbackCalled
ROSCPP_DECL void spinOnce()
string message
Definition: ros_python.py:46
#define ROS_ERROR(...)
static vector< float > imageRangeFinder
void compassCallback(const sensor_msgs::MagneticField::ConstPtr &values)
void radarTargetsCallback(const webots_ros::RadarTarget::ConstPtr &target)


webots_ros
Author(s): Cyberbotics
autogenerated on Fri Sep 4 2020 03:55:03