ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
752 stars 913 forks source link

rospy get_param('') behaves differently after rospy.loginfo() #2216

Open reinzor opened 2 years ago

reinzor commented 2 years ago

The rospy.get_param('') behavior is affected by a rospy.loginfo. This is not expected:

$ python -c "import rospy; rospy.init_node('test'); print(rospy.get_param('')); rospy.loginfo(''); print(rospy.get_param(''))"
{'run_id': 'a561b8ca-6c8e-11ec-9979-4737778163b4', 'roslaunch': {'uris': {'host_ws_180018__39993': 'http://ws-180018:39993/'}}, 'rosversion': '1.15.13\n', 'rosdistro': 'noetic\n'}
[INFO][/test][1641212098.262899]: 
{'rosout_disable_topics_generation': {}}

Related to this line. When the get_param_cached call is removed, the result of both print statements is the same.

flixr commented 2 years ago

I'm running in the same issue. This is a regression caused by #1881.

mikepurvis commented 2 years ago

@paulbovbel Are you aware?

StephanHasler commented 2 years ago

Same issue here. I'm using noetic.

flixr commented 2 years ago

My current workaround:

def ros_get_params():
    """
    This is a workaround since rospy.get_param('/') is currently broken.
    See https://github.com/ros/ros_comm/issues/2216
    """
    def build_nested(name, val, d):
        if name.startswith('/'):
            name = name[1:]
        if '/' not in name:
            d[name] = val
        else:
            head, rest = name.split('/', 1)
            if head not in d:
                d[head] = {}
            build_nested(rest, val, d[head])

    ros_params = {}
    for param in rospy.get_param_names():
        pval = rospy.get_param_cached(param)
        build_nested(param, pval, ros_params)
    return ros_params