Python

build publisher

cd src/my_py_pkg/my_py_pkg
touch hw_status_publisher.py
chmod +x hw_status_publisher.py

now you can use the custom msg!

from hexa_robot_interfaces.msg import HardwareStatus

let CODE to know the path. file-preference-setting-typing(python path)-python> Auto Complete: Extra Paths>edit

let CODE to know the path. file-preference-setting-typing(python path)-python> Auto Complete: Extra Paths>edit

In package.xml, add to use the package

<depend>hexa_robot_interfaces</depend>

write node

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
 
from hexa_robot_interfaces.msg import HardwareStatus

class HardwareStatusPublisherNode(Node): # MODIFY NAME
    def __init__(self):
        super().__init__("hardware_status_publisher") # MODIFY NAME
        self.hw_status_publisher_ = self.create_publisher(HardwareStatus, "hardware_status", 10)
        self.timer_ = self.create_timer(1.0, self.publish_hw_status)
        self.get_logger().info("Hardware status publisher has been started.")

    def publish_hw_status(self):
        msg = HardwareStatus()
        msg.temperature = 45
        msg.are_motors_ready = True
        msg.debug_message = "Nothing special here"
        self.hw_status_publisher_.publish(msg)
 
 
def main(args=None):
    rclpy.init(args=args)
    node = HardwareStatusPublisherNode() # MODIFY NAME
    rclpy.spin(node)
    rclpy.shutdown()
 
 
if __name__ == "__main__":
    main()

edit setup.py. add line below.

"hw_status_publisher = my_py_pkg.hw_status_publisher:main"

build colcon

colcon build --packages-select my_py_pkg --symlink-install

check if it works

ros2 node list
ros2 topic list
ros2 topic info /hardware_status
ros2 topic echo /hardware_status # make error! we haven’t sourced. Do, source install/setup.bash