Skip to content

Commit

Permalink
Added Twist msg publisher
Browse files Browse the repository at this point in the history
working publisher that keeps the turtle rotating.
  • Loading branch information
nhjschulz committed Aug 13, 2024
1 parent fed1684 commit c2b7757
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
5 changes: 4 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
<package format="3">
<name>ros2_turtlesim_teleop_python</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<description>TurtleSim Python Controller</description>
<maintainer email="[email protected]">norbert</maintainer>
<license>MIT</license>

<exec_depend>geometry_msgs</exec_depend>
<exec_depend>rclpy</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
Expand Down
33 changes: 31 additions & 2 deletions ros2_turtlesim_teleop_python/pythonop_turtle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
def main():
print('Hi from ros2_turtlesim_teleop_python.')
import geometry_msgs.msg
import rclpy
from rclpy.node import Node
import geometry_msgs
import rclpy.destroyable

class TurtlePublisher(Node):
def __init__(self):
super().__init__('turtlesim_teleop_python')
self.publisher_ = self.create_publisher(geometry_msgs.msg.Twist, 'turtle1/cmd_vel', 10)
timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0

def timer_callback(self):
msg = geometry_msgs.msg.Twist()
msg.linear.x = 0.0
msg.linear.y = 0.0
msg.linear.z = 1.0
msg.angular = msg.linear

self.publisher_.publish(msg)
self.get_logger().info('Publishing: ' + str(msg))
self.i += 1

def main(args=None):
print('Hi from ros2_turtlesim_teleop_python.')
rclpy.init(args=args)
turtle_publisher = TurtlePublisher()
rclpy.spin(turtle_publisher)
turtle_publisher.destroy_node()
rclpy.shutdown()

if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='norbert',
maintainer='Norbert Schulz',
maintainer_email='[email protected]',
description='TODO: Package description',
description='TurtleSim Python Controller',
license='MIT',
tests_require=['pytest'],
entry_points={
Expand Down

0 comments on commit c2b7757

Please sign in to comment.