ROS2 Publisher Node (Python) - Ros-ros2 Typing CST Test
Loading…
ROS2 Publisher Node (Python) — Ros-ros2 Code
A simple ROS2 publisher node that sends messages to a topic.
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(String, 'topic', 10)
self.timer = self.create_timer(1.0, self.timer_callback)
def timer_callback(self):
msg = String()
msg.data = 'Hello ROS2'
self.publisher_.publish(msg)
self.get_logger().info('Publishing: %s' % msg.data)
def main(args=None):
rclpy.init(args=args)
node = MinimalPublisher()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()Ros-ros2 Language Guide
ROS (Robot Operating System) and ROS2 are open-source frameworks for robot software development. They provide libraries, tools, and conventions to simplify programming, communication, and control in robotics, supporting modularity, real-time systems, and hardware abstraction.
Primary Use Cases
- ▸Robot perception, navigation, and control
- ▸Multi-robot coordination and communication
- ▸Simulation and testing of robotic systems
- ▸Integration with sensors, actuators, and middleware
- ▸Development of autonomous systems and AI robotics
Notable Features
- ▸Node-based modular architecture
- ▸Communication via topics, services, and actions
- ▸Hardware abstraction for diverse robot platforms
- ▸Simulation and visualization integration
- ▸Cross-platform support in ROS2 (Linux, Windows, macOS)
Origin & Creator
ROS was created by the Stanford AI Lab and Willow Garage around 2007-2009. ROS2 development started by Open Robotics in 2014 to address ROS1 limitations in real-time, security, and cross-platform support.
Industrial Note
ROS2 is increasingly adopted in industrial automation, autonomous vehicles, and robotics middleware due to its support for real-time deterministic systems and secure communication.