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

[ros2run]: Process exited with failure 1

asked 2022-10-07 04:34:23 -0500

LucB gravatar image

updated 2022-10-07 04:41:04 -0500

I try to write a simple programm with ros2.

when i run ros2 run test_ur_controller first_moveit_node i get following output.

Traceback (most recent call last):
File "/home/.../workspace/moveit_test/install/test_ur_controller/lib/test_ur_controller/first_moveit_node", line 33, in <module>
sys.exit(load_entry_point('test-ur-controller==0.0.0', 'console_scripts', 'first_moveit_node')()) 
File "/home/.../workspace/moveit_test/install/test_ur_controller/lib/python3.10/site-packages/test_ur_controller/first_moveit_node.py", line 13, in main
node = test_moveit_node()
File "/home/.../workspace/moveit_test/install/test_ur_controller/lib/python3.10/site-packages/test_ur_controller/first_moveit_node.py", line 8, in __init__
super().__init__("first_moveit_node")
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
[ros2run]: Process exited with failure 1

My file first_moveit_node.py looks like this

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node

class test_moveit_node():

    def __init__(self):
        super().__init__("first_moveit_node")
        self.get_logger().info("Hello moveit")

def main(args=None):
    rclpy.init(args=args) 
    node = test_moveit_node()
    rclpy.spin(node) 
    rclpy.shutdown()

In my setup.py file i added:

entry_points={
    'console_scripts': [
        "first_moveit_node = test_ur_controller.first_moveit_node:main"
    ],
},

I already build my workspace colcon build which was successful. Furthermore i source ~/workspace/moveit_test/install/setup.bash afterwards.

Where is my mistake?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-10-07 05:28:58 -0500

ravijoshi gravatar image

The class must inherits from (or is a subclass of) Node. You are missing it! Please see a complete working example below:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import rclpy
from rclpy.node import Node


class TestMoveitNode(Node):
    def __init__(self):
        super().__init__("first_moveit_node")
        self.get_logger().info("Hello moveit")


def main(args=None):
    rclpy.init(args=args)
    node = TestMoveitNode()
    rclpy.spin(node)
    rclpy.shutdown()


if __name__ == "__main__":
    main()

This is how I run it:

$ ros2 run  examples_rclpy_minimal_publisher first_moveit_node 
[INFO] [1665138307.033597919] [first_moveit_node]: Hello moveit

Please feel free to look at the documentation.

edit flag offensive delete link more

Comments

1

Thanks. This worked.

At the Documentation for Moveit2 i can only find a code example for C++. All the examples with the python interface are for ros1. Could you suggest me any tutorial with a python example?

LucB gravatar image LucB  ( 2022-10-07 07:01:37 -0500 )edit
1

I am glad you made it work. By the way, when you are getting started with ROS 2, I recommend going through ROS 2 tutorials instead of MoveIt tutorials. Therefore, please feel free to look at the ROS2 documentation titled "Writing a simple publisher and subscriber (Python)".

ravijoshi gravatar image ravijoshi  ( 2022-10-07 22:24:30 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-10-07 04:34:23 -0500

Seen: 1,053 times

Last updated: Oct 07 '22