Built in mechanism to prevent multiple instances of same Node
This question was already asked here on ROS answers but no answer was given. Only a suggestion in the comments.
I am building a mobile robot, and using GPIO on the Jetson Nano for the wheel encoder, motor drivers etc. For the wheel encoders, I have a node that maintains the total ticks of both wheel encoders, and publishes those ticks on different topics; left_wheel_encoder and right_wheel_encoder.
Wheel encoders work by incrementing total ticks, which is kept in two variables (one left and one right) within the WheelEncoderNode class.
It's too easy to launch two WheelEncoderNode nodes that are 1 min apart and will end up publishing different total tick values; obv. the latter one will have a lower count.
Is there a built in mechanism to prevent me from doing that? I mean other than launch files for all packages, which is a requirement.
But I am thinking of maybe a lock file that the WheelEncoderNode creates and checks if it exists, similar to how daemons run. But hoping there's a built-in mechanism in ros for this?