14 for(
int index; index < points_.size()-1; ++index) {
15 segments.emplace_back(points_.at(index), points_.at(index+1));
32 map_pub = n.advertise<nav_msgs::OccupancyGrid>(
"map", 1,
true);
47 for(std::vector<Obstacle>::iterator it =
obstacles.begin(); it !=
obstacles.end(); ++it) {
48 if ((*it).name == name){
49 (*it).clearSegments();
50 (*it).setSegments(points);
57 for (
int index = 0; index <=
obstacles.size(); ++index){
71 tf::StampedTransform transform;
72 std::vector<Point_2> points;
74 for(std::vector<int>::iterator it = alvar_nums.begin(); it != alvar_nums.end(); ++it) {
81 ros::Time(0), transform);
82 points.push_back(
Point_2(transform.getOrigin().x(), transform.getOrigin().y()));
84 catch (tf::TransformException &ex) {
85 ROS_ERROR(
"%s",ex.what());
89 for(std::vector<Obstacle>::iterator it =
obstacles.begin(); it !=
obstacles.end(); ++it) {
90 if ((*it).name == name){
91 (*it).clearSegments();
92 (*it).setSegments(points);
101 for(std::vector<Obstacle>::iterator it_obstacles =
obstacles.begin(); it_obstacles !=
obstacles.end(); ++it_obstacles) {
102 for(std::vector<Segment_2>::iterator it_segments = (*it_obstacles).segments.begin(); it_segments != (*it_obstacles).segments.end(); ++ it_segments){
104 Point_2 p1 = (*it_segments).source();
105 Point_2 p2 = (*it_segments).target();
111 float dx = std::abs(x2 - x1);
112 float dy = std::abs(y2 - y1);
117 float m = float((y2 - y1)/dx);
118 for (
int i = x1; i < x2; i++) {
126 float m = float((y1 - y2)/dx);
127 for (
int i = x2; i < x1; i++) {
137 float m = float((x2 - x1)/dy);
138 for (
int i = y1; i < y2; i++) {
146 float m = float((x1 - x2)/dy);
147 for (
int i = y2; i < y1; i++) {
161 nav_msgs::OccupancyGrid grid;
163 grid.header.frame_id =
"map";
165 nav_msgs::MapMetaData mapData;
167 mapData.map_load_time = ros::Time::now();
172 geometry_msgs::Pose
origin;
193 time = ros::Time::now();
223 qMap.setRPY(0, 0, 0);
229 tf::Quaternion qOdom;
230 qOdom.setRPY(0, 0, 0);
236 tf::Quaternion qBase_link;
237 qBase_link.setRPY(0, 0, 0);
253 tf::StampedTransform transform;
257 ros::Time lastCommonTime;
258 std::string* error_string;
260 lastCommonTime, error_string);
262 if (lastCommonTime !=
time)
265 ros::Time(0), transform);
267 ros::Duration dt = ros::Time::now() - lastCommonTime;
269 transformBase_Link.setOrigin(tf::Vector3(transform.getOrigin().x()+
vx*dt.toSec(), transform.getOrigin().y()+
vy*dt.toSec(), 0.0));
270 time = lastCommonTime;
273 tf::Matrix3x3(transform.getRotation()).getRPY(
roll,
pitch,
yaw);
275 tf::Quaternion qBase_link;
283 pose_alvar.pose.pose.position.x = transform.getOrigin().x();
284 pose_alvar.pose.pose.position.y = transform.getOrigin().y();
286 pose_alvar.pose.pose.orientation = tf::createQuaternionMsgFromYaw(
yaw);
299 catch (tf::TransformException &ex) {
307 tf::StampedTransform transform;
311 ros::Time lastCommonTime;
312 std::string* error_string;
314 lastCommonTime, error_string);
316 if (lastCommonTime !=
time)
319 ros::Time(0), transform);
321 ros::Duration dt = ros::Time::now() - lastCommonTime;
323 transformBase_Link.setOrigin(tf::Vector3(transform.getOrigin().x()+
vx*dt.toSec(), transform.getOrigin().y()+
vy*dt.toSec(), 0.0));
325 time = lastCommonTime;
327 tf::Matrix3x3(transform.getRotation()).getRPY(
roll,
pitch,
yaw);
329 tf::Quaternion qBase_link;
333 x = transform.getOrigin().x();
334 y = transform.getOrigin().y();
339 catch (tf::TransformException &ex) {
340 ROS_ERROR(
"%s",ex.what());
348 tf::Quaternion qBase_link;
352 msg.pose.pose.orientation.x,
353 msg.pose.pose.orientation.y,
354 msg.pose.pose.orientation.z,
355 msg.pose.pose.orientation.w);
361 x = msg.pose.pose.position.x;
362 y = msg.pose.pose.position.y;
364 qBase_link.setRPY(0, 0,
yaw);
375 ros::Duration dt = ros::Time::now() -
time_2;
376 time_2 = ros::Time::now();
378 tf::Quaternion qBase_link;
380 double vx_beagle = msg.twist.twist.linear.x;
381 double vy_beagle = msg.twist.twist.linear.y;
383 double angularz = msg.twist.twist.angular.z;
387 msg.pose.pose.orientation.x,
388 msg.pose.pose.orientation.y,
389 msg.pose.pose.orientation.z,
390 msg.pose.pose.orientation.w);
395 double v = vx_beagle/cos(
yaw);
400 qBase_link.setRPY(0, 0,
fi);
403 x =
x +
vx*dt.toSec();
404 y =
y +
vy*dt.toSec();
416 odom.pose.pose.position.x =
x;
417 odom.pose.pose.position.y =
y;
418 odom.pose.pose.position.z = 0.0;
419 odom.pose.pose.orientation = tf::createQuaternionMsgFromYaw(
fi);
423 odom.twist.twist.linear.x =
vx;
424 odom.twist.twist.linear.y =
vy;
433 std::vector<Segment_2> segments;
434 for(std::vector<Obstacle>::iterator it_obstacles = field->
obstacles.begin(); it_obstacles != field->
obstacles.end(); ++it_obstacles) {
435 for(std::vector<Segment_2>::iterator it_segments = (*it_obstacles).segments.begin(); it_segments != (*it_obstacles).segments.end(); ++ it_segments){
436 segments.push_back(*it_segments);
439 std::vector<Obstacle>::iterator it_obstacle_first = field->
obstacles.begin();
440 Point_2 *points = &((*it_obstacle_first).points[0]);
441 Polygon_2 pgn(points, points+(*it_obstacle_first).points.size()-1);
442 for (
int i = 0; i<list_length; i++){
445 Point_2 h1(robotek_list[i].
x+0.1*std::cos(3.14159/4. +
fi), robotek_list[i].
y + 0.1*std::sin(3.1415926/4. +
fi));
446 Point_2 h2(robotek_list[i].
x+0.1*std::cos(3.14159*3./4. +
fi), robotek_list[i].
y + 0.1*std::sin(3.1415926*3./4. +
fi));
447 Point_2 h3(robotek_list[i].
x+0.1*std::cos(3.14159*5./4. +
fi), robotek_list[i].
y + 0.1*std::sin(3.1415926*5./4. +
fi));
448 Point_2 h4(robotek_list[i].
x+0.1*std::cos(3.14159*7./4. +
fi), robotek_list[i].
y + 0.1*std::sin(3.1415926*7./4. +
fi));
457 CGAL::insert(env,segments.begin(),segments.end());
460 Arrangement_2::Face_const_handle * face;
461 CGAL::Arr_naive_point_location<Arrangement_2> pl(env);
462 CGAL::Arr_point_location_result<Arrangement_2>::Type obj = pl.locate(query_point);
465 face = boost::get<Arrangement_2::Face_const_handle> (&obj);
467 CGAL::Bounded_side bside = pgn.bounded_side(query_point);
468 if (bside == CGAL::ON_BOUNDED_SIDE) {
472 Face_handle fh = tev.compute_visibility(query_point, *face, output_arr);
474 Arrangement_2::Ccb_halfedge_circulator curr = fh->outer_ccb();
476 sensor_msgs::LaserScan LaserScan_msg;
478 LaserScan_msg.header.stamp = ros::Time::now();
481 LaserScan_msg.angle_min = 0.;
482 LaserScan_msg.angle_max = 2*3.1415926;
484 LaserScan_msg.angle_increment = 3.1415926/40.;
485 LaserScan_msg.time_increment = 0.001;
487 LaserScan_msg.scan_time = 0.1;
489 LaserScan_msg.range_min = 0.01;
490 LaserScan_msg.range_max = 4.0;
491 int size = (int)((LaserScan_msg.angle_max - LaserScan_msg.angle_min)/LaserScan_msg.angle_increment+2);
492 LaserScan_msg.ranges.resize(size);
494 float ray_angle = LaserScan_msg.angle_increment;
496 while (ray_angle <= LaserScan_msg.angle_max){
497 Ray_2 ray(query_point,
Vector_2(std::cos(
fi+ray_angle), std::sin(
fi+ray_angle)));
499 auto result = CGAL::intersection(ray,
Segment_2(curr->source()->point(), curr->target()->point()));
501 Point_2* p = boost::get<Point_2>(&*result);
502 double distance = std::pow(CGAL::to_double(squared_distance(query_point, *p)), 0.5);
503 LaserScan_msg.ranges.at(index) = distance;
506 while (++curr != fh->outer_ccb()){
508 auto result = CGAL::intersection(ray,
Segment_2(curr->source()->point(), curr->target()->point()));
510 Point_2* p = boost::get<Point_2>(&*result);
511 double distance = std::pow(CGAL::to_double(squared_distance(query_point, *p)), 0.5);
512 LaserScan_msg.ranges.at(index) = distance;
517 ray_angle+=LaserScan_msg.angle_increment;
525 ros::Time transmit_time = ros::Time::now();
568 float vel = msg.linear.x;
569 float rotation = msg.angular.z;
572 float wheel_left = vel/(3.14159265*
wheelRadius) - wheel_right;
574 wheelSrv.request.value = -wheel_right*5.;
576 wheelSrv.request.value = -wheel_left*5.;
582 std::vector<Segment_2> segments;
583 for(std::vector<Obstacle>::iterator it_obstacles = field->
obstacles.begin(); it_obstacles != field->
obstacles.end(); ++it_obstacles) {
584 for(std::vector<Segment_2>::iterator it_segments = (*it_obstacles).segments.begin(); it_segments != (*it_obstacles).segments.end(); ++ it_segments){
585 segments.push_back(*it_segments);
588 std::vector<Obstacle>::iterator it_obstacle_first = field->
obstacles.begin();
589 Point_2 *points = &((*it_obstacle_first).points[0]);
590 Polygon_2 pgn(points, points+(*it_obstacle_first).points.size()-1);
591 for (
int i = 0; i<list_length; i++){
594 Point_2 h1(robotek_list[i].
x+0.1*std::cos(3.14159/4. +
fi), robotek_list[i].
y + 0.1*std::sin(3.1415926/4. +
fi));
595 Point_2 h2(robotek_list[i].
x+0.1*std::cos(3.14159*3./4. +
fi), robotek_list[i].
y + 0.1*std::sin(3.1415926*3./4. +
fi));
596 Point_2 h3(robotek_list[i].
x+0.1*std::cos(3.14159*5./4. +
fi), robotek_list[i].
y + 0.1*std::sin(3.1415926*5./4. +
fi));
597 Point_2 h4(robotek_list[i].
x+0.1*std::cos(3.14159*7./4. +
fi), robotek_list[i].
y + 0.1*std::sin(3.1415926*7./4. +
fi));
606 CGAL::insert(env,segments.begin(),segments.end());
609 Arrangement_2::Face_const_handle * face;
610 CGAL::Arr_naive_point_location<Arrangement_2> pl(env);
611 CGAL::Arr_point_location_result<Arrangement_2>::Type obj = pl.locate(query_point);
614 face = boost::get<Arrangement_2::Face_const_handle> (&obj);
616 CGAL::Bounded_side bside = pgn.bounded_side(query_point);
617 if (bside == CGAL::ON_BOUNDED_SIDE) {
621 Face_handle fh = tev.compute_visibility(query_point, *face, output_arr);
623 Arrangement_2::Ccb_halfedge_circulator curr = fh->outer_ccb();
625 sensor_msgs::LaserScan LaserScan_msg;
627 LaserScan_msg.header.stamp = ros::Time::now();
630 LaserScan_msg.angle_min = 0.;
631 LaserScan_msg.angle_max = 2*3.1415926;
633 LaserScan_msg.angle_increment = 3.1415926/40.;
634 LaserScan_msg.time_increment = 0.001;
636 LaserScan_msg.scan_time = 0.1;
638 LaserScan_msg.range_min = 0.01;
639 LaserScan_msg.range_max = 4.0;
640 int size = (int)((LaserScan_msg.angle_max - LaserScan_msg.angle_min)/LaserScan_msg.angle_increment+2);
641 LaserScan_msg.ranges.resize(size);
643 float ray_angle = LaserScan_msg.angle_increment;
645 while (ray_angle <= LaserScan_msg.angle_max){
646 Ray_2 ray(query_point,
Vector_2(std::cos(
fi+ray_angle), std::sin(
fi+ray_angle)));
648 auto result = CGAL::intersection(ray,
Segment_2(curr->source()->point(), curr->target()->point()));
650 Point_2* p = boost::get<Point_2>(&*result);
651 double distance = std::pow(CGAL::to_double(squared_distance(query_point, *p)), 0.5);
652 LaserScan_msg.ranges.at(index) = distance;
655 while (++curr != fh->outer_ccb()){
657 auto result = CGAL::intersection(ray,
Segment_2(curr->source()->point(), curr->target()->point()));
659 Point_2* p = boost::get<Point_2>(&*result);
660 double distance = std::pow(CGAL::to_double(squared_distance(query_point, *p)), 0.5);
661 LaserScan_msg.ranges.at(index) = distance;
666 ray_angle+=LaserScan_msg.angle_increment;
679 ros::ServiceClient enableGyroClient =
681 webots_ros::set_int enableGyroSrv;
683 enableGyroSrv.request.value = 2 *
TIME_STEP;
684 if (enableGyroClient.call(enableGyroSrv) && enableGyroSrv.response.success) {
685 ROS_INFO(
"Gyro enabled with sampling period %d.", enableGyroSrv.request.value);}
696 while (
subGyro.getNumPublishers() == 0) {
717 tf::Quaternion qCamera(0.0, 0.0, 0.0, 1.0);
718 qCamera.setRPY(3.14159, 0, 0);
742 pub = imgt.advertise(
"/camera/image_raw", 1);
743 pub_info = nh.advertise<sensor_msgs::CameraInfo>(
"/camera/camera_info", 100);
746 ros::ServiceClient deviceListClient = nh.serviceClient<webots_ros::robot_get_device_list>(
controllerNameinWebots +
"/robot/get_device_list");
747 std::vector<std::string> deviceList;
748 webots_ros::robot_get_device_list deviceListSrv;
750 if (deviceListClient.call(deviceListSrv)) {
751 deviceList = deviceListSrv.response.list;
752 ROS_INFO(
"The controller has %lu devices availables:", deviceList.size());
753 for (
unsigned int i = 0; i < deviceList.size(); i++)
754 ROS_INFO(
"Device [%d]: %s.", i, deviceList[i].c_str());
756 ROS_ERROR(
"Failed to call service deviceList.");
760 ros::ServiceClient cameraGetInfoClient =
763 webots_ros::camera_get_info cameraGetInfoSrv;
764 if (cameraGetInfoClient.call(cameraGetInfoSrv)) {
765 width = cameraGetInfoSrv.response.width;
766 height = cameraGetInfoSrv.response.height;
767 ROS_INFO(
"Camera size is %d x %d.",
width,
height);
769 ROS_ERROR(
"Failed to call service range_finder_get_info.");
775 cam_info.header.stamp = ros::Time::now();
776 cam_info.header.frame_id =
"camera_link";
777 cam_info.distortion_model =
"plumb_bob";
810 int size = image->width * image->height;
813 const float *depth_data = reinterpret_cast<const float *>(&image->data[0]);
814 for (
int i = 0; i < size; ++i)
820 ros::ServiceClient enableCameraClient =
822 webots_ros::set_int enableCameraSrv;
824 enableCameraSrv.request.value = 2 *
TIME_STEP;
825 if (enableCameraClient.call(enableCameraSrv) && enableCameraSrv.response.success) {
826 ROS_INFO(
"Camera enabled with sampling period %d.", enableCameraSrv.request.value);}
842 sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(),
"bgra8", image).toImageMsg();
844 msg->header.stamp = ros::Time::now();
845 cam_info.header.stamp = ros::Time::now();