I am implementing a simple roslaunch file but I am getting an exit code 2 status I have pasted the exact log below any idea what would cause this and how I can rectify it.

kshitij@Kshitij:~/catkin_ws$ roslaunch apriltag_ros apriltag.launch 
... logging to /home/kshitij/.ros/log/c7672d6c-479d-11ec-bd02-c56b9aa24743/roslaunch-Kshitij-20782.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt 
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://Kshitij:38583/


* /rosdistro: noetic
* /rosversion: 1.15.13

apriltag_ros (apriltag_ros/tagdetector.py)

auto-starting new master
process[master]: started with pid [20790]

setting /run_id to c7672d6c-479d-11ec-bd02-c56b9aa24743
process[rosout-1]: started with pid [20800]
started core service [/rosout] 
process[apriltag_ros-2]: started with pid [20803]
usage: tagdetector.py [-h] [-f FAMILIES] [-B N] [-t N] [-x SCALE] [-b SIGMA] [-0] [-1] [-2] [-c]
tagdetector.py: error: unrecognized arguments: __name:=apriltag_ros __log:=/home/kshitij/.ros/log/c7672d6c-479d-11ec-bd02-c56b9aa24743/apriltag_ros-2.log
[apriltag_ros-2] process has died [pid 20803, exit code 2, cmd /home/kshitij/catkin_ws/src/apriltag_ros/scripts/tagdetector.py __name:=apriltag_ros __log:=/home/kshitij/.ros/log/c7672d6c-479d-11ec-bd02-c56b9aa24743/apriltag_ros-2.log].
log file: /home/kshitij/.ros/log/c7672d6c-479d-11ec-bd02-c56b9aa24743/apriltag_ros-2*.log

The launch file code is as below

<?xml version = "1.0"?>

    <node name = "apriltag_ros" pkg = "apriltag_ros" type = "tagdetector.py"  output="screen" />

Edit 1: I have added the function that I am using to publish to ROS where the ROS node is initialised and used.

The function I am using to publish the data is as below

def location_publisher():
    ROS Publisher: Publishes X, Y and Yaw values
    pub = rospy.Publisher('apriltag_pose', tag, queue_size=10)
    rospy.init_node('apriltag_ros', anonymous=False)
    msg = tag()
    msg.location.x = z # z in camera frame of reference is the distance from the tag i.e. x in general frame of reference
    msg.location.y = y
    msg.location.theta = yaw
    msg.status.data = status_tag
    msg.tagid.data = tag_id

# Detect AprilTag
parser = ArgumentParser(description='Detect AprilTags from video stream.')
options = parser.parse_args()

detector = apriltagbase.Detector(options, searchpath=apriltagbase._get_dll_path())


    check,frame = video.read()
    if not check:

    # overlay box on AprilTag format of detect_tags can be viewd in apriltag.py line 590.
    result,overlay = apriltagbase.detect_tags(frame, 
                                        camera_params=(565.348501, 565.653872, 326.910261, 226.544390),
    cv2.imshow('April Tag', overlay)

Link to the same question on the ROS Forum: https://answers.ros.org/question/391124/roslaunch-exit-code-2-error/

  • $\begingroup$ we will wait to see what answers you get on ros.org $\endgroup$
    – jsotola
    Nov 18, 2021 at 7:21

2 Answers 2


roslaunch expects you to be launching ROS nodes. And it's passing standard ROS nodes arguments such as the full name and log path. You're seeing the errors in it rejecting arguments __name: __log:

If you want to make this work you should use a script which is robust to receiving these extra arguments. Or wrap it in a script which will discard the extra arguments.

As a simple solution rospy.init_node will process those arguments. And you can access the stripped ones via rospy.myargs http://wiki.ros.org/rospy/Overview/Initialization%20and%20Shutdown

rosrun is a much lower level function that just executes the file from a different path

  • $\begingroup$ This is what I got on my post on answers.ros.org but this does not solve my problem as I am already using rospy.init_node() $\endgroup$
    – NOVA1323
    Nov 19, 2021 at 11:24

The script I have added uses parses arguments defined in apriltagbase.

options = parser.parse_args()

argparse fails for all arguments which are not added here. So need to replace it by

options, unknown = parser.parse_known_args()

to prevent failing due to arguments added automatically by roslaunch.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.