ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to make custom action?

asked 2017-10-28 00:07:44 -0500

rozoalex gravatar image

updated 2022-01-22 16:16:37 -0500

Evgeny gravatar image

Console output from compilation:

-- Generating .msg files for action turtlebot3_console_controller/Motor 
/home/rozoalex/ros_catkin_ws/src/turtlebot3_console_controller/action/Motor.action
File "/home/rozoalex/ros_catkin_ws/src/turtlebot3_console_controller/action/Motor.action", line 6
float64 angle
            ^
SyntaxError: invalid syntax
CMake Error at /opt/ros/indigo/share/catkin/cmake/safe_execute_process.cmake:11 (message):

execute_process(/home/rozoalex/ros_catkin_ws/build/catkin_generated/env_cached.sh
"/usr/bin/python"
"/home/rozoalex/ros_catkin_ws/src/turtlebot3_console_controller/action/Motor.action"
"-o"
"/home/rozoalex/ros_catkin_ws/devel/share/turtlebot3_console_controller/msg")
returned error code 1
Call Stack (most recent call first):
/opt/ros/indigo/share/actionlib_msgs/cmake/actionlib_msgs-extras.cmake:67 (safe_execute_process)
turtlebot3_console_controller/CMakeLists.txt:63 (add_action_files)


-- Configuring incomplete, errors occurred!
See also "/home/rozoalex/ros_catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/rozoalex/ros_catkin_ws/build/CMakeFiles/CMakeError.log".
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed

When I tried to make my own action, I got this. It says I had a syntax error, which I dont think there is.

Here is my Motor.action file ->

# This is an action definition file, which has three parts: the goal
# the result, and the feedback.
# Part 1: the goal.
#
# The angle in degree the robot to turn, sent by client main
float64 angle
---
# Part 2: the result, sent by action server unpon completion
#
# How much time used
duration time_elapsed
# How many updates thrown in total
uint32 updates_n
---
# Part 3: the feedback,to be sent periodically by server
#
# The amount of time elapsed from the start
duration time_elapsed

Thanks!

edit retag flag offensive close merge delete

Comments

I can't see anything you've posted. Can you edit your question?

l4ncelot gravatar image l4ncelot  ( 2017-10-28 02:39:38 -0500 )edit
1

@rozoalex: don't post images to show us text.

Copy-paste the content of the files into your question text, select it and press the Preformatted Text button (the one with 101010 on it).

gvdhoorn gravatar image gvdhoorn  ( 2017-10-28 05:34:12 -0500 )edit

Thanks! just edited it

rozoalex gravatar image rozoalex  ( 2017-10-28 09:33:04 -0500 )edit

Can you post your CMakeLists.txt file? I really can't see what the problem is, your .action file looks fine to me. Also try to rebuild your project removing build and devel directories.

l4ncelot gravatar image l4ncelot  ( 2017-10-30 03:12:03 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-12-22 13:49:58 -0500

Hi @rozoalex,

The error is "probably" on your CMakeLists.txt, but since it wasn't provided, I'll show you the steps to make custom action from zero (which can be useful for more people), as shown in this video.

Since the name of your package is turtlebot3_console_controller and the action name is Motor.action, we are going to use the same names for simplicity.

1. Create the Catkin Workspace:

mkdir ~/catkin_ws/src/ -p
cd ~/catkin_ws/src/
catkin_init_workspace

2. Create your package named turtlebot3_console_controller that depends on the packages actionlib_msgs and std_msgs:

cd ~/catkin_ws/src/
catkin_create_pkg turtlebot3_console_controller actionlib_msgs std_msgs

3. Create the Motor.action on turtlebot3_console_controller/action:

cd ~/catkin_ws/src/
mkdir -p turtlebot3_console_controller/action
touch turtlebot3_console_controller/action/Motor.action

4. Add to Motor.action the content provided on the question:

# This is an action definition file, which has three parts: the goal
# the result, and the feedback.
# Part 1: the goal.
#
# The angle in degree the robot to turn, sent by client main
float64 angle
---
# Part 2: the result, sent by action server unpon completion
#
# How much time used
duration time_elapsed
# How many updates thrown in total
uint32 updates_n
---
# Part 3: the feedback,to be sent periodically by server
#
# The amount of time elapsed from the start
duration time_elapsed

5. Change add_action_files and generate_messages from turtlebot3_console_controller/CMakeLists.txt to be able to compile the action file. At the end, the CMakeLists.txt will be like we have below:

cmake_minimum_required(VERSION 2.8.3)
project(turtlebot3_console_controller)

find_package(catkin REQUIRED COMPONENTS
  actionlib_msgs
  std_msgs
)

add_action_files(
   FILES
   Motor.action
)

generate_messages(
   DEPENDENCIES
   actionlib_msgs#   std_msgs
)

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES turtlebot3_console_controller
#  CATKIN_DEPENDS actionlib_msgs std_msgs
#  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

6. Compile your package:

cd ~/catkin_ws/src/
catkin_make

Ok, now your custom action should be compiled.

To confirm it was compiled, you can create a test file named node.py that just imports your custom action by following the steps below:

7. Create your test file named node.py:

cd ~/catkin_ws/src/
touch turtlebot3_console_controller/src/node.py

8. Add the content below to node.py:

#! /usr/bin/env python

from turtlebot3_console_controller.msg import MotorGoal, MotorResult, MotorFeedback

print 'Ok, it worked!!!'

9. Run your node.py to confirm your custom action was compiled without any problem.

rosrun turtlebot3_console_controller node.py

After running node.py you should seee the message "Ok, it worked!!!".

In the video mentioned at the beginning we just follow the steps described here.

Hope it helps.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-10-28 00:07:44 -0500

Seen: 2,770 times

Last updated: Dec 22 '17