0

我正在实现一个简单的 roslaunch 文件,但我得到了一个退出代码 2 状态我已将确切的日志粘贴在任何想法会导致此问题以及如何纠正它的下方。当通过 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

启动文件代码如下

<?xml version = "1.0"?>

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

编辑 1:我添加了用于发布到 ROS 的功能,其中 ROS 节点被初始化和使用。

我用来发布数据的功能如下

# 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)
    

编辑 2:删除了完整代码,现在只显示开源代码

链接到 ROS 论坛上的相同问题:https ://answers.ros.org/question/391124/roslaunch-exit-code-2-error/

4

1 回答 1

1

输出

用法:tagdetector.py [-h] [-f FAMILIES] [-BN] [-t N] [-x SCALE] [-b SIGMA] [-0] [-1] [-2] [-c]

显示,tagdetector.py是一个脚本,需要使用一些特定参数调用。首先,您应该确保脚本是否是 rosnode,以确保像这样通过 roslaunch 启动它是正确的。其次,查看启动文档,其中显示了如何向节点添加参数。

因此,您需要通过添加将一些提到的参数添加到您的启动文件中

args="-h"

到节点启动条目。

更新

您添加的脚本使用解析在apriltagbase.

apriltagbase.add_arguments(parser)
options = parser.parse_args()

对于此处未添加的所有参数,argparse失败。因此,您需要将其替换为

options, unknown = parser.parse_known_args()

防止由于 roslaunch 自动添加的参数而失败。

于 2021-11-18T15:00:16.983 回答