Node Template
From ChatGPT
#include <ros/ros.h>
int main(int argc, char** argv)
{
// Initialize the ROS node
ros::init(argc, argv, "my_node");
// Create a ROS node handle
ros::NodeHandle nh;
// Add your code here
// Main loop
while (ros::ok())
{
// Add your code here
// Handle ROS callbacks
ros::spinOnce();
}
return 0;
}
In this template:
ros::init()
initializes the ROS node with the given name.ros::NodeHandle
is used to create a handle for interacting with the ROS system.You can add your code and functionality where indicated by the comments.
The main loop
while (ros::ok())
allows the node to continuously run until ROS is shut down.ros::spinOnce()
allows the ROS system to handle any pending callbacks.
Remember to replace "my_node" with the desired name for your ROS node. You can add your own publishers, subscribers, services, and other functionality within the main loop and the indicated code sections.
Make sure to link against the necessary ROS libraries when compiling your node. For example, if you are using catkin
build system, you can include the necessary dependencies in your CMakeLists.txt
file.
Last updated