3 Obstacle Avoidance Example Code 5 Written by: Zahi Kakish (zmk5) 11 from geometry_msgs.msg
import Twist
12 from pheeno_robot
import PheenoRobot
16 """ Get arguments from rosrun for individual deployment. """ 17 parser = argparse.ArgumentParser(
18 description=
"Obstacle avoidance python script." 22 parser.add_argument(
"-n",
"--number",
25 help=
"Add a pheeno number namespace.",
30 return parser.parse_args(rospy.myargv()[1:])
35 Obstacle Avoidance Pheeno 37 In this demo task, the Pheeno robot does a random walk, but avoids 38 obstacles that are a certain distance away from the Pheeno. Those 39 sensor limits are shown in `sensor_limits`. 44 if input_args.number ==
"":
48 pheeno_number = str(input_args.number)
51 rospy.init_node(
"pheeno_obstacle_avoidance")
58 saved_time = rospy.get_rostime().secs
65 while not rospy.is_shutdown():
67 current_duration = rospy.get_rostime().secs - saved_time
69 if current_duration <= 10:
70 pheeno.avoid_obstacle(ir_limit, 0, angular_vel)
71 cmd_vel_msg.linear.x = pheeno.linear_velocity
72 cmd_vel_msg.angular.z = pheeno.angular_velocity
76 if angular_vel != pheeno.angular_velocity:
77 angular_vel = pheeno.angular_velocity
79 elif current_duration < 20:
80 pheeno.avoid_obstacle(ir_limit, linear_vel, 0)
81 cmd_vel_msg.linear.x = pheeno.linear_velocity
82 cmd_vel_msg.angular.z = pheeno.angular_velocity
86 saved_time = rospy.get_rostime().secs
87 angular_vel = pheeno.random_turn() * angular_vel
90 pheeno.publish_cmd_vel(cmd_vel_msg)
94 if __name__ ==
"__main__":
98 except rospy.ROSInterruptException:
102 rospy.loginfo(
"Exiting 'pheeno_obstacle_avoidance' node.")