Skip to content

Instantly share code, notes, and snippets.

@sk413025
Last active September 2, 2021 09:34
Show Gist options
  • Save sk413025/7166cd699f9cb95cc89084d625c570f7 to your computer and use it in GitHub Desktop.
Save sk413025/7166cd699f9cb95cc89084d625c570f7 to your computer and use it in GitHub Desktop.
example of basic rclpy
import rclpy
import time
import numpy as np
from rclpy.node import Node
from std_msgs.msg import Float32
def main():
rclpy.init()
node = Node('my_node')
rv_publisher = node.create_publisher(Float32, 'my_rv', 1)
msg_rv = Float32()
while(True):
val = np.random.normal(1)
print("Checking: ", type(val))
msg_rv.data = val
rv_publisher.publish(msg_rv)
time.sleep(0.1)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
@sk413025
Copy link
Author

sk413025 commented Sep 2, 2021

source /opt/ros/foxy/setup.sh
python ros2_ex.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment