Can't Import Action Messages

asked 2021-02-04 17:05:09 -0500

BesterJester gravatar image

updated 2021-02-05 17:30:49 -0500

I have two ROS action files I am working with. The first one, which works, is Timer.action which looks like:

duration time_to_wait
---
duration time_elapsed
uint32 updates_sent
---
duration time_elapsed
duration time_remaining

The second action file, which I can't get to work, looks exactly the same (I made them the same for trouble shooting purposes). Both are in the package's action file.

I create the server to use the Timer.action message in a file called simple_action_server.py. When I run the file using the command rosrun basics simple_action_server.py, it runs without issue. It is able to successfully import everything shown below:

#! /usr/bin/env python
import rospy
import time
import actionlib
from basics.msg import TimerAction, TimerGoal, TimerResult

However, the server that uses the Talk.action message always comes back with an import error. The code for this server is in a file named pyttsx_server.py and the import part of the code is:

#! /usr/bin/env python
import pyttsx
import rospy
import threading, time
import actionlib
from basics.msg import TalkAction, TalkGoal, TalkResult

When I run the command rosrun basics pyttsx_server.py, I always get the error:

Traceback (most recent call last):
  File "/home/jesse/cougarbot_ws/src/basics/src/pyttsx_server.py", line 7, in <module>
    from basics.msg import TimerAction, TimerGoal, TimerResult
ImportError: cannot import name TalkAction

In my basics package, here is applicable sections of the CMakeLists.txt file:

cmake_minimum_required(VERSION 3.0.2)
project(basics)

find_package(catkin REQUIRED COMPONENTS
  rospy
  actionlib_msgs
)

add_action_files(
  DIRECTORY action
  FILES Timer.action
  FILES Talk.action
)

generate_messages(
  DEPENDENCIES
  actionlib_msgs
  std_msgs
)

catkin_package(
 CATKIN_DEPENDS
 actionlib_msgs
)

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

In my basics package, here are the applicable sections of my package.xml file:

<buildtool_depend>catkin</buildtool_depend>
<build_depend>rospy</build_depend>
<build_depend>actionlib_msgs</build_depend>
<build_export_depend>rospy</build_export_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>actionlib_msgs</exec_depend>

I can't figure out what the difference is between these two actions that causes one to fail and the other to work. Any advice will be greatly appreciated.

Linux 5.3.0-62-generic #56 18.04.1-Ubuntu

edit retag flag offensive close merge delete

Comments

1

Have you compiled your workspace?

jayess gravatar image jayess  ( 2021-02-04 17:48:32 -0500 )edit
1

Be sure to re-source the setup file as well after you rebuild the package.

tryan gravatar image tryan  ( 2021-02-04 21:17:05 -0500 )edit

I've done both those things. I tried them again, as seen below, with the same result.

06:07~/cougarbot_ws$ catkin_make
Base path: /home/jesse/cougarbot_ws
Source space: /home/jesse/cougarbot_ws/src
Build space: /home/jesse/cougarbot_ws/build
Devel space: /home/jesse/cougarbot_ws/devel
Install space: /home/jesse/cougarbot_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/jesse/cougarbot_ws/build"
####
####
#### Running command: "make -j4 -l4" in "/home/jesse/cougarbot_ws/build"
####
06:07~/cougarbot_ws$ source devel/setup.bash 
06:07~/cougarbot_ws$ rosrun basics pyttsx_server.py
Traceback (most recent call last):
  File "/home/jesse/cougarbot_ws/src/basics/src/pyttsx_server.py", line 7, in <module>
    from basics.msg import TalkAction, TalkGoal, TalkResult
ImportError: cannot import name TalkAction
BesterJester gravatar image BesterJester  ( 2021-02-05 08:10:02 -0500 )edit
1

Please, post CMakeLists.txt and package.xml. Also, can you confirm whether all the message files actually exist in the devel space?

tryan gravatar image tryan  ( 2021-02-05 10:05:43 -0500 )edit
2

I checked the devel/include/basics folder, and found that catkin_make generated the Timer files but not the Talk files. I made the rookie mistake of not adding FILES Talk.action to the add_action_files function in the package's CMakeLists.txt. I posted the working CMakeLists.txt and package.xml above. Thanks for your help, and teaching me the valuable lesson of paying attention to the CMakeLists.txt file any time I add a message, service, or action.

BesterJester gravatar image BesterJester  ( 2021-02-05 18:00:18 -0500 )edit
1

Glad you got it worked out!

tryan gravatar image tryan  ( 2021-02-05 19:31:16 -0500 )edit
1

@BesterJester you may want to write your solution up as an answer to help others who may encounter this same issue later

jayess gravatar image jayess  ( 2021-02-05 19:43:53 -0500 )edit