Skip to content

Instantly share code, notes, and snippets.

@eborghi10
Last active May 2, 2020 19:06
Show Gist options
  • Save eborghi10/a936935dc86aa4556f4adffccda8fd3d to your computer and use it in GitHub Desktop.
Save eborghi10/a936935dc86aa4556f4adffccda8fd3d to your computer and use it in GitHub Desktop.
Nodo de ejemplo para la clase de Robótica del año 2020 (Introducción a ROS)
<launch>
<node name="mi_nodo_utn" pkg="mi_nuevo_paquete" type="mi_nodo.py" />
<include file="$(find ca_gazebo)/launch/create_empty_world.launch"/>
</launch>
#! /usr/bin/env python
import rospy
from nav_msgs.msg import Odometry
from geometry_msgs.msg import Twist, Vector3
class MiNodo():
def __init__(self):
self.x = 0.0
rospy.init_node('mi_nodo')
rospy.Subscriber("/create1/odom", Odometry, self.callback)
self.pub = rospy.Publisher('/create1/cmd_vel', Twist, queue_size=10)
r = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
vel = Twist()
if(self.x < 0):
vel.linear.x = 0.1 # m/s
vel.angular = Vector3(0, 0, 0)
else:
vel.linear.x = 0
vel.angular.z = 0.5 # rad/s
self.pub.publish(vel)
r.sleep()
def callback(self, data):
self.x = data.pose.pose.position.x
if __name__ == "__main__":
mi_nodo = MiNodo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment