Created
December 4, 2023 14:28
-
-
Save takanotaiga/5d3b5307298446c441d2d64308e20f15 to your computer and use it in GitHub Desktop.
Hello.SIM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rclpy | |
from rclpy.node import Node | |
from std_msgs.msg import Float32 | |
class MinimalPublisher(Node): | |
def __init__(self): | |
super().__init__('minimal_publisher') | |
self.publisher_1 = self.create_publisher(Float32, '/hellosim/motor_1', 1) | |
self.publisher_2 = self.create_publisher(Float32, '/hellosim/motor_2', 1) | |
self.publisher_3 = self.create_publisher(Float32, '/hellosim/motor_3', 1) | |
self.publisher_4 = self.create_publisher(Float32, '/hellosim/motor_4', 1) | |
timer_period = 0.5 # seconds | |
self.timer = self.create_timer(timer_period, self.timer_callback) | |
self.i = 0 | |
def timer_callback(self): | |
msg = Float32() | |
msg.data = 1.0 | |
self.publisher_1.publish(msg) | |
self.publisher_2.publish(msg) | |
msg.data = -1.0 | |
self.publisher_3.publish(msg) | |
self.publisher_4.publish(msg) | |
self.get_logger().info('Publishing: "%s"' % msg.data) | |
self.i += 1 | |
def main(args=None): | |
rclpy.init(args=args) | |
minimal_publisher = MinimalPublisher() | |
rclpy.spin(minimal_publisher) | |
# Destroy the node explicitly | |
# (optional - otherwise it will be done automatically | |
# when the garbage collector destroys the node object) | |
minimal_publisher.destroy_node() | |
rclpy.shutdown() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment