How to write ROS py

$ wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/talker.py
$ chmod +x talker.py

$ rosed beginner_tutorials talker.py

#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import String
   
def talker():
    pub = rospy.Publisher('chatter', String, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
       hello_str = "hello world %s" % rospy.get_time()
       rospy.loginfo(hello_str)
       pub.publish(hello_str)
       rate.sleep()
   
if __name__ == '__main__':
    try:
       talker()
    except rospy.ROSInterruptException:
        pass


from ackermann_msgs.msg import AckermannDriveStamped

pub = rospy.Publisher('/????',AckermannDriveStamped, queue_size=1)
 

ack_msg = AckermannDriveStamped()
ack_msg.header.stamp = rospy.Time.now()
ack_msg.header.frame_id = ''
ack_msg.drive.steering_angle = 0
ack_msg.drive.speed = 1
pub.publish(ack_msg)

Last updated