jsk-ros-pkg / jsk_roseus

ROS EusLisp Client
http://wiki.ros.org/roseus/Tutorials
16 stars 56 forks source link

Allow to recursively set alists with string keys in ros::set-param #710

Closed Affonso-Gui closed 2 years ago

Affonso-Gui commented 2 years ago

Allows to recursively set values organized in alists at ros::set-param.

# test.yaml
that:
  test:
    a: 1
    b:
      - 1
      - 2
      - 3
(ros::roseus "test")
(ros::get-param "/that")
;; (("test" ("a" . 1) ("b" 1 2 3)))

(ros::set-param "/this" (ros::get-param "/that"))

(ros::get-param "/this")
;; (("test" ("a" . 1) ("b" 1 2 3)))

Needs discussion & testing.

Partially related to https://github.com/jsk-ros-pkg/jsk_roseus/issues/709

k-okada commented 2 years ago

if this feature is supported by roscpp/rospy, we'd better to support in roseus

Affonso-Gui commented 2 years ago

Yes, this is supported in both rospy and roscpp:

# test.py
rospy.init_node("py")

rospy.get_param("/that")
# {'test': {'a': 1, 'b': [1, 2, 3]}}

rospy.set_param("/this", rospy.get_param("/that"))

rospy.get_param("/this")
# {'test': {'a': 1, 'b': [1, 2, 3]}}
// test.cpp
#include <ros/ros.h>

int main(int argc, char **argv)
{
  ros::init(argc, argv, "cpp");
  ros::NodeHandle n;

  XmlRpc::XmlRpcValue val;
  n.getParam("/that", val);

  n.setParam("/another", val);

}
$ rosparam get this
test:
  a: 1
  b: [1, 2, 3]

$ rosparam get that
test:
  a: 1
  b: [1, 2, 3]

$ rosparam get another
test:
  a: 1
  b: [1, 2, 3]
Affonso-Gui commented 2 years ago

Actually, roseus does support recursive ros::set-param through alists, it is only not able to interpret string names, which happen to be the format returned by ros::get-param.

I have adjusted the code to accept string params as well, and added test code.

Affonso-Gui commented 2 years ago

Found another problem:

irteusgl$ (ros::set-param "test" '(((a . 1) (b . 2))))
[ERROR] [1652371517.860218315] [${node}]: ROSEUS_SET_PARAM: EusValueToXmlRpc: assuming symbol
(a . 1)
t

This corresponds to a list of dictionaries, as in the following:

test:
  - {a: 1, b: 2}

This is because in https://github.com/jsk-ros-pkg/jsk_roseus/blob/master/roseus/roseus.cpp#L1282 an alist is defined as a cons with a cons car. A list of dictionaries meets this criteria, but does not have a key element, thus leading to the error.

Added tests & fixed.

@Kanazawanaoaki