Skip to content

Publishing commands with python

ldemk edited this page Apr 9, 2019 · 1 revision
  1. Create new_package

  2. Create a launch file

<launch>
    <!-- My Package launch file -->
    <node pkg="new_package" type="simpli_pub.py" name="topic_publisherroscd"  output="screen">
    </node>
</launch>
  1. Create a simply_pub.py file
#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist 

msg = Twist()
rospy.init_node('topic_publisher')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
rate = rospy.Rate(2)
msg.linear.x = 2
msg.linear.y = 0
msg.angular.z = 2


while not rospy.is_shutdown(): 
  pub.publish(msg)
  rate.sleep()
Clone this wiki locally