ROS2 c++ project part 3 calling action server

I’m currently on part 3 of the rosject that’s focused on actions. I was able to build the package with no errors, but I get this when I try to send a goal to the action server. Note: I understand that my code may not be functional, but I can’t decipher this error message in order to figure out where to start debugging. Any advice is appreciated

user:~/ros2_ws$ ros2 action send_goal /odom_action_server ros2_project/action/OdomRecord "{}"
Traceback (most recent call last):
  File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
    return importlib.import_module(module_name, package=pkg_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 556, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1166, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: /home/user/ros2_ws/install/ros2_project/lib/libros2_project__rosidl_generator_c.so: undefined symbol: geometry_msgs__msg__Point32__Sequence__init

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/ros/foxy/bin/ros2", line 11, in <module>
    load_entry_point('ros2cli==0.9.9', 'console_scripts', 'ros2')()
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2action/command/action.py", line 37, in main
    return extension.main(args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2action/verb/send_goal.py", line 54, in main
    return send_goal(args.action_name, args.action_type, args.goal, feedback_callback)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2action/verb/send_goal.py", line 95, in send_goal
    action_client = ActionClient(node, action_module, action_name)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 148, in __init__
    check_for_type_support(action_type)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
    msg_type.__class__.__import_type_support__()
  File "/home/user/ros2_ws/install/ros2_project/lib/python3.8/site-packages/ros2_project/action/_odom_record.py", line 1162, in __import_type_support__
    module = import_type_support('ros2_project')
  File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
    raise UnsupportedTypeSupport(pkg_name)
rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'ros2_project'
Exception ignored in: <function ActionClient.__del__ at 0x7f972d44b040>
Traceback (most recent call last):
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 596, in __del__
    self.destroy()
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 587, in destroy
    if self._client_handle is None:
AttributeError: 'ActionClient' object has no attribute '_client_handle'

Here’s my code:

# scrubbed
1 Like

Cmake:

# scrubbed

package:

# scrubbed

Are you doing the Python or C++ part of the project? Are you familiar with C++?

The error messages are point pointing to rclpy - the Python API. I suggest you go with the Python version if you are not that familiar with C++.

could you elaborate on this? This is for the c++ ros2 course, I don’t recall there being anything python related except for the launch files…

The error messages seem to suggest that your code has been written in Python.

I’ll ask one of our C++ experts (@rzegers) to have a look.

1 Like

Hi @reallen,

my first guess is that there might be something wrong with the command you are executing (ros2 action send_goal /odom_action_server ros2_project/action/OdomRecord "{}") rather than the code itself, but I might be as well wrong.

Regardless let’s start there, confirming that the command is correct.

To recap, the structure of the command is the following:
ros2 action send_goal <action_name> <action_type> <values>

So for confirming that the values are correct please run this command:
ros2 action list -t
Verify that you can find the action that you want to call in the list. Please compare the action name and action type with the ones that you are using (in brackets to the right of each action name is the action type).

Also please post the output here.

Finally please also verify that the structure of the action values is correct.
To do so enter the following command with the action type in your terminal:
ros2 interface show <action_type>
then post the output here.

Cheers,

Roberto

So I’ve made a few changes since I posted this. Originally, I had created my custom action interface in the same package where I wrote my action server (ros2_project). Since then, I created a custom interface package to see if that could fix the error that I was initially having. I’m still running into the same problem when I run a command similar to the one from before.

user:~$ ros2 action list
/record_odom
user:~$ ros2 action list -t
/record_odom [project_action_msgs/action/OdomRecord]
user:~$ ros2 action send_goal /record_odom
--feedback                             project_action_msgs/action/OdomRecord
-f
user:~$ ros2 action send_goal /record_odom project_action_msgs/action/OdomRecord "{}"
Traceback (most recent call last):
  File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
    return importlib.import_module(module_name, package=pkg_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 556, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1166, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: /home/user/ros2_ws/install/project_action_msgs/lib/libproject_action_msgs__rosidl_generator_c.so: undefined symbol: geometry_msgs__msg__Point32__Sequence__init

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/ros/foxy/bin/ros2", line 11, in <module>
    load_entry_point('ros2cli==0.9.9', 'console_scripts', 'ros2')()
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2cli/cli.py", line 67, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2action/command/action.py", line 37, in main
    return extension.main(args=args)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2action/verb/send_goal.py", line 54, in main
    return send_goal(args.action_name, args.action_type, args.goal, feedback_callback)
  File "/opt/ros/foxy/lib/python3.8/site-packages/ros2action/verb/send_goal.py", line 95, in send_goal
    action_client = ActionClient(node, action_module, action_name)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 148, in __init__
    check_for_type_support(action_type)
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
    msg_type.__class__.__import_type_support__()
  File "/home/user/ros2_ws/install/project_action_msgs/lib/python3.8/site-packages/project_action_msgs/action/_odom_record.py", line 1162, in __import_type_support__
    module = import_type_support('project_action_msgs')
  File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
    raise UnsupportedTypeSupport(pkg_name)
rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'project_action_msgs'
Exception ignored in: <function ActionClient.__del__ at 0x7f3fe544ff70>
Traceback (most recent call last):
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 596, in __del__
    self.destroy()
  File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/action/client.py", line 587, in destroy
    if self._client_handle is None:
AttributeError: 'ActionClient' object has no attribute '_client_handle'
user:~$

And this is the custom interface:

user:~$ ros2 interface show project_action_msgs/action/OdomRecord

---
geometry_msgs/Point32[] list_of_odoms
---
float32 current_total

Thanks for the prompt reply, btw!

Hello @reallen, thanks for posting those command outputs.
Now let us introspect this line here:
ImportError: /home/user/ros2_ws/install/project_action_msgs/lib/libproject_action_msgs__rosidl_generator_c.so: undefined symbol: geometry_msgs__msg__Point32__Sequence__init

From my understanding “undefined symbol” generally means that the symbol shown can’t be found in any of the linked libraries.

Please verify that you have declared the dependency inside package.xml:

<depend>geometry_msgs</depend>

And in CMakeLists.txt:

find_package(geometry_msgs REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  <write_msg_file_here>
  DEPENDENCIES geometry_msgs)

Also make sure you export the message runtime dependency:

ament_export_dependencies(rosidl_default_runtime)

Finally you also need to include the header of Point32.msg in your source code file:

#include "geometry_msgs/msg/point32.hpp"

Could you please confirm and verify with your code?

Regards,

Roberto

Hi Roberto, so it seems that I was missing the

DEPENDENCIES geometry_msgs

in the “rosidl_generate_interfaces” function. I don’t think it was mentioned in the action servers chapter of the course that you needed to add the dependencies of the action interface file if you’re not using the standard messages. But I might be mistaken.

And same case for the function:

ament_export_dependencies(rosidl_default_runtime)

(Could you explain what ^ does?)
I added those two lines to the CMake and everything works now. Thanks!

1 Like

Hi @reallen,

I am glad you got it solved!

The rosidl_default_runtime package is needed for code generation of ROS messages at runtime. Specifically it gathers dependencies for all runtime related dependencies of ROS interface files (.idl). Your packages depends on geometry_msgs in order to generate its own message type. You use ament_export_dependencies(rosidl_default_runtime) so that ros2cli package (the one that you use for sending ros2 commands via the command line) knows where the point32.hpp header files are too. So basically it is needed for resolving dependencies.

I will check the course to see if this needs to be added.

Cheers,

Roberto