我正在实现一个简单的rectify文件,但我得到了一个退出代码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/
发布于 2021-11-18 15:00:16
输出量
用法: tagdetector.py -h -B N -x量表-0 -2
显示,tagdetector.py是一个需要使用特定参数调用的脚本。首先,您应该确保,如果脚本是一个rosnode,以确保通过rosnode启动它像这样是正确的。其次,看看发射文件,它展示了如何向节点添加参数。
因此,您需要将上述参数添加到启动文件中,方法是
args="-h"到节点启动项。
更新
您添加的脚本使用apriltagbase中定义的解析参数。
apriltagbase.add_arguments(parser)
options = parser.parse_args()对于这里没有添加的所有参数,argparse解析都会失败。所以你需要用
options, unknown = parser.parse_known_args()以防止因roslaunch自动添加的参数而失败。
https://stackoverflow.com/questions/70015342
复制相似问题