Unexpected error while launching: actions_quiz_server node

Hi,
While working on the Actions Quiz, unit 6. I got to launch succesfully my server node once, it failed because of a typo error. I corrected the mistake, however, when I rebuilded and tried to launch again the node, the following error appears:

I don’t understand why the error is happening. I would be grateful for your help. Thanks

Also, I went to the file that the error points and I got this.
def importlib_load_entry_point(spec, group, name):
dist_name, _, _ = spec.partition(‘==’)
matches = (
entry_point
for entry_point in distribution(dist_name).entry_points
if entry_point.group == group and entry_point.name == name
)
25 return next(matches).load()

globals().setdefault(‘load_entry_point’, importlib_load_entry_point)

if name == ‘main’:
33 sys.argv[0] = re.sub(r’(-script.pyw?|.exe)?

Best regards.

, ‘’, sys.argv[0])
sys.exit(load_entry_point(‘my-action-client==0.0.0’, ‘console_scripts’, ‘action_quiz_server’)())

Best regards.

Hi @w.ronaldo.cd ,

Could you please change the support category from “General Support” to the appropriate “Course Support” category?
I see that you are working with ROS2 Basics in 5 Days course, but I am not sure if your are doing the C++ or the Python version of the course.
So, please change it to either
ROS2 Basics in 5 Days Humble (C++)
(OR)
ROS2 Basics in 5 Days Humble (Python).

Now, coming to your problem,
If your are working on C++ version, please post the CMakeLists.txt file contents as a Code Block.
If your are working on Python version, please post the setup.py file contents as a Code Block.
Also, post your main code (C++ or Python) as a Code Block.

Refer this guide on how to use Fenced Code Blocks in Markdown.

Regards,
Girish

Hi Girish,

Thanks for your response. I am working on Python.
This is the setup.py file

  from setuptools import setup
  import os
  from glob import glob
  
  package_name = 'actions_quiz'
  
  setup(
      name='my_action_client',
      version='0.0.0',
      packages=[package_name],
      data_files=[
          ('share/ament_index/resource_index/packages',
              ['resource/' + package_name]),
          ('share/' + package_name, ['package.xml']),
          (os.path.join('share', package_name), glob('launch/*.launch.py'))
      ],
      install_requires=['setuptools'],
      zip_safe=True,
      maintainer='user',
      maintainer_email='user@todo.todo',
      description='TODO: Package description',
      license='TODO: License declaration',
      tests_require=['pytest'],
      entry_points={
          'console_scripts': [
              'action_quiz_server = actions_quiz.actions_quiz_server:main',
              'action_quiz_client = actions_quiz.actions_quiz_client:main'
          ],
      },
  )

This is my main code:

  import time
  import numpy as np
  
  import rclpy
  from rclpy.action import ActionServer
  from rclpy.node import Node
  from rclpy.executors import MultiThreadedExecutor
  from rclpy.callback_groups import ReentrantCallbackGroup
  from rclpy.qos import ReliabilityPolicy, QoSProfile
  
  from actions_quiz_msg.action import Distance
  from std_msgs.msg import Float64
  from geometry_msgs.msg import Twist
  from nav_msgs.msg import Odometry
  
  
  class ActionQuizServer(Node):
  
      def __init__(self):
          super().__init__('action_quiz_server')
          self.group1 = ReentrantCallbackGroup()
          
          self._action_server = ActionServer(self, 
              Distance, 
              'distance_as', 
              self.execute_callback,
              callback_group=self.group1) 
  
          self.cmd_vel_publisher = self.create_publisher(Twist, 'cmd_vel', 10)
          self.distance_publisher = self.create_publisher(Float64, '/total_distance', 10)
          self.odom_subscriber_ = self.create_subscription(
              Odometry,
              '/odom',
              self.odom_callback,
              QoSProfile(depth=10, reliability=ReliabilityPolicy.RELIABLE),
              callback_group=self.group1)
          
          self.start_pos_x = 0.0
          self.start_pos_y = 0.0
          self.start_pos_set = False
  
          self.current_pos_x = 0.0
          self.current_pos_y = 0.0
  
      def odom_callback(self, msg):
          if self.start_pos_set is False:
              self.start_pos_x = msg.pose.pose.position.x
              self.start_pos_y = msg.pose.pose.position.y
              self.start_pos_set = True
          else:
              self.current_pos_x = msg.pose.pose.position.x
              self.current_pos_y = msg.pose.pose.position.y
      
      def get_distance_traveled(self):
          dist_traveled = np.sqrt((self.current_pos_x - self.start_pos_x)**2 + (self.current_pos_y - self.start_pos_y)**2)
          return dist_traveled
  
      def execute_callback(self, goal_handle):
          cmd_msg = Twist()
          dist_msg = Float64()
  
          self.get_logger().info('Executing goal...')
  
          feedback_msg = Distance.Feedback()
          
          for i in range(1, goal_handle.request.seconds):
              cmd_msg.linear.x = 0.3
              self.cmd_vel_publisher.publish(cmd_msg)
  
              distance_traveled = self.get_distance_traveled()
              feedback_msg.current_dist = distance_traveled
              dist_msg.data = distance_traveled
  
              goal_handle.publish_feedback(feedback_msg)
              self.distance_publisher.publish(dist_msg)
  
              self.get_logger().info('Current distance traveled: "%s" meters' %str(distance_traveled))
  
              time.sleep(1)
              self.get_logger().info('"%s" seconds have passed' %str(i + 1))
  
          goal_handle.succeed()
  
          cmd_msg.linear.x = 0.0
          self.cmd_vel_publisher.publish(cmd_msg)
  
          total_distance = self.get_distance_traveled()
          result = Distance.Result()
          result.status = True
          result.total_dist = total_distance
          self.get_logger().info('The action has finished')
          self.get_logger().info('The robot has traveled: "%s" meters' %str(total_distance))
          return result
  
  def main(args=None):
      rclpy.init(args=args)
  
      action_server_node = ActionQuizServer()
      executor = MultiThreadedExecutor(num_threads=2)
      executor.add_node(action_server_node)
      try:
          executor.spin()
      finally:
          executor.shutdown()
          action_server_node.destroy_node()
  
      rclpy.shutdown()
  
  if __name__ == '__main__':
      main()

Best regards,
Ronaldo

Hi @w.ronaldo.cd ,

Your file contents looks fine to me. Could you post the error messages from your terminal again?
Are they different or the same that you have posted earlier?
Also post those error messages as code block.
Also post your launch file contents.

Regards,
Girish

Hi Girish,
I tried to launch my code again and I got the same error.

user:~/ros2_ws$ ros2 launch actions_quiz actions_quiz_server.launch.py
  [INFO] [launch]: All log files can be found below /home/user/.ros/log/2023-01-27-19-00-13-222176-4_xterm-1316
  [INFO] [launch]: Default logging verbosity is set to INFO
  [INFO] [action_quiz_server-1]: process started with pid [1325]
  [action_quiz_server-1] Traceback (most recent call last):
  [action_quiz_server-1]   File "/home/user/ros2_ws/install/actions_quiz/lib/actions_quiz/action_quiz_server", line 33, in <module>
  [action_quiz_server-1]     sys.exit(load_entry_point('my-action-client==0.0.0', 'console_scripts', 'action_quiz_server')())
  [action_quiz_server-1]   File "/home/user/ros2_ws/install/actions_quiz/lib/actions_quiz/action_quiz_server", line 25, in importlib_load_entry_point
  [action_quiz_server-1]     return next(matches).load()
  [action_quiz_server-1] StopIteration
  [ERROR] [action_quiz_server-1]: process has died [pid 1325, exit code 1, cmd '/home/user/ros2_ws/install/actions_quiz/lib/actions_quiz/action_quiz_server --ros-args'].

Launch files:

actions_quiz_client.launch.py

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='actions_quiz',
            executable='action_quiz_client',
            output='screen'),
    ])

actions_quiz_server.launch.py

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='actions_quiz',
            executable='action_quiz_server',
            output='screen'),
    ])

Hi @w.ronaldo.cd ,

Ok, your launch files are also written correctly.

At this point I just have one suggestion:

  1. Delete the build, install and log directories inside ros2_ws
  2. Build packages again and source:
    cd ~/ros2_ws && colcon build && source install/setup.bash
  3. Now do the ros2 launch ... command.

Let me know if it worked this time for you.

Regards,
Girish

Hi Girish
Still does not work. :frowning:

I ran the code on my personal computer and eventough I don’t have the simulation running, my Action Server worked. I got the following (on my personal computer):

I created the package again and I still have the same problem

Hi @w.ronaldo.cd ,

This problem seems strange.

I think something might have gone wrong in the course environment.

I believe TheConstruct team can help you with this problem as I am out of options.

Regards,
Girish

Hi,

Thank you for replying. Do you know what email should I write about my problem?

Kind regards,
Ronaldo

Hi @w.ronaldo.cd ,

You do not need email. You just need to tag their name. I will do it for you this time.

Regards,
Girish

Hi @albertoezquerro / @bayodesegun ,
Sorry to tag you directly on this issue. Could you please look into this when you get time? Thanks.

Hello @w.ronaldo.cd ,

The problem is in the setup.py file, in line 7. You have this as the name of your package:

name='my_action_client',

but it should be this:

name=package_name,

Remove your current build files, recompile, and it should get fixed:

cd ~/ros2_ws
rm -rf build/ install/ log/
colcon build
source install/setup.bash

I don’t know how you got this part of the file wrong, since it is generated automatically when you create the package. My guess is that you copy/pasted it from another setup.py file. This is NEVER a good idea since errors like this may appear.

Best,

PS: Thanks @girishkumar.kannan for the follow up on the issue.

2 Likes

This was a good find. I usually do not check those lines as those lines are created automatically.

I actually looked for: 1. imports, 2. data_files and 3. entry_points console_scripts.
I am sure I overlooked. My bad.

– Girish

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.