Reputation: 79
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. It works perfectly when used as a node via rosrun.
PC@PC :~/catkin_ws$ roslaunch apriltag_ros apriltag.launch
... logging to /home/pc/.ros/log/c7672d6c-479d-11ec-bd02-c56b9aa24743/roslaunch-PC-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://PC:38583/
SUMMARY
========
PARAMETERS
* /rosdistro: noetic
* /rosversion: 1.15.13
NODES
/
apriltag_ros (apriltag_ros/tagdetector.py)
auto-starting new master
process[master]: started with pid [20790]
ROS_MASTER_URI=http://localhost:11311
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/pc/.ros/log/c7672d6c-479d-11ec-bd02-c56b9aa24743/apriltag_ros-2.log
[apriltag_ros-2] process has died [pid 20803, exit code 2, cmd /home/pc/catkin_ws/src/apriltag_ros/scripts/tagdetector.py __name:=apriltag_ros __log:=/home/pc/.ros/log/c7672d6c-479d-11ec-bd02-c56b9aa24743/apriltag_ros-2.log].
log file: /home/pc/.ros/log/c7672d6c-479d-11ec-bd02-c56b9aa24743/apriltag_ros-2*.log
The launch file code is as below
<?xml version = "1.0"?>
<launch>
<node name = "apriltag_ros" pkg = "apriltag_ros" type = "tagdetector.py" output="screen" />
</launch>
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
# Import Libraries
from argparse import ArgumentParser
import sys
import cv2
import apriltagbase
import numpy as np
import math
import rospy
from apriltag_ros.msg import tag
def location_publisher():
"""
ROS Publisher: Publishes X, Y and Yaw values
"""
# rospy.myargv(argv=sys.argv)
pub = rospy.Publisher('apriltag_pose', tag, queue_size=10)
rospy.init_node('apriltag_ros')
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
rospy.loginfo(msg)
pub.publish(msg)
# Detect AprilTag
parser = ArgumentParser(description='Detect AprilTags from video stream.')
apriltagbase.add_arguments(parser)
options = parser.parse_args()
detector = apriltagbase.Detector(options, searchpath=apriltagbase._get_dll_path())
while(video.isOpened()):
check,frame = video.read()
if not check:
break
# overlay box on AprilTag format of detect_tags can be viewd in apriltag.py line 590.
result,overlay = apriltagbase.detect_tags(frame,
detector,
camera_params=(565.348501, 565.653872, 326.910261, 226.544390),
tag_size=0.1688,
vizualization=3,
verbose=3,
annotation=True
)
cv2.imshow('April Tag', overlay)
Edit 2: Removed Full code only open source code is now shown
Link to the same question on the ROS Forum: https://answers.ros.org/question/391124/roslaunch-exit-code-2-error/
Upvotes: 2
Views: 3282
Reputation: 11389
The output
usage: tagdetector.py [-h] [-f FAMILIES] [-B N] [-t N] [-x SCALE] [-b SIGMA] [-0] [-1] [-2] [-c]
shows, that tagdetector.py is a script which needs to be called with some specific parameters. First of all you should make sure, if the script is a rosnode to ensure launching it via roslaunch like this is correct. Secondly, have a look at the launch documentation which shows how to add arguments to the node.
So you need to add some of the mentioned parameters to your launchfile by adding
args="-h"
to the node launch entry.
Update
The script you've added uses parses arguments defined in apriltagbase
.
apriltagbase.add_arguments(parser)
options = parser.parse_args()
argparse fails for all arguments which are not added here. So you need to replace it by
options, unknown = parser.parse_known_args()
to prevent failing due to arguments added automatically by roslaunch.
Upvotes: 4