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> 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> 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> 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> 159 imageColor.resize(values->step * values->height);
160 for (std::vector<unsigned char>::const_iterator it = values->data.begin(); it != values->data.end(); ++it) {
168 ROS_INFO(
"Camera recognition saw a '%s' (time: %d:%d).", object->model.c_str(),
object->header.stamp.sec,
169 object->header.stamp.nsec);
174 ROS_INFO(
"Joystick button pressed: %d (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
179 ROS_INFO(
"Keyboard key pressed: %d (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
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);
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);
197 int size = image->width * image->height;
200 const float *depth_data =
reinterpret_cast<const float *
>(&image->data[0]);
201 for (
int i = 0; i < size; ++i)
228 ROS_INFO(
"Battery level is %f (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
238 values->header.stamp.sec, values->header.stamp.nsec);
243 ROS_INFO(
"Distance from object is %f (time: %d:%d).", value->range, value->header.stamp.sec, value->header.stamp.nsec);
247 void GPSCallback(
const sensor_msgs::NavSatFix::ConstPtr &values) {
253 values->header.stamp.nsec);
258 ROS_INFO(
"GPS speed is: %fkm/h (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
268 values->header.stamp.sec, values->header.stamp.nsec);
280 values->header.stamp.nsec);
285 ROS_INFO(
"Light intensity is %f.", value->illuminance);
290 ROS_INFO(
"Motor sensor sent value %f.", value->data);
295 ROS_INFO(
"Position sensor sent value %f (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
300 ROS_INFO(
"Touch sensor sent value %f (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
305 ROS_INFO(
"Touch sensor sent value %d (time: %d:%d).", value->data, value->header.stamp.sec, value->header.stamp.nsec);
320 char *
message =
const_cast<char *
>(value->data.c_str());
321 ROS_INFO(
"Received a message %s.", message);
328 ROS_INFO(
"User stopped the 'complete_test' node.");
333 int main(
int argc,
char **argv) {
334 string model_name =
"my_robot";
339 signal(SIGINT,
quit);
358 vector<string> device_list;
360 time_step_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/robot/time_step");
364 ROS_INFO(
"time_step service works.");
366 ROS_ERROR(
"Failed to call service time_step to update robot's time step.");
369 n.
serviceClient<webots_ros::get_int>(model_name +
"/robot/get_number_of_devices");
370 webots_ros::get_int get_number_of_devices_srv;
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);
376 ROS_ERROR(
"Failed to call service get_number_of_devices.");
378 get_number_of_devices_client.
shutdown();
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;
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());
390 ROS_ERROR(
"Failed to call service device_list.");
396 webots_ros::get_urdf urdf_srv;
397 urdf_srv.request.prefix =
"unique_robot_prefix_name_";
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.");
404 ROS_INFO(
"URDF has been successfully obtained.");
406 ROS_ERROR(
"Failed to call service get_urdf.");
412 n.
serviceClient<webots_ros::get_float>(model_name +
"/robot/get_basic_time_step");
413 webots_ros::get_float get_basic_time_step_srv;
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);
419 ROS_ERROR(
"Failed to call service get_basic_time_step.");
421 get_basic_time_step_client.
shutdown();
425 n.
serviceClient<webots_ros::get_string>(model_name +
"/robot/get_custom_data");
426 webots_ros::get_string robot_get_custom_data_srv;
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());
432 ROS_ERROR(
"Failed to call service robot_get_custom_data.");
434 robot_get_custom_data_client.
shutdown();
438 webots_ros::get_int get_mode_srv;
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);
444 ROS_ERROR(
"Failed to call service get_mode.");
450 webots_ros::get_string get_model_srv;
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());
456 ROS_ERROR(
"Failed to call service get_model.");
462 webots_ros::get_string get_project_path_srv;
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());
468 ROS_ERROR(
"Failed to call service get_project_path.");
475 webots_ros::get_string get_world_path_srv;
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());
481 ROS_ERROR(
"Failed to call service get_project_path.");
487 webots_ros::get_bool get_supervisor_srv;
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());
493 ROS_ERROR(
"%s isn't a supervisor.", model_name.c_str());
495 ROS_ERROR(
"Failed to call service get_synchronization.");
501 n.
serviceClient<webots_ros::get_bool>(model_name +
"/robot/get_synchronization");
502 webots_ros::get_bool get_synchronization_srv;
504 if (get_synchronization_client.
call(get_synchronization_srv)) {
505 bool synchronization = get_synchronization_srv.response.value;
507 ROS_INFO(
"%s is sync.", model_name.c_str());
509 ROS_INFO(
"%s isn't sync.", model_name.c_str());
511 ROS_ERROR(
"Failed to call service get_synchronization.");
513 get_synchronization_client.
shutdown();
517 webots_ros::get_float get_time_srv;
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);
523 ROS_ERROR(
"Failed to call service get_time.");
529 webots_ros::get_int get_type_srv;
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);
535 ROS_ERROR(
"Failed to call service get_type.");
541 n.
serviceClient<webots_ros::set_string>(model_name +
"/robot/set_custom_data");
542 webots_ros::set_string robot_set_custom_data_srv;
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());
549 ROS_ERROR(
"Failed to call service robot_set_custom_data.");
551 robot_set_custom_data_client.
shutdown();
555 webots_ros::robot_set_mode set_mode_srv;
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);
562 ROS_ERROR(
"Failed to call service set_mode.");
568 webots_ros::set_int enable_keyboard_srv;
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());
575 ROS_INFO(
"Topics for keyboard initialized.");
581 ROS_INFO(
"Topics for keyboard connected.");
583 ROS_ERROR(
"Failed to enable keyboard.");
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;
589 wait_for_user_input_event_srv.request.eventType = 4;
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);
594 ROS_ERROR(
"Failed to call service wait_for_user_input_event.");
596 wait_for_user_input_event_client.
shutdown();
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.");
614 ROS_ERROR(
"Failed to call service brake_set_damping_constant.");
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());
629 ROS_ERROR(
"Failed to call service brake_get_motor_name.");
631 brake_get_motor_name_client.
shutdown();
639 double focal_distance = 0.33;
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);
646 ROS_ERROR(
"Failed to call service camera_set_focal_distance.");
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);
659 ROS_ERROR(
"Failed to call service camera_set_fov.");
666 webots_ros::set_int camera_srv;
669 enable_camera_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/camera/enable");
671 if (enable_camera_client.
call(camera_srv) && camera_srv.response.success) {
674 ROS_INFO(
"Topic for camera color initialized.");
680 ROS_INFO(
"Topic for camera color connected.");
682 if (camera_srv.response.success == -1)
683 ROS_ERROR(
"Sampling period is not valid.");
684 ROS_ERROR(
"Failed to enable camera.");
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);
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.");
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);
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.");
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);
730 ROS_ERROR(
"Failed to call service camera_get_zoom_info.");
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());
742 ROS_ERROR(
"Recognition capability of camera of %s not found.", model_name.c_str());
744 ROS_ERROR(
"Failed to call service camera_get_zoom_info.");
751 webots_ros::set_int camera_recognition_srv;
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.");
759 ROS_INFO(
"Topic for camera recognition initialized.");
765 ROS_INFO(
"Topic for camera recognition connected.");
767 if (camera_recognition_srv.response.success == -1)
768 ROS_ERROR(
"Sampling period is not valid.");
769 ROS_ERROR(
"Failed to enable camera recognition.");
774 enable_camera_recognition_client.
shutdown();
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;
783 if (save_image_client.
call(save_image_srv) && save_image_srv.response.success == 1)
786 ROS_ERROR(
"Failed to call service save_image.");
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());
803 ROS_ERROR(
"Failed to call service get_name.");
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());
814 ROS_ERROR(
"Failed to call service get_model.");
824 webots_ros::set_int accelerometer_srv;
828 set_accelerometer_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/accelerometer/enable");
830 accelerometer_srv.request.value = 64;
831 if (set_accelerometer_client.
call(accelerometer_srv) && accelerometer_srv.response.success) {
839 if (accelerometer_srv.response.success == -1)
840 ROS_ERROR(
"Sampling period is not valid.");
841 ROS_ERROR(
"Failed to enable accelerometer.");
849 webots_ros::get_int sampling_period_accelerometer_srv;
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);
856 accelerometer_srv.request.value = 32;
857 if (set_accelerometer_client.
call(accelerometer_srv) && accelerometer_srv.response.success) {
865 if (accelerometer_srv.response.success == -1)
866 ROS_ERROR(
"Sampling period is not valid.");
867 ROS_ERROR(
"Failed to enable accelerometer.");
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());
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();
884 set_accelerometer_client.
shutdown();
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);
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);
898 sampling_period_accelerometer_client.
shutdown();
906 webots_ros::set_int battery_sensor_srv;
908 set_battery_sensor_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/battery_sensor/enable");
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");
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.");
925 if (!battery_sensor_srv.response.success)
926 ROS_ERROR(
"Sampling period is not valid.");
927 ROS_ERROR(
"Failed to enable battery_sensor.");
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);
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);
947 set_battery_sensor_client.
shutdown();
948 sampling_period_battery_sensor_client.shutdown();
956 webots_ros::set_int compass_srv;
958 set_compass_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/compass/enable");
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");
964 compass_srv.request.value = 32;
965 if (set_compass_client.
call(compass_srv) && compass_srv.response.success == 1) {
974 if (compass_srv.response.success == -1)
975 ROS_ERROR(
"Sampling period is not valid.");
976 ROS_ERROR(
"Failed to enable compass.");
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());
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();
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);
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);
1008 sampling_period_compass_client.shutdown();
1016 webots_ros::set_int connector_srv;
1018 connector_enable_presence_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/connector/presence_sensor/enable");
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.");
1030 if (!connector_srv.response.success)
1031 ROS_ERROR(
"Sampling period is not valid.");
1032 ROS_ERROR(
"Failed to enable connector's presence sensor.");
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.");
1046 if (!connector_srv.response.success)
1047 ROS_ERROR(
"Sampling period is not valid.");
1048 ROS_ERROR(
"Failed to disable connector's presence sensor.");
1053 webots_ros::set_bool connector_lock_srv;
1054 connector_lock_client = n.
serviceClient<webots_ros::set_bool>(model_name +
"/connector/lock");
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.");
1060 ROS_INFO(
"Failed to lock connector.");
1063 connector_enable_presence_client.
shutdown();
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");
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);
1078 display_get_info_client.
shutdown();
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");
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.");
1089 ROS_ERROR(
"Failed to call service display_set_color. Success = %d.", display_set_color_srv.response.success);
1091 display_set_color_client.
shutdown();
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");
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.");
1102 ROS_ERROR(
"Failed to call service display_set_alpha.");
1104 display_set_alpha_client.
shutdown();
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");
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.");
1115 ROS_ERROR(
"Failed to call service display_set_opacity.");
1117 display_set_opacity_client.
shutdown();
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");
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.");
1130 ROS_ERROR(
"Failed to call service display_set_font. Success = %d.", display_set_font_srv.response.success);
1132 display_set_font_client.
shutdown();
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");
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.");
1144 ROS_ERROR(
"Failed to call service display_draw_pixel. Success = %d.", display_draw_pixel_srv.response.success);
1146 display_draw_pixel_client.
shutdown();
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");
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.");
1160 ROS_ERROR(
"Failed to call service display_draw_line. Success = %d.", display_draw_line_srv.response.success);
1162 display_draw_line_client.
shutdown();
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");
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.");
1176 ROS_ERROR(
"Failed to call service display_draw_rectangle. Success = %d.", display_draw_rectangle_srv.response.success);
1178 display_draw_rectangle_client.
shutdown();
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");
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;
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.");
1193 ROS_ERROR(
"Failed to call service display_draw_oval. Success = %d.", display_draw_oval_srv.response.success);
1195 display_draw_oval_client.
shutdown();
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");
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.");
1216 ROS_ERROR(
"Failed to call service display_draw_polygon. Success = %d.", display_draw_polygon_srv.response.success);
1218 display_draw_polygon_client.
shutdown();
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");
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.");
1231 ROS_ERROR(
"Failed to call service display_draw_text. Success = %d.", display_draw_text_srv.response.success);
1233 display_draw_text_client.
shutdown();
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");
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.");
1247 ROS_ERROR(
"Failed to call service display_fill_rectangle. Success = %d.", display_fill_rectangle_srv.response.success);
1249 display_fill_rectangle_client.
shutdown();
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");
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;
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.");
1264 ROS_ERROR(
"Failed to call service display_fill_oval. Success = %d.", display_fill_oval_srv.response.success);
1266 display_fill_oval_client.
shutdown();
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");
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.");
1287 ROS_ERROR(
"Failed to call service display_fill_polygon. Success = %d.", display_fill_polygon_srv.response.success);
1289 display_fill_polygon_client.
shutdown();
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");
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);
1308 uint64_t new_image = display_image_new_srv.response.ir;
1310 display_image_new_client.
shutdown();
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");
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);
1323 uint64_t copy_image = display_image_copy_srv.response.ir;
1325 display_image_copy_client.
shutdown();
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");
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.");
1339 ROS_ERROR(
"Failed to call service display_image_paste to paste image.");
1341 display_image_paste_client.
shutdown();
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");
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.");
1355 ROS_ERROR(
"Failed to call service display_image_save to save image.");
1357 display_image_save_client.
shutdown();
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");
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;
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.");
1373 ROS_ERROR(
"Failed to call service display_image_paste to paste image.");
1375 display_image_load_client.
shutdown();
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");
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.");
1386 ROS_ERROR(
"Failed to call service display_image_delete.");
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.");
1392 ROS_ERROR(
"Failed to call service display_image_delete.");
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.");
1398 ROS_ERROR(
"Failed to call service display_image_delete.");
1400 display_image_delete_client.
shutdown();
1408 webots_ros::set_int distance_sensor_srv;
1410 set_distance_sensor_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/distance_sensor/enable");
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");
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);
1423 ROS_ERROR(
"Failed to get the minimum value of 'distance_sensor'.");
1424 min_value_distance_sensor_client.shutdown();
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);
1432 ROS_ERROR(
"Failed to get the maximum value of 'distance_sensor'.");
1433 max_value_distance_sensor_client.
shutdown();
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);
1441 ROS_ERROR(
"Failed to get the aperture of 'distance_sensor'.");
1442 aperture_distance_sensor_client.
shutdown();
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());
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();
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.");
1467 if (!distance_sensor_srv.response.success)
1468 ROS_ERROR(
"Sampling period is not valid.");
1469 ROS_ERROR(
"Failed to enable distance_sensor.");
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);
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);
1489 set_distance_sensor_client.
shutdown();
1490 sampling_period_distance_sensor_client.shutdown();
1498 webots_ros::set_string emitter_send_srv;
1499 emitter_send_client = n.
serviceClient<webots_ros::set_string>(model_name +
"/emitter/send");
1501 emitter_send_srv.request.value =
"abc";
1503 if (emitter_send_client.
call(emitter_send_srv) && emitter_send_srv.response.success)
1504 ROS_INFO(
"Emitter has sent data.");
1506 ROS_ERROR(
"Failed to call service emitter_send to send data.");
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");
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);
1518 emitter_get_buffer_size_client.
shutdown();
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");
1525 emitter_set_channel_srv.request.value = 1;
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.");
1530 ROS_ERROR(
"Failed to call service emitter_set_channel to update channel.");
1532 emitter_set_channel_client.
shutdown();
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");
1539 emitter_set_range_srv.request.value = 50;
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.");
1544 ROS_ERROR(
"Failed to call service emitter_set_range to update range.");
1546 emitter_set_range_client.
shutdown();
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");
1553 emitter_get_channel_client.
call(emitter_get_channel_srv);
1554 ROS_INFO(
"Emitter uses channel %d.", emitter_get_channel_srv.response.value);
1556 emitter_get_channel_client.
shutdown();
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");
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);
1566 emitter_get_range_client.
shutdown();
1574 webots_ros::set_int GPS_srv;
1577 set_GPS_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/gps/enable");
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");
1583 GPS_srv.request.value = 32;
1584 if (set_GPS_client.
call(GPS_srv) && GPS_srv.response.success) {
1602 if (!GPS_srv.response.success)
1603 ROS_ERROR(
"Sampling period is not valid.");
1604 ROS_ERROR(
"Failed to enable GPS.");
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);
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");
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);
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);
1627 sampling_period_GPS_client.shutdown();
1628 gps_get_coordinate_system_client.
shutdown();
1636 webots_ros::set_int gyro_srv;
1638 set_gyro_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/gyro/enable");
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");
1644 gyro_srv.request.value = 32;
1645 if (set_gyro_client.
call(gyro_srv) && gyro_srv.response.success) {
1654 if (!gyro_srv.response.success)
1655 ROS_ERROR(
"Sampling period is not valid.");
1656 ROS_ERROR(
"Failed to enable gyro.");
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());
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();
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);
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);
1683 sampling_period_gyro_client.shutdown();
1691 webots_ros::set_int inertial_unit_srv;
1693 set_inertial_unit_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/inertial_unit/enable");
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");
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.");
1710 if (!inertial_unit_srv.response.success)
1711 ROS_ERROR(
"Sampling period is not valid.");
1712 ROS_ERROR(
"Failed to enable inertial_unit.");
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());
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();
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);
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);
1740 set_inertial_unit_client.
shutdown();
1741 sampling_period_inertial_unit_client.shutdown();
1749 webots_ros::set_int enable_joystick_srv;
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());
1757 ROS_INFO(
"Topics for joystick initialized.");
1759 while (sub_joystick.getNumPublishers() == 0 && !
callbackCalled) {
1763 ROS_INFO(
"Topics for joystick connected.");
1765 ROS_ERROR(
"Failed to enable joystick.");
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());
1778 joystick_get_model_client.
shutdown();
1786 webots_ros::set_int set_led_srv;
1787 set_led_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/led/set_led");
1789 set_led_srv.request.value = 1;
1790 if (set_led_client.
call(set_led_srv) && set_led_srv.response.success)
1793 ROS_ERROR(
"Failed to call service set_led.");
1799 webots_ros::get_int get_led_srv;
1800 get_led_client = n.
serviceClient<webots_ros::get_int>(model_name +
"/led/get_led");
1802 get_led_client.
call(get_led_srv);
1803 ROS_INFO(
"LED value is %d.", get_led_srv.response.value);
1805 set_led_srv.request.value = 0;
1806 if (set_led_client.
call(set_led_srv) && set_led_srv.response.success)
1809 ROS_ERROR(
"Failed to call service set_led.");
1821 webots_ros::set_int lidar_srv;
1824 set_lidar_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/lidar/enable");
1826 if (set_lidar_client.
call(lidar_srv) && lidar_srv.response.success) {
1830 ROS_INFO(
"Topic for lidar initialized.");
1836 ROS_INFO(
"Topic for lidar color connected.");
1838 if (!lidar_srv.response.success)
1839 ROS_ERROR(
"Sampling period is not valid.");
1840 ROS_ERROR(
"Failed to enable lidar.");
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 " 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);
1857 ROS_ERROR(
"Failed to call service lidar_get_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);
1870 ROS_ERROR(
"Failed to call service lidar_get_frequency_info.");
1882 webots_ros::set_int light_sensor_srv;
1884 set_light_sensor_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/light_sensor/enable");
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");
1890 light_sensor_srv.request.value = 32;
1891 if (set_light_sensor_client.
call(light_sensor_srv) && light_sensor_srv.response.success) {
1900 if (!light_sensor_srv.response.success)
1901 ROS_ERROR(
"Sampling period is not valid.");
1902 ROS_ERROR(
"Failed to enable light_sensor.");
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());
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();
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);
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);
1930 set_light_sensor_client.
shutdown();
1931 sampling_period_light_sensor_client.shutdown();
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);
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);
1953 linear_motor_get_type_client.
shutdown();
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());
1966 ROS_ERROR(
"Failed to call service motor_get_brake_name.");
1968 motor_get_brake_name_client.
shutdown();
1972 webots_ros::set_float set_acceleration_srv;
1973 set_acceleration_client = n.
serviceClient<webots_ros::set_float>(model_name +
"/rotational_motor/set_acceleration");
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.");
1979 ROS_ERROR(
"Failed to call service set_acceleration on motor.");
1981 set_acceleration_client.
shutdown();
1985 webots_ros::set_float set_velocity_srv;
1986 set_velocity_client = n.
serviceClient<webots_ros::set_float>(model_name +
"/rotational_motor/set_velocity");
1988 set_velocity_srv.request.value = 0.9;
1989 if (set_velocity_client.
call(set_velocity_srv) && set_velocity_srv.response.success)
1992 ROS_ERROR(
"Failed to call service set_velocity on motor.");
1998 webots_ros::set_float set_force_srv;
1999 set_force_client = n.
serviceClient<webots_ros::set_float>(model_name +
"/linear_motor/set_force");
2001 set_force_srv.request.value = 0.2;
2002 if (set_force_client.
call(set_force_srv) && set_force_srv.response.success)
2005 ROS_ERROR(
"Failed to call service set_force on motor.");
2011 webots_ros::set_float set_torque_srv;
2012 set_torque_client = n.
serviceClient<webots_ros::set_float>(model_name +
"/rotational_motor/set_torque");
2014 set_torque_srv.request.value = 0.5;
2015 if (set_torque_client.
call(set_torque_srv) && set_torque_srv.response.success)
2018 ROS_ERROR(
"Failed to call service set_torque on motor.");
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");
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.");
2031 ROS_ERROR(
"Failed to call service set_available_force on motor.");
2033 set_available_force_client.
shutdown();
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");
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.");
2044 ROS_ERROR(
"Failed to call service set_available_torque on motor.");
2046 set_available_torque_client.
shutdown();
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");
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)
2057 ROS_ERROR(
"Failed to call service set_controlp on motor.");
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");
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.");
2072 ROS_ERROR(
"Failed to call service set_controlp on linear_motor.");
2074 set_linear_control_pid_client.
shutdown();
2079 webots_ros::set_float set_position_srv;
2080 set_position_client = n.
serviceClient<webots_ros::set_float>(model_name +
"/rotational_motor/set_position");
2082 set_position_srv.request.value = 1.5;
2083 if (set_position_client.
call(set_position_srv) && set_position_srv.response.success)
2086 ROS_ERROR(
"Failed to call service set_position on motor.");
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");
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.");
2100 ROS_ERROR(
"Failed to call service set_position on linear_motor.");
2102 set_linear_position_client.
shutdown();
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");
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);
2112 get_target_position_client.
shutdown();
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");
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);
2122 get_min_position_client.
shutdown();
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");
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);
2132 get_max_position_client.
shutdown();
2136 webots_ros::get_float get_velocity_srv;
2137 get_velocity_client = n.
serviceClient<webots_ros::get_float>(model_name +
"/rotational_motor/get_velocity");
2139 get_velocity_client.
call(get_velocity_srv);
2140 ROS_INFO(
"Velocity for rotational_motor is %f.", get_velocity_srv.response.value);
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");
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);
2152 get_max_velocity_client.
shutdown();
2156 webots_ros::get_float get_acceleration_srv;
2157 get_acceleration_client = n.
serviceClient<webots_ros::get_float>(model_name +
"/rotational_motor/get_acceleration");
2159 get_acceleration_client.
call(get_acceleration_srv);
2160 ROS_INFO(
"Acceleration for rotational_motor is %f.", get_acceleration_srv.response.value);
2162 get_acceleration_client.
shutdown();
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");
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);
2172 get_available_force_client.
shutdown();
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");
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);
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");
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);
2192 get_available_torque_client.
shutdown();
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");
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);
2206 webots_ros::set_int motor_feedback_srv;
2208 set_motor_feedback_client =
2209 n.
serviceClient<webots_ros::set_int>(model_name +
"/rotational_motor/torque_feedback_sensor/enable");
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");
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.");
2226 if (!motor_feedback_srv.response.success)
2227 ROS_ERROR(
"Sampling period is not valid.");
2228 ROS_ERROR(
"Failed to enable motor_feedback.");
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);
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);
2244 set_motor_feedback_client.
shutdown();
2245 sampling_period_motor_feedback_client.shutdown();
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");
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.");
2261 ROS_ERROR(
"Failed to call service set_ink_color.");
2267 webots_ros::set_bool pen_write_srv;
2268 pen_write_client = n.
serviceClient<webots_ros::set_bool>(model_name +
"/pen/write");
2270 pen_write_srv.request.value =
true;
2271 if (pen_write_client.
call(pen_write_srv) && pen_write_srv.response.success)
2274 ROS_ERROR(
"Failed to call service pen_write.");
2285 webots_ros::set_int position_sensor_srv;
2287 set_position_sensor_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/position_sensor/enable");
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");
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.");
2304 if (!position_sensor_srv.response.success)
2305 ROS_ERROR(
"Sampling period is not valid.");
2306 ROS_ERROR(
"Failed to enable position_sensor.");
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);
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");
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);
2326 position_sensor_get_type_client.
shutdown();
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);
2332 set_position_sensor_client.
shutdown();
2333 sampling_period_position_sensor_client.shutdown();
2342 webots_ros::set_int radar_srv;
2346 set_radar_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/radar/enable");
2348 if (set_radar_client.
call(radar_srv) && radar_srv.response.success) {
2353 ROS_INFO(
"Topics for radar initialized.");
2359 ROS_INFO(
"Topics for radar connected.");
2361 if (!radar_srv.response.success)
2362 ROS_ERROR(
"Sampling period is not valid.");
2363 ROS_ERROR(
"Failed to enable radar.");
2368 sub_radar_target_number.
shutdown();
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.");
2379 ROS_ERROR(
"Received wrong radar max range.");
2381 ROS_ERROR(
"Failed to call service radar_get_max_range.");
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.");
2392 ROS_ERROR(
"Received wrong radar min range.");
2394 ROS_ERROR(
"Failed to call service radar_get_min_range.");
2407 webots_ros::set_int range_finder_srv;
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) {
2416 ROS_INFO(
"Topic for range-finder initialized.");
2422 ROS_INFO(
"Topic for range-finder connected.");
2424 if (!range_finder_srv.response.success)
2425 ROS_ERROR(
"Sampling period is not valid.");
2426 ROS_ERROR(
"Failed to enable range-finder.");
2431 set_range_finder_client.
shutdown();
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))
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);
2444 ROS_ERROR(
"Failed to call service range_finder_get_info.");
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;
2455 if (save_image_client.
call(save_range_image_srv) && save_range_image_srv.response.success == 1)
2458 ROS_ERROR(
"Failed to call service save_image.");
2463 ROS_INFO(
"Range-finder disabled.");
2470 webots_ros::set_int receiver_srv;
2472 set_receiver_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/receiver/enable");
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");
2478 receiver_srv.request.value = 32;
2479 if (set_receiver_client.
call(receiver_srv) && receiver_srv.response.success) {
2488 if (!receiver_srv.response.success)
2489 ROS_ERROR(
"Sampling period is not valid.");
2490 ROS_ERROR(
"Failed to enable receiver.");
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);
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");
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);
2514 ROS_INFO(
"No message received by emitter, impossible to get buffer size.");
2516 receiver_get_data_size_client.
shutdown();
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");
2524 receiver_set_channel_srv.request.value = 1;
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.");
2529 ROS_ERROR(
"Failed to call service receiver_set_channel to update channel.");
2531 receiver_set_channel_client.
shutdown();
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");
2539 receiver_get_channel_client.
call(receiver_get_channel_srv);
2540 ROS_INFO(
"Receiver uses channel %d.", receiver_get_channel_srv.response.value);
2542 receiver_get_channel_client.
shutdown();
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");
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);
2553 receiver_get_queue_length_client.
shutdown();
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");
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);
2566 ROS_INFO(
"No message received by emitter, impossible to get signal strength.");
2568 receiver_get_signal_strength_client.
shutdown();
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");
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]);
2586 ROS_INFO(
"No message received by emitter, impossible to get signal direction.");
2588 receiver_get_emitter_direction_client.
shutdown();
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");
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.");
2602 ROS_ERROR(
"Failed to call service receiver_next_packet.");
2604 receiver_next_packet_client.
shutdown();
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);
2610 sampling_period_receiver_client.shutdown();
2618 webots_ros::set_int touch_sensor_srv;
2620 set_touch_sensor_client = n.
serviceClient<webots_ros::set_int>(model_name +
"/touch_sensor/enable");
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");
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");
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);
2633 touch_sensor_get_type_client.shutdown();
2636 touch_sensor_srv.request.value = 32;
2637 if (set_touch_sensor_client.
call(touch_sensor_srv) && touch_sensor_srv.response.success) {
2639 if (touch_sensor_get_type_srv.response.value == 0)
2641 else if (touch_sensor_get_type_srv.response.value == 1)
2651 if (!touch_sensor_srv.response.success)
2652 ROS_ERROR(
"Sampling period is not valid.");
2653 ROS_ERROR(
"Failed to enable touch_sensor.");
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());
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();
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);
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);
2681 set_touch_sensor_client.
shutdown();
2682 sampling_period_touch_sensor_client.shutdown();
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");
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.");
2698 ROS_ERROR(
"Failed to call service simulation_reset_physics.");
2700 supervisor_simulation_reset_physics_client.
shutdown();
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");
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.");
2712 ROS_ERROR(
"Failed to call service export_image.");
2714 supervisor_export_image_client.
shutdown();
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");
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.");
2732 ROS_ERROR(
"Failed to call service set_label.");
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");
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;
2744 supervisor_get_root_client.
shutdown();
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");
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;
2755 supervisor_get_self_client.
shutdown();
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");
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;
2770 ROS_ERROR(
"Could not get node from DEF.");
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");
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);
2782 supervisor_node_get_type_client.
shutdown();
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");
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());
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());
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());
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;
2809 ROS_ERROR(
"Could not get node from DEF GROUND.");
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());
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());
2825 supervisor_node_get_base_type_name_client.
shutdown();
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());
2835 supervisor_node_get_def_client.
shutdown();
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");
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);
2848 supervisor_node_get_position_client.
shutdown();
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");
2856 supervisor_node_get_orientation_srv.request.node = from_def_node;
2857 supervisor_node_get_orientation_client.
call(supervisor_node_get_orientation_srv);
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);
2863 supervisor_node_get_orientation_client.
shutdown();
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");
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);
2878 supervisor_node_get_center_of_mass_client.
shutdown();
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");
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);
2891 supervisor_node_get_number_of_contact_points_client.
shutdown();
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");
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);
2906 supervisor_node_get_contact_point_client.
shutdown();
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");
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);
2920 supervisor_node_get_static_balance_client.
shutdown();
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;
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.");
2934 ROS_ERROR(
"Failed to call service node_reset_physics.");
2936 supervisor_node_reset_physics_client.
shutdown();
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;
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.");
2949 ROS_ERROR(
"Failed to call service node_restart_controller.");
2951 supervisor_node_restart_controller_client.
shutdown();
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");
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;
2964 supervisor_node_get_field_client.
shutdown();
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");
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);
2975 supervisor_field_get_type_client.
shutdown();
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");
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());
2987 supervisor_field_get_type_name_client.
shutdown();
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");
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);
2999 ROS_ERROR(
"Illegal call to Field::getCount() argument must be multiple fields.");
3001 supervisor_field_get_count_client.
shutdown();
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;
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");
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'.");
3020 ROS_ERROR(
"Failed to call service field_set_string.");
3022 supervisor_field_set_string_client.
shutdown();
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");
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());
3034 supervisor_field_get_string_client.
shutdown();
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;
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");
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);
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());
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;
3063 ROS_ERROR(
"could not get CONE node from DEF.");
3065 supervisor_node_get_type_name_client.
shutdown();
3066 supervisor_get_from_def_client.
shutdown();
3067 supervisor_field_get_node_client.
shutdown();
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.");
3079 ROS_ERROR(
"Failed to call service node_get_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.");
3093 ROS_ERROR(
"Failed to call service supervisor_get_from_id.");
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.");
3112 ROS_ERROR(
"Failed to call service node_set_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.");
3125 ROS_ERROR(
"Failed to call service node_get_velocity.");
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.");
3143 ROS_ERROR(
"Failed to call service node_add_force_or_torque.");
3145 node_add_force_or_torque_client.
shutdown();
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.");
3165 ROS_ERROR(
"Failed to call service node_add_force_with_offset.");
3167 node_add_force_with_offset_client.
shutdown();
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.");
3180 ROS_ERROR(
"Failed to call service node_get_parent_node.");
3182 node_get_parent_node_client.
shutdown();
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");
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.");
3194 ROS_ERROR(
"Failed to call service supervisor_movie_is_ready.");
3196 supervisor_movie_is_ready_client.
shutdown();
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");
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.");
3214 ROS_ERROR(
"Failed to call service movie_start_recording.");
3216 supervisor_movie_start_client.
shutdown();
3217 for (
int i = 0; i < 25; ++i)
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");
3224 if (supervisor_movie_stop_client.
call(supervisor_movie_stop_srv) && supervisor_movie_stop_srv.response.value)
3225 ROS_INFO(
"Movie stopped successfully.");
3227 ROS_ERROR(
"Failed to call service movie_stop_recording.");
3229 supervisor_movie_stop_client.
shutdown();
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");
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.");
3239 ROS_ERROR(
"Failed movie recording.");
3241 supervisor_movie_failed_client.
shutdown();
3244 supervisor_set_label_srv.request.label =
"";
3245 supervisor_set_label_client.
call(supervisor_set_label_srv);
3247 supervisor_set_label_client.
shutdown();
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.");
3259 ROS_ERROR(
"Failed to call service field_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;
3271 ROS_INFO(
"Node removed successfully.");
3273 ROS_ERROR(
"Failed to call service node_removed.");
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.");
3286 ROS_ERROR(
"Failed to call service robot/wwi_send_text.");
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.");
3298 ROS_ERROR(
"Failed to call service robot/wwi_receive_text.");
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;
3312 ROS_INFO(
"No virtual reality headset connected.");
3314 ROS_ERROR(
"Virtual reality headset wrongly detected.");
3316 virtual_reality_headset_client.
shutdown();
3363 ROS_INFO(
"Robot's time step called to end tests.");
3365 ROS_ERROR(
"Failed to call service time_step to end tests.");
3371 printf(
"\nTest Completed\n");
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)
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)
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 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
void touchSensor3DCallback(const geometry_msgs::WrenchStamped::ConstPtr &values)
static bool callbackCalled
ROSCPP_DECL void spinOnce()
static vector< float > imageRangeFinder
void compassCallback(const sensor_msgs::MagneticField::ConstPtr &values)
void radarTargetsCallback(const webots_ros::RadarTarget::ConstPtr &target)