Error in Actions Quiz

When I run the command

roslaunch actions_quiz action_custom_msg.launch

It gives me the following error and I don’t know how to fix it.

ImportError: cannot import name ‘CustomActionMsg’ from ‘actions_quiz.msg’ (/home/user/catkin_ws/devel/lib/python3/dist-packages/actions_quiz/msg/init.py)
[action_custom_msg-1] process has died [pid 25831, exit code 1, cmd /home/user/catkin_ws/src/actions_quiz/scripts/action_custom_msg.py __name:=action_custom_msg __log:=/home/user/.ros/log/ 909fd734-e611-11ed-8c56-0242c0a85007/action_custom_msg-1.log].
log file: /home/user/.ros/log/909fd734-e611-11ed-8c56-0242c0a85007/action_custom_msg-1*.log

Greetings and thank you.

Hi @JoseMBG44 ,

Please share your python program’s import lines (or the entire program if you wish) as a code-block.

Regards,
Girish

This is the python file. I know it’s not finished yet. I just want to resolve the error when importing CustomActionMsg.

#!/usr/bin/env python

import rospy
import actionlib
from actions_quiz.msg import CustomActionMsg

class ArdoneActionServer:
    def __init__(self):
        # create the action server
        self._as = actionlib.SimpleActionServer(
            '/action_custom_msg_as',
            CustomActionMsg,
            execute_cb=self.execute_callback,
            auto_start=False
        )
        self._as.start()
        rospy.loginfo('Action server started')

    def execute_callback(self, goal):
        # check the goal action
        if goal.goal == "TAKEOFF":
            self.takeoff()
        elif goal.goal == "LAND":
            self.land()
        else:
            rospy.logerr('Invalid action: "{}"'.format(goal.goal))
            self._as.set_aborted()

    def takeoff(self):
        # TODO: Implement takeoff function
        rospy.loginfo('Taking off')
        rate = rospy.Rate(1)
        while not rospy.is_shutdown():
            self._as.publish_feedback(CustomActionMsg(feedback="Taking off"))
            rate.sleep()

    def land(self):
        # TODO: Implement land function
        rospy.loginfo('Landing')
        rate = rospy.Rate(1)
        while not rospy.is_shutdown():
            self._as.publish_feedback(CustomActionMsg(feedback="Landing"))
            rate.sleep()

if __name__ == '__main__':
    rospy.init_node('action_custom_msg')
    server = ArdoneActionServer()
    rospy.spin()

Please check the following, on the same terminal where you are running the program

  • Have you successfully compiled your custom message? Can you find it in rosmsg list?
  • Have you run source ~/catkin_ws/devel/setup.bash on this terminal? You need to run this on every terminal after doing catkin_make successfully.

It still doesn’t work. Help please.

user:~/catkin_ws$ catkin_make
Base path: /home/user/catkin_ws
Source space: /home/user/catkin_ws/src
Build space: /home/user/catkin_ws/build
Devel space: /home/user/catkin_ws/devel
Install space: /home/user/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/user/catkin_ws/build"
####
####
#### Running command: "make -j8 -l8" in "/home/user/catkin_ws/build"
####
[  0%] Built target actionlib_msgs_generate_messages_nodejs
[  0%] Built target _actions_quiz_generate_messages_check_deps_CustomActionMsgGoal
[  0%] Built target std_msgs_generate_messages_nodejs
[  0%] Built target _actions_quiz_generate_messages_check_deps_CustomActionMsgActionResult
[  0%] Built target _actions_quiz_generate_messages_check_deps_CustomActionMsgActionGoal
[  0%] Built target _actions_quiz_generate_messages_check_deps_CustomActionMsgResult
[  0%] Built target _actions_quiz_generate_messages_check_deps_CustomActionMsgAction
[  0%] Built target _actions_quiz_generate_messages_check_deps_CustomActionMsgFeedback
[  0%] Built target actionlib_msgs_generate_messages_py
[  0%] Built target std_msgs_generate_messages_py
[  0%] Built target std_msgs_generate_messages_eus
[  0%] Built target _actions_quiz_generate_messages_check_deps_CustomActionMsgActionFeedback
[  0%] Built target actionlib_msgs_generate_messages_eus
[  0%] Built target actionlib_msgs_generate_messages_cpp
[  0%] Built target std_msgs_generate_messages_cpp
[  0%] Built target actionlib_msgs_generate_messages_lisp
[  0%] Built target std_msgs_generate_messages_lisp
[ 21%] Built target actions_quiz_generate_messages_nodejs
[ 40%] Built target actions_quiz_generate_messages_eus
[ 62%] Built target actions_quiz_generate_messages_py
[ 94%] Built target actions_quiz_generate_messages_lisp
[100%] Built target actions_quiz_generate_messages_cpp
[100%] Built target actions_quiz_generate_messages
user:~/catkin_ws$ source devel/setup.bash
user:~/catkin_ws$ roslaunch actions_quiz action_custom_msg.launch
... logging to /home/user/.ros/log/e73dddae-e920-11ed-bff9-0242c0a85006/roslaunch-2_xterm-4680.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://2_xterm:41343/

SUMMARY
========

PARAMETERS
 * /rosdistro: noetic
 * /rosversion: 1.15.9

NODES
  /
    action_custom_msg (actions_quiz/action_custom_msg.py)

ROS_MASTER_URI=http://2_simulation:11311

process[action_custom_msg-1]: started with pid [4688]
Traceback (most recent call last):
  File "/home/user/catkin_ws/src/actions_quiz/scripts/action_custom_msg.py", line 5, in <module>
    from actions_quiz.msg import CustomActionMsg
ImportError: cannot import name 'CustomActionMsg' from 'actions_quiz.msg' (/home/user/catkin_ws/devel/lib/python3/dist-packages/actions_quiz/msg/__init__.py)
[action_custom_msg-1] process has died [pid 4688, exit code 1, cmd /home/user/catkin_ws/src/actions_quiz/scripts/action_custom_msg.py __name:=action_custom_msg __log:=/home/user/.ros/log/e73dddae-e920-11ed-bff9-0242c0a85006/action_custom_msg-1.log].
log file: /home/user/.ros/log/e73dddae-e920-11ed-bff9-0242c0a85006/action_custom_msg-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done
user:~/catkin_ws$ rosmsg list | grep actions
actions_quiz/CustomActionMsgAction
actions_quiz/CustomActionMsgActionFeedback
actions_quiz/CustomActionMsgActionGoalactions_quiz/CustomActionMsgActionResult
actions_quiz/CustomActionMsgFeedbackactions_quiz/CustomActionMsgGoalactions_quiz/CustomActionMsgResult

Hi @JoseMBG44 ,

Your import line is wrong - hence it did not work and threw compilation error.
You should use the following line instead:

from actions_quiz.msg import (CustomActionMsgAction,
                              CustomActionMsgActionFeedback,
                              CustomActionMsgActionResult)

This should fix your problem. Let me know if it does not.

Regards,
Girish

And should I also change all the CustomActionMsg in the code to CustomActionMsgAction?

Regards.

Hi @JoseMBG44 ,

Yes.

Regards,
Girish

Fixed the problem. Thanks a lot.

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