13 from sensor_msgs.msg
import LaserScan
14 from geometry_msgs.msg
import Twist
15 from nav_msgs.msg
import Odometry
16 from tf
import transformations
42 res = SetBoolResponse()
51 'right': min(min(msg.ranges[0:143]), 10),
52 'fright': min(min(msg.ranges[144:287]), 10),
53 'front': min(min(msg.ranges[288:431]), 10),
54 'fleft': min(min(msg.ranges[432:575]), 10),
55 'left': min(min(msg.ranges[576:713]), 10),
62 global state_, state_dict_
63 if state
is not state_:
64 print (
'Wall follower - [%s] - %s' % (state, state_dict_[state]))
74 state_description =
''
79 if regions[
'front'] > d0
and regions[
'fleft'] > d
and regions[
'fright'] > d:
80 state_description =
'case 1 - nothing'
82 elif regions[
'front'] < d0
and regions[
'fleft'] > d
and regions[
'fright'] > d:
83 state_description =
'case 2 - front'
85 elif regions[
'front'] > d0
and regions[
'fleft'] > d
and regions[
'fright'] < d:
86 state_description =
'case 3 - fright'
88 elif regions[
'front'] > d0
and regions[
'fleft'] < d
and regions[
'fright'] > d:
89 state_description =
'case 4 - fleft'
91 elif regions[
'front'] < d0
and regions[
'fleft'] > d
and regions[
'fright'] < d:
92 state_description =
'case 5 - front and fright'
94 elif regions[
'front'] < d0
and regions[
'fleft'] < d
and regions[
'fright'] > d:
95 state_description =
'case 6 - front and fleft'
97 elif regions[
'front'] < d0
and regions[
'fleft'] < d
and regions[
'fright'] < d:
98 state_description =
'case 7 - front and fleft and fright'
100 elif regions[
'front'] > d0
and regions[
'fleft'] < d
and regions[
'fright'] < d:
101 state_description =
'case 8 - fleft and fright'
104 state_description =
'unknown case'
105 rospy.loginfo(regions)
132 rospy.init_node(
'reading_laser')
134 pub_ = rospy.Publisher(
'/cmd_vel', Twist, queue_size=1)
136 sub = rospy.Subscriber(
'/scan', LaserScan, clbk_laser)
138 srv = rospy.Service(
'wall_follower_switch', SetBool, wall_follower_switch)
140 rate = rospy.Rate(20)
141 while not rospy.is_shutdown():
154 rospy.logerr(
'Unknown state!')
161 if __name__ ==
'__main__':
def wall_follower_switch(req)