generated from LCAS/ros2_pkg_template
-
Notifications
You must be signed in to change notification settings - Fork 14
/
mover_basic.py
38 lines (27 loc) · 923 Bytes
/
mover_basic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import Twist
class MoverBasic(Node):
def __init__(self):
super().__init__('mover_basic')
self.publisher_ = self.create_publisher(Twist, 'cmd_vel', 10)
timer_period = 2.0 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0
def timer_callback(self):
msg = Twist()
msg.linear.x = 0.1
self.publisher_.publish(msg)
self.get_logger().info('Publishing: "{0}"'.format(msg))
self.i += 1
def main(args=None):
rclpy.init(args=args)
mover_basic = MoverBasic()
rclpy.spin(mover_basic)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
mover_basic.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()