ros / actionlib

Provides a standardized interface for interfacing with preemptable tasks. Examples of this include moving the base to a target location, performing a laser scan and returning the resulting point cloud, detecting the handle of a door, etc.
http://www.ros.org/wiki/actionlib
96 stars 155 forks source link

GoalStatus.to_string(0) in action_client.py result the wrong key attribute #209

Open tutorgaming opened 1 year ago

tutorgaming commented 1 year ago

while I've been working with custom action client I found that in function to_string (in "action_client.py")

https://github.com/ros/actionlib/blob/noetic-devel/actionlib/src/actionlib/action_client.py#L64

def get_name_of_constant(C, n):
    for k, v in C.__dict__.items():
        if isinstance(v, int) and v == n:
            return k
    return "NO_SUCH_STATE_%d" % n

to be used in this definition in line 92

GoalStatus.to_string = classmethod(get_name_of_constant)
CommState.to_string = classmethod(get_name_of_constant)
TerminalState.to_string = classmethod(get_name_of_constant)

If I run the following code with python3,

> python3
> import action_client
> action_client.GoalStatus.to_string(0) 
'_has_header'   # THE RESULT

I got the "_has_header" as the result instead of "PENDING"

So, the suggestion might be putting the condition of the dict 's key not to start with an underscore ("_") would solve this problem and get the CONSTANT "PENDING" as the key in string type (that we're asking for)


ROS1 Noetic Ubuntu 20.04