Can't Import Action Messages
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
Have you compiled your workspace?
Be sure to re-source the setup file as well after you rebuild the package.
I've done both those things. I tried them again, as seen below, with the same result.
Please, post
CMakeLists.txt
andpackage.xml
. Also, can you confirm whether all the message files actually exist in thedevel
space?I checked the
devel/include/basics
folder, and found thatcatkin_make
generated theTimer
files but not theTalk
files. I made the rookie mistake of not addingFILES Talk.action
to theadd_action_files
function in the package'sCMakeLists.txt
. I posted the workingCMakeLists.txt
andpackage.xml
above. Thanks for your help, and teaching me the valuable lesson of paying attention to theCMakeLists.txt
file any time I add a message, service, or action.Glad you got it worked out!
@BesterJester you may want to write your solution up as an answer to help others who may encounter this same issue later