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

Can you use constants in action files?

asked 2020-08-06 16:00:35 -0500

prithupareek gravatar image

I am trying to define a constant in an action file, but for some reason its not working. Is this even possible?

Here is what my action file looks like:

uint8 ROS_CONTROLLED=0
uint8 RANDOM_MOVEMENT=1
# Goal
geometry_msgs/Pose actorPose
string actorName
uint8 actorType # 0 = ros controlled, 1 = random movement
---
# Result
bool spawnedSuccesfully
string errorCode
---
# Feedback
edit retag flag offensive close merge delete

Comments

1

In what way does it not work? At first glance it seems correct.

pcoenen gravatar image pcoenen  ( 2020-08-07 01:52:34 -0500 )edit

Well, as you told in the wiki, you can declare and assign constant in msgs types so I assume that can be done in action msgs too. This is because when catkin generate their bindings it is generating the necessary msgs types for the action.

Weasfas gravatar image Weasfas  ( 2020-08-07 05:25:21 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2020-08-07 10:58:29 -0500

prithupareek gravatar image

Thank you for your help. I was able to figure out the answer. I was trying to publish to the goal topic of the action server using rospub from the command line, but it appears that the constants only compile when publishing to the goal from a c++ or python file. I was able to get it to work from there.

You would have to do something like this:

goal.actorType = goal.ROS_CONTROLLED
edit flag offensive delete link more

Comments

Note it is slightly preferrable to use the static form MyActionGoal::ROS_CONTROLLED

Rufus gravatar image Rufus  ( 2021-07-20 05:54:25 -0500 )edit
1

answered 2020-09-21 04:43:29 -0500

Combinacijus gravatar image

Yes you can:

# MyAction.action
# Goal constants
uint8 AAAAAAAAAAAAAAAAAAAAAAAAAA = 42
---
# Result constants
uint8 BBBBBBBBBBBBBBBBBBBBBBBBBB = 42
---
# Feedback constants
uint8 CCCCCCCCCCCCCCCCCCCCCCCCCC = 42

Build it To access each one :

# my_script.py
from my_robot.msg import MyActionGoal, MyActionFeedback, MyActionResult

print(MyActionGoal.AAAAAAAAAAAAAAAAAAAAAAAAAA)
print(MyActionFeedback.CCCCCCCCCCCCCCCCCCCCCCCCCC)
print(MyActionResult.BBBBBBBBBBBBBBBBBBBBBBBBBB)

EXTRA tip to check if it's defined:

# my_script.py
from my_robot.msg import MyActionGoal, MyActionFeedback, MyActionResult

print(MyActionGoal.__dict__.keys())
print(MyActionFeedback.__dict__.keys())
print(MyActionResult.__dict__.keys())

You'll get something like this:

['AAAAAAAAAAAAAAAAAAAAAAAAAA', 'deserialize_numpy', '_type', 'deserialize', '_has_header', '_slot_types', 'serialize', '_full_text',
'__module__', '_md5sum', '_get_types', '__slots__', '__doc__', 'serialize_numpy', '__init__']
['deserialize_numpy', '_type', 'deserialize', '_has_header', '_slot_types', 'serialize', '_full_text', '__module__', '_md5sum', '_get
_types', '__slots__', '__doc__', 'CCCCCCCCCCCCCCCCCCCCCCCCCC', 'serialize_numpy', '__init__']
['deserialize_numpy', '_type', 'deserialize', '_has_header', '_slot_types', 'serialize', '_full_text', '__module__', 'BBBBBBBBBBBBBBB
BBBBBBBBBBB', '_md5sum', '_get_types', '__slots__', '__doc__', 'serialize_numpy', '__init__']
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-08-06 16:00:35 -0500

Seen: 660 times

Last updated: Sep 21 '20