Aerial Robotics IITK
  • Introduction
  • Danger Zone
  • Tutorials
    • Workspace Setup
      • Installing Ubuntu
      • Basic Linux Setup
      • Spruce up your space
      • ROS Setup
      • PX4 Setup
        • PX4 Toolchain Setup
      • Ardupilot Setup
      • Installing Ground Control Station
        • QGroundControl
        • Mission Planner
      • ArduPilot Setup on Docker
      • PX4 Setup on Docker
    • How to Write a ROS Package
      • ROS Package
      • Node Handles, Parameters, and Topics
      • Coding Standards
      • Custom mavros message
      • Transformations
      • Conversions
    • Cheatsheets
      • CMakeCheatsheet
      • GitCheatsheet
      • LatexCheatsheet
      • Markdown Cheatsheet
    • Miscellaneous
      • Odroid XU4 Setup
      • Simulation using Offboard Control
        • Enable Offboard Mode in PX4
      • Writing a UDev rule
      • Sensor fusion
    • Reference wiki links
  • Concepts
    • Quaternions
      • Theory
    • Kalman Filters
    • Rotations
    • Path Planning
      • Grassfire Algorithm
      • Dijkstra Algorithm
      • A* Algorithm
      • Probabilistic Roadmap
      • RRT Algorithm
      • Visibility Graph Analysis
    • Lectures
      • Aerial Robotics
      • Avionics
      • Control Systems: Introduction
      • Control Systems: Models
      • Inter IIT Tech Meet 2018
      • Kalman Filters
      • Linux and Git
      • Git Tutorial
      • ROS
      • Rotorcraft
      • Software Training
  • Control System
    • Model Predictive Control
      • System Identification
      • Sample SysId Launch Files
      • Running MPC
        • MPC with Rotors
        • MPC with PX4 Sim
        • MPC with ROS
      • References
    • PID Controller
      • Introduction
      • Basic Theory
  • Estimation
    • Visual-Inertial Odometry
      • Hardware Requirements
      • Visual-Inertial Sensing
      • DIYing a VI-Sensor
    • Setup with VICON
    • Odometry from pose data
  • Computer Vision
    • Intel RealSense D435i setup for ROS Noetic
    • IntelRealSense D435i Calibration
    • Camera Calibration
    • ArUco ROS
  • Machine Learning
    • Datasets
  • Hardware Integration
    • Configuring Radio Telemetry
    • Setting up RTK + GPS
    • Integration of Sensors with PixHawk
      • Connecting Lidar-lite through I2C
    • Connections
    • Setting up Offboard Mission
      • Setting up Companion Computer
        • Raspberry Pi 4B Setup
        • Jetson TX2 Setup
      • Communication Setup
      • Guided mode
    • Miscellaneous
  • Resources
    • Open-source algorithms and resources
    • Courses
      • State Space Modelling of a Multirotor
      • Path Planning Lecture
      • Introduction to AI in Robotics
      • RRT, RRT* and RRT*- Path Planning Algorithms
    • Useful Reading Links
      • Aerial Robotics
      • Books
      • Computer Vision and Image Processing
      • Courses on AI and Robotics
      • Deep Neural Network
      • Dynamics and Controls system
      • Motion Planning
      • Probabilistic Robotics
      • Programming
      • Robotics Hardware
      • Miscellaneous and Awesome
    • Online Purchase websites
  • Competitions
    • Inter-IIT TechMeet 8.0
    • Inter-IIT TechMeet 9.0
    • IMAV 2019, Madrid, Spain
    • Inter-IIT TechMeet 10.0
    • Inter-IIT TechMeet 11.0
Powered by GitBook
On this page
  • Topic naming, node naming, namespacing
  • Parameters

Was this helpful?

  1. Tutorials
  2. How to Write a ROS Package

Node Handles, Parameters, and Topics

How To ROS.

PreviousROS PackageNextCoding Standards

Last updated 5 years ago

Was this helpful?

Topic naming, node naming, namespacing

First, read the overview on the ROS Wiki, as it will clear up a lot of questions about private/public/relative namespaces. Second, never use global namespaces for topic names.

Why namespaces?

Each of our quadrotors runs all its nodes and topics in its own namespace. This makes it easier to see (1) which quadrotor something is running on, and (2) makes it possible to run several quadrotors at the same time. This is absolutely essential for any collaborative missions with the quadrotors, so all nodes have to stick to the namespacing conventions.

ROS topic names:

No global names. This is because they do not resolve properly when you push nodes into namespaces, and does not allow you to run more than one of your node at a time properly. Or use multiple robots on the same master. Basically just creates a world of problems.

Good: odometry, binary_map, cam0/camera_info Bad: /odometry, /binary_map, /helicopter/cam0/camera_info

If you want to use a namespace, prefer to actually namespace the node handle on which the publisher is created.

Node Handles

There are 4 main types of node handles:

  1. Default (public) node handle - nh_ = ros::NodeHandle();

  2. Private node handle - nh_private_ = ros::NodeHandle("~");

  3. Namespaced node handle - nh_aslam_ = ros::NodeHandle("aslam");

  4. Global node handle - nh_global_ = ros::NodeHandle("/"); - you probably shouldn't use this ever.

Generally you will only use the first 2 - you could also use the namespaced node handle for separating out publishers for nodes that have many.

To explain what these do and how they should be used, let's assume your ROS node is named ros_node, in namespace blah, and you are trying to look up the name topic. Here is what they will resolve to using all 3 nodehandles:

  1. /blah/topic

  2. /blah/ros_node/topic

  3. /blah/aslam/topic

  4. /topic

If, instead, your try to resolve /topic, this will skip the namespace of the node and resolve to /topic.

When to use which Node Handle

These are just general guidelines, but when possible, prefer to use the following in each case:

  • Subscribers - usually public node handles.

  • Publishers - usually private node handles for most output/visualization, occasionally necessary to use public for globally-used data (i.e., /odom topic).

  • Parameters - almost always private node handle.

Parameters

If a node (or the underlying libraries) have configurations that can be set at startup, expose them as ROS parameters. Your parameters should be_named_like_this.

It is important to provide reasonable defaults for your params. Prefer to make them member variables in a class, and set them to the correct value in the constructor.

Then you can read new values for them from the parameter file if they have been specified.

Naming