3 import rospy, math, random
4 from geometry_msgs.msg
import Twist, Pose
5 from nav_msgs.msg
import Odometry
13 if rospy.has_param(
"pos_lb"):
14 pos_lb = rospy.get_param(
"pos_lb")
19 if rospy.has_param(
"pos_ub"):
20 pos_ub = rospy.get_param(
"pos_ub")
31 if rospy.has_param(
"vel_y"):
32 vel_y = rospy.get_param(
"vel_y")
34 vel_y = random.uniform(vel_min, vel_max)
37 if base_pose_ground_truth.pose.pose.position.y >= pos_ub:
38 Twist_msg.linear.y = -vel_y
39 if base_pose_ground_truth.pose.pose.position.y <= pos_lb:
40 Twist_msg.linear.y = vel_y
45 rospy.init_node(
"Mover")
47 pub = rospy.Publisher(
'cmd_vel', Twist, queue_size=10)
48 sub = rospy.Subscriber(
'base_pose_ground_truth', Odometry, callback_base_pose_ground_truth)
49 start_t = rospy.get_time()
52 if rospy.has_param(
"vel_y"):
53 vel_y = rospy.get_param(
"vel_y")
55 vel_y = random.uniform(vel_min, vel_max)
56 Twist_msg.linear.y = float(random.choice([
'-1',
'1'])) * vel_y
59 while not rospy.is_shutdown():
60 pub.publish(Twist_msg)
64 if __name__ ==
'__main__':
67 except rospy.ROSInterruptException:
def callback_base_pose_ground_truth(base_pose_ground_truth)