ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

roslaunch exit code 2 error

asked 2021-11-17 06:21:07 -0600

NOVA1323 gravatar image

updated 2021-11-23 11:13:43 -0600

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. I can run it perfectly using rosrun

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/

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/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"?>

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

As per my understanding I should add an extra line in my publisher that is rospy.myargv(argv=sys.argv) but it doesn't seem to work. Please let me know if I am missing something.

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
    rospy.loginfo(msg)
    pub.publish(msg)

Any help is appreciated.

Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2021-11-18 17:52:15 -0600

tfoote gravatar image

updated 2021-11-22 14:22:06 -0600

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 __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.myargshttp://wiki.ros.org/rospy/Overview/In...

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

Edit:

Looking at your snippet you need to move the rospy.init_node to somewhere that it will only be run once. Similarly the lifetime of you publisher should be longer than the function call. It won't have time to establish connections within the callback.

To strip the arguments from your argument parser you need to interact with your argument parser along these lines.

rospy.init_node('apriltag_ros')
parser = argparse.ArgumentParser(prog='PROG')
# Set your argument parser
parser.parse_args(args=rospy.myargv())

This will avoid your crash.

As I mentioned in the comment below. There are many other issues with your below snippet. You need to make sure to pay attention to the lifespan/scope of things that you are creating. Fixing the above will avoid the initially described problem. Which is what I originally answered. But I don't expect your program will function the way you expect. I would strongly recommend going through the beginner python tutorials and after doing that ask a question back here about what you still can't get working. And when you ask make sure to fully capture the problem. As you can see the more details you provide in your question the easier it is for someone to help you.

edit flag offensive delete link more
0

answered 2021-11-29 02:43:49 -0600

NOVA1323 gravatar image

The script I was using used parser from the Apriltag library and could not Parse other arguments given changing the parser to adjust for unknown arguments solves the launch file issue.

This is one way it can be implemented.

options, unknown = parser.parse_known_args()
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-11-17 06:21:07 -0600

Seen: 996 times

Last updated: Nov 29 '21