Merge branch 'master' of https://www.ikko-lab.k.hosei.ac.jp/gitbucket/git/tsukuba2022/waypoint_navigation
commit 209cf1418c6d68e19ab6d5d6dd644a74f99d91e6
2 parents 8ec4de3 + fde79be
@koki0624 koki0624 authored on 14 Nov 2022
Showing 2 changed files
View
37
waypoint_nav/scripts/tandem_run_manager.py
## Dynamic reconfigure clients
self.costmap_client1 = dynamic_reconfigure.client.Client("/move_base/global_costmap/obstacle_layer1")
self.costmap_client2 = dynamic_reconfigure.client.Client("/move_base/global_costmap/obstacle_layer2")
## Variable
self.front_angle = 40 # degree
self.danger_dist = 1.0 # meter
self.waypoint_num = 0
self.front_range = None
self.danger_dist = 1.0
self.in_tandem_area = False
self.stop = False
## for debug
# self.scan_pub = rospy.Publisher("/debug_scan", LaserScan, queue_size=10)
return
 
 
## Subscribe current waypoint number
def laserscan_callback(self, msg):
try:
if self.front_range is None:
front = round(-msg.angle_min / msg.angle_increment)
ran = int(round(np.deg2rad(10) / msg.angle_increment))
ran = int(round(np.deg2rad(self.front_angle/2) / msg.angle_increment))
self.front_range = [front-ran, front+ran]
return
if not self.in_tandem_area: return
sort_ranges = np.sort(msg.ranges[self.front_range[0]:self.front_range[1]])
min_range = np.mean(sort_ranges[:5])
ranges = np.array(msg.ranges[self.front_range[0]:self.front_range[1]])
## Use simply minimum
ranges[ranges <= msg.range_min] = msg.range_max
min_range = min(ranges)
## or use sort
#sort_ranges = np.sort(ranges)
#min_range = np.mean(sort_ranges[:5])
if (not self.stop) and (min_range < self.danger_dist):
self.stop_nav()
self.stop = True
rospy.loginfo("Stop because of obstacle within {}m ahead.".format(self.danger_dist))
elif (self.stop) and (min_range >= self.danger_dist+0.1):
self.resume_nav()
self.stop = False
rospy.loginfo("Resumed navigation because the obstacle ahead was more than {}m away.".format(self.danger_dist+0.1))
## for debug
# debug_scan = msg
# debug_scan.ranges = np.array(msg.ranges)
# debug_scan.ranges[:self.front_range[0]] = 0
# debug_scan.ranges[self.front_range[1]:] = 0
# debug_scan.ranges = tuple(debug_scan.ranges)
# self.scan_pub.publish(debug_scan)
except AttributeError:
pass
return
 
View
10
waypoint_nav/src/waypoint_nav.cpp
if (time - start_nav_time > 10.0 && time - last_moved_time_ > 10.0) {
ROS_WARN("Resend the navigation goal.");
clear_costmaps_srv_.call(empty);
startNavigationGL(*current_waypoint_);
// resend_goal++;
//if (resend_goal == 3) {
// ROS_WARN("Skip waypoint.");
// break;
//}
resend_goal++;
if (resend_goal == 3) {
ROS_WARN("Skip waypoint.");
break;
}
start_nav_time = time;
}
wp_num_pub_.publish(wp_num_);
sleep();