- `resource`: holds files that do not need executable permissions like config, launch files, data files etc.
- python executables **NEED executable permissions**, so they need to placed in `dummy_test`
setup.py: so we can create exportable modules (along with ament_python_install_package(${PROJECT_NAME})). It’s NOT used for creating python nodes
importrclpyfromrclpy.nodeimportNodefromstd_msgs.msgimportStringclassMinimalPublisher(Node):def__init__(self):super().__init__('minimal_publisher')self.publisher_=self.create_publisher(String,'topic',10)timer_period=0.5# seconds
self.timer=self.create_timer(timer_period,self.timer_callback)self.i=0deftimer_callback(self):msg=String()msg.data='Hello World: %d'%self.iself.publisher_.publish(msg)self.get_logger().info('Publishing: "%s"'%msg.data)self.i+=1defmain(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()
-DCMAKE_BUILD_TYPE=RelWithDebInfo: This sets the CMake variable CMAKE_BUILD_TYPE to RelWithDebInfo, meaning “Release with Debug Info.”. Despite the existence of the debugging symbols, below can still happen with optimization:
Lines can be merged or removed
Variables can vanish
Stepping can feel “jumpy”
use a pure Debug build (no optimization) or something like -Og (for GCC) or -O1 -g (for Clang) for real debug build
-DCMAKE_EXPORT_COMPILE_COMMANDS=1: Tells CMake to generate a compile_commands.json file in your build directory. This JSON file lists all compiler invocations for your project, which is extremely useful for tools like clangd, code analyzers, and IDEs that need to know your include paths and compiler flags.
--cmake-force-configure This is not a standard CMake flag; it’s a colcon (ROS 2 build tool) argument. It forces CMake to re-run its configuration step for all packages, even if CMake thinks nothing has changed.
Custom Messages
You can define constants in a .msg for its field values
There’s an open design effort (and PR #685 in rosidl) to add proper enum support to the underlying IDL, but it isn’t released yet. Until then, you must either wrap or validate in C++ if you want real enforcement. You can do msg.code = 42; and nobody stops you. So we need to define a enum class: