3 roslib.load_manifest(
'yocs_velocity_smoother')
9 from geometry_msgs.msg
import Twist
10 from nav_msgs.msg
import Odometry
12 Varied translational input for a velocity smoother test. 25 rospy.init_node(
"test_velocity_smoother_input")
26 cmd_vel_publisher = rospy.Publisher(
"~cmd_vel", Twist)
27 odom_publisher = rospy.Publisher(
"~odom", Odometry)
29 param[
'velocity_maximum'] = rospy.get_param(
"~velocity_maximum", 0.50)
30 param[
'ramp_increment'] = rospy.get_param(
"~ramp_increment", 0.02)
31 rospy.loginfo(
"Test Input : ramp increment [%f]",param[
'ramp_increment'])
32 param[
'ramp_decrement'] = rospy.get_param(
"~ramp_decrement", 0.02)
33 rospy.loginfo(
"Test Input : ramp decrement [%f]",param[
'ramp_decrement'])
42 odom.header.frame_id =
"base_link" 43 odom.pose.pose.position.x = 0.0
44 odom.pose.pose.position.y = 0.0
45 odom.pose.pose.position.z = 0.0
46 odom.pose.pose.orientation.x = 0.0
47 odom.pose.pose.orientation.y = 0.0
48 odom.pose.pose.orientation.z = 0.0
49 odom.pose.pose.orientation.w = 1.0
51 odom.pose.covariance[0] = 0.1
52 odom.pose.covariance[7] = 0.1
53 odom.pose.covariance[35] = 0.2
54 odom.pose.covariance[14] = 10.0
55 odom.pose.covariance[21] = 10.0
56 odom.pose.covariance[28] = 10.0
58 odom.twist.twist.linear.x = 0.0
59 odom.twist.twist.linear.y = 0.0
60 odom.twist.twist.linear.z = 0.0
61 odom.twist.twist.angular.x = 0.0
62 odom.twist.twist.angular.y = 0.0
63 odom.twist.twist.angular.z = 0.0
69 timer = rospy.Rate(100)
70 rospy.loginfo(
"Test Input : STATE_RAMP_UP")
71 while not rospy.is_shutdown():
72 if state == STATE_RAMP_UP:
73 cmd_vel.linear.x = cmd_vel.linear.x + param[
'ramp_increment']
74 if cmd_vel.linear.x >= param[
'velocity_maximum']:
75 state = STATE_RAMP_LEVEL
77 rospy.loginfo(
"Test Input : STATE_RAMP_UP -> STATE_RAMP_LEVEL")
78 elif state == STATE_RAMP_LEVEL:
80 state = STATE_RAMP_DOWN
82 rospy.loginfo(
"Test Input : STATE_RAMP_LEVEL -> STATE_RAMP_DOWN")
85 elif state == STATE_RAMP_DOWN:
86 cmd_vel.linear.x = cmd_vel.linear.x - param[
'ramp_decrement']
87 if cmd_vel.linear.x <= 0.0:
88 cmd_vel.linear.x = 0.0
91 rospy.loginfo(
"Test Input : STATE_RAMP_DOWN -> STATE_ZERO")
92 elif state == STATE_ZERO:
95 cmd_vel.linear.x = param[
'velocity_maximum']
97 rospy.loginfo(
"Test Input : STATE_ZERO -> STATE_UP")
100 elif state == STATE_UP:
101 if count > count_max:
103 cmd_vel.linear.x = 0.0
105 rospy.loginfo(
"Test Input : STATE_UP -> STATE_DOWN")
108 elif state == STATE_DOWN:
109 if count > count_max:
113 state = STATE_RAMP_UP
114 cmd_vel.linear.x = 0.0
115 rospy.loginfo(
"Test Input : STATE_DOWN -> STATE_RAMP_UP")
119 elif state == STATE_UP_AGAIN:
120 if count > count_max:
121 state = STATE_NOTHING
124 rospy.loginfo(
"Test Input : STATE_UP_AGAIN -> STATE_NOTHING")
127 elif state == STATE_NOTHING:
128 if count > count_max:
129 state = STATE_RAMP_UP
130 cmd_vel.linear.x = 0.0
133 rospy.loginfo(
"Test Input : STATE_NOTHING -> STATE_RAMP_UP")
137 odom.twist.twist.linear.x = cmd_vel.linear.x
138 cmd_vel_publisher.publish(cmd_vel)
141 odom.twist.twist.linear.x = cmd_vel.linear.x
142 odom.header.stamp = rospy.Time().now()
143 odom_publisher.publish(odom)
146 if __name__ ==
"__main__":