0

I have a roslaunch file, in which I am including an xacro file:

<param if="$(arg load_robot_description)" name="$(arg robot_description)" command="xacro 'path/to/xacro' robot_parameters:='$(arg robot_parameters)'"/>

I now want to read some data from a json file (yaml is also possible, but json would be better), so I can pass it like shown above to the xacro and use it like

<origin xyz="$(arg robot_parameters.pose.xyz)" rpy="0 0 0"/>

in the xacro. The passing of the argument works, because if I use

<arg name="robot_parameters" default="{}"/>

it shows me that the arg gets passed to the xacro (and I get an error because it cannot access pose.xyz). Now I want to read the data from the json file and I tried multiple approaches (listed below), but none of them worked. First I tried command in arg tag

<arg name="robot_parameters" command="rosparam load $(find my_package)/robot_definition.json robot_parameters"/>

Second I tried using rosparam

<rosparam command="load" file="$(find my_package)/robot_definition.yaml" />

whereas the first marker in the yaml was called 'robot_parameters'. Third I tried using a python script:

load_json.py:

#!/usr/bin/env python3

import rospy
import json
import sys

def load_json_to_rosparam(param_name, json_file_path):
    with open(json_file_path, 'r') as f:
        json_data = json.load(f)

    rospy.set_param(param_name, json_data)

if __name__ == '__main__':
    if len(sys.argv) != 3:
        sys.exit(1)

    param_name = sys.argv[1]
    json_file_path = sys.argv[2]

    rospy.init_node('load_json_to_rosparam')
    load_json_to_rosparam(param_name, json_file_path)

In the launch file:

<node name="load_json_to_rosparam_node" pkg="my_package" type="load_json.py"
    args="robot_parameters $(find my_package)/robot-definition.json" output="screen" />

All of them resulted in the error "launchfile requires 'robot_parameters' to be set". What is the correct way to do this? I cannot image that it is that complicated.

wittn
  • 298
  • 5
  • 16

0 Answers0