18 #include <webots_ros/get_bool.h> 19 #include <webots_ros/get_int.h> 20 #include <webots_ros/get_uint64.h> 21 #include <webots_ros/set_int.h> 23 #include <webots_ros/field_get_node.h> 24 #include <webots_ros/field_get_rotation.h> 25 #include <webots_ros/field_get_type_name.h> 26 #include <webots_ros/field_get_vec3f.h> 27 #include <webots_ros/field_set_rotation.h> 28 #include <webots_ros/field_set_vec3f.h> 29 #include <webots_ros/node_get_field.h> 30 #include <webots_ros/supervisor_movie_start_recording.h> 31 #include <webots_ros/supervisor_set_label.h> 33 #include <std_msgs/String.h> 53 ROS_INFO(
"User stopped the 'panoramic_view_recorder' node.");
58 int main(
int argc,
char **argv) {
80 int wantedController = 0;
81 std::cout <<
"Choose the # of the controller you want to use:\n";
82 std::cin >> wantedController;
86 ROS_ERROR(
"Invalid number for controller choice.");
93 timeStepClient = n.
serviceClient<webots_ros::set_int>(controllerName +
"/robot/time_step");
96 ROS_INFO(
"Welcome to the panoramic_view_recorder example.");
97 ROS_INFO(
"This node will connect to a supervisor in Webots and access world to record a panoramic movie around a nao robot.");
101 webots_ros::get_uint64 getWorldSrv;
102 getWorldClient.
call(getWorldSrv);
106 n.
serviceClient<webots_ros::node_get_field>(controllerName +
"/supervisor/node/get_field");
107 webots_ros::node_get_field getWorldChildrenSrv;
108 getWorldChildrenSrv.request.node = getWorldSrv.response.value;
109 getWorldChildrenSrv.request.fieldName =
"children";
110 getWorldChildrenClient.
call(getWorldChildrenSrv);
114 webots_ros::field_get_node getPovSrv;
115 getPovSrv.request.field = getWorldChildrenSrv.response.field;
116 getPovSrv.request.index = 1;
117 getPovClient.
call(getPovSrv);
121 n.
serviceClient<webots_ros::node_get_field>(controllerName +
"/supervisor/node/get_field");
122 webots_ros::node_get_field getPovPositionFieldSrv;
123 getPovPositionFieldSrv.request.node = getPovSrv.response.node;
124 getPovPositionFieldSrv.request.fieldName =
"position";
125 getPovPositionFieldClient.
call(getPovPositionFieldSrv);
128 n.
serviceClient<webots_ros::field_get_vec3f>(controllerName +
"/supervisor/field/get_vec3f");
129 webots_ros::field_get_vec3f getPovPositionSrv;
130 getPovPositionSrv.request.field = getPovPositionFieldSrv.response.field;
131 getPositionClient.
call(getPovPositionSrv);
132 geometry_msgs::Vector3 initialPovPosition = getPovPositionSrv.response.value;
135 n.
serviceClient<webots_ros::node_get_field>(controllerName +
"/supervisor/node/get_field");
136 webots_ros::node_get_field getPovOrientationFieldSrv;
137 getPovOrientationFieldSrv.request.node = getPovSrv.response.node;
138 getPovOrientationFieldSrv.request.fieldName =
"orientation";
139 getPovOrientationFieldClient.
call(getPovOrientationFieldSrv);
142 n.
serviceClient<webots_ros::field_get_rotation>(controllerName +
"/supervisor/field/get_rotation");
143 webots_ros::field_get_rotation getPovOrientationSrv;
144 getPovOrientationSrv.request.field = getPovOrientationFieldSrv.response.field;
145 getPovOrientationClient.
call(getPovOrientationSrv);
146 geometry_msgs::Quaternion povOrientation = getPovOrientationSrv.response.value;
148 ROS_INFO(
"Initial position of point of view is %f %f %f and its orientation is %f %f %f %f.", initialPovPosition.x,
149 initialPovPosition.y, initialPovPosition.z, povOrientation.x, povOrientation.y, povOrientation.z, povOrientation.w);
155 n.
serviceClient<webots_ros::field_set_vec3f>(controllerName +
"/supervisor/field/set_vec3f");
156 webots_ros::field_set_vec3f setPovPositionSrv;
157 setPovPositionSrv.request.field = getPovPositionFieldSrv.response.field;
158 setPovPositionSrv.request.value = initialPovPosition;
161 n.
serviceClient<webots_ros::field_set_rotation>(controllerName +
"/supervisor/field/set_rotation");
162 webots_ros::field_set_rotation setPovOrientationSrv;
163 setPovOrientationSrv.request.field = getPovOrientationFieldSrv.response.field;
164 setPovOrientationSrv.request.value = povOrientation;
168 webots_ros::supervisor_set_label supervisorSetLabelSrv;
169 supervisorSetLabelClient = n.
serviceClient<webots_ros::supervisor_set_label>(controllerName +
"/supervisor/set_label");
171 supervisorSetLabelSrv.request.id = 1;
172 supervisorSetLabelSrv.request.label =
"Recording";
173 supervisorSetLabelSrv.request.xpos = 0.02;
174 supervisorSetLabelSrv.request.ypos = 0.1;
175 supervisorSetLabelSrv.request.size = 0.2;
176 supervisorSetLabelSrv.request.color = 0XFF0000;
177 supervisorSetLabelSrv.request.transparency = 0;
178 supervisorSetLabelSrv.request.font =
"Tahoma";
179 if (!supervisorSetLabelClient.
call(supervisorSetLabelSrv) || supervisorSetLabelSrv.response.success != 1)
180 ROS_ERROR(
"Failed to call service set_label.");
184 webots_ros::supervisor_movie_start_recording supervisorMovieStartSrv;
185 supervisorMovieStartClient =
186 n.
serviceClient<webots_ros::supervisor_movie_start_recording>(controllerName +
"/supervisor/movie_start_recording");
188 supervisorMovieStartSrv.request.filename = std::string(getenv(
"HOME")) + std::string(
"/supervisor_movie.mp4");
189 supervisorMovieStartSrv.request.width = 480;
190 supervisorMovieStartSrv.request.height = 360;
191 supervisorMovieStartSrv.request.codec = 1337;
192 supervisorMovieStartSrv.request.quality = 100;
193 supervisorMovieStartSrv.request.acceleration = 1;
194 supervisorMovieStartSrv.request.caption =
false;
195 if (supervisorMovieStartClient.
call(supervisorMovieStartSrv) && supervisorMovieStartSrv.response.success == 1)
196 ROS_INFO(
"Movie started recording.");
198 ROS_ERROR(
"Failed to call service movie_start_recording.");
201 while (angle < 6.28) {
203 setPovOrientationSrv.request.value.w = cos(0.5 * angle);
204 setPovOrientationSrv.request.value.y = sin(0.5 * angle);
205 double cosAngle = cos(angle);
206 double sinAngle = sin(angle);
207 if (setPovOrientationClient.
call(setPovOrientationSrv) && setPovOrientationSrv.response.success == 1) {
208 setPovPositionSrv.request.value.x = initialPovPosition.z * sinAngle;
209 setPovPositionSrv.request.value.z = initialPovPosition.z * cosAngle;
210 if (setPositionClient.
call(setPovPositionSrv) && setPovPositionSrv.response.success == 1) {
212 ROS_ERROR(
"Couldn't update robot step.");
214 ROS_ERROR(
"Failed to send new point of view position.");
216 ROS_ERROR(
"Failed to send new point of view orientation.");
221 webots_ros::get_bool supervisorMovieStopSrv;
222 supervisorMovieStopClient = n.
serviceClient<webots_ros::get_bool>(controllerName +
"/supervisor/movie_stop_recording");
224 if (supervisorMovieStopClient.
call(supervisorMovieStopSrv) && supervisorMovieStopSrv.response.value)
225 ROS_INFO(
"Movie stopped recording.");
227 ROS_ERROR(
"Failed to call service movie_stop_recording.");
229 supervisorSetLabelSrv.request.label =
"";
230 supervisorSetLabelClient.
call(supervisorSetLabelSrv);
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::ServiceClient timeStepClient
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
static std::string controllerName
void controllerNameCallback(const std_msgs::String::ConstPtr &name)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
static std::vector< std::string > controllerList
static int controllerCount
uint32_t getNumPublishers() const
int main(int argc, char **argv)
ROSCPP_DECL void shutdown()
ROSCPP_DECL void spinOnce()
webots_ros::set_int timeStepSrv