rover
/cmd_vel
/odom
cmd_vel
odom
Twist
motor_control
subs = rospy.Subscriber("/odom", Odometry, odom_callback) def odom_callback(msg): x_position = msg.pose.pose.position.x
def scan_callback(self, msg): indices = list(range(350, 360)) + list(range(0, 11)) relevant_ranges = [msg.ranges[i] for i in indices] valid_ranges = [r for r in relevant_ranges if msg.range_min < r < msg.range_max] if valid_ranges: self.average_distance = sum(valid_ranges) / len(valid_ranges) def main(): rospy.init_node('scan_subscriber', anonymous=True) rospy.Subscriber("/scan", LaserScan, scan_callback) rospy.spin()
$ roscore # open a new tab $ roslanch cosi119_src pubsubexample.launch # open a new tab $ rostopic list $ rostopic echo counter -n 5
# shell commands $ roscd samples $ chmod +x scripts/topic_subscriber.py $ rosrun samples topic_subscriber.py