replace string in ros2 launch command xacro

asked 2023-05-17 04:10:31 -0500

muttidrhummer gravatar image

Hi all, i need to replace a string in an urdf after the xacro command is executed. In the launcher, I load the xacro like this:

    robot_description_content_1 = Command(
    [
        PathJoinSubstitution([FindExecutable(name="xacro")]),
        " ",
        PathJoinSubstitution([FindPackageShare(description_package), "urdf", description_file]),
        " ","safety_limits:=",safety_limits,
        " ","safety_pos_margin:=",safety_pos_margin,
        " ","safety_k_position:=",safety_k_position,
        " ","name:=","ur1",
        " ","ur_type:=",ur_type,
        " ","prefix:=","sweepee_1/",
        " ","prefix_rc:=","sweepee_1",
        " ","simulation_controllers:=",initial_joint_controllers_1,
        " ","use_fake_hardware:=",use_fake_hardware,
        " ","sim_gazebo:=",sim_gazebo,
        " ","sim_ignition:=",sim_ignition,
    ]
)
robot_description_1  = {"robot_description": robot_description_content_1}

After loading it , I need to replace a keyword with another.
The problem is that the command is not yet a string and I don't know how to act on it. I would use the xacro package directly but I have a lot of PathJoinSubstitution, and I cant deal with them in the xacro.
Is there a way to do this ?
Thanks

edit retag flag offensive close merge delete

Comments

Do you need to change this keyword in the launcher? Maybe you could add a parameter callback to dynamically change the node parameters. Perhaps use of the OpaqueFunction can help if you have to do this change in the launcher?

ljaniec gravatar image ljaniec  ( 2023-05-17 05:32:57 -0500 )edit

I will take a look at the OpaqueFunction, but the problem I'm having is that I need to put

<fdir1 ignition:expressed_in='${prefix}base_link_sweepee'>1 -1 0</fdir1>

in my urdf, and xacro wont allow "ignition:", I wanted to substitute it later.

muttidrhummer gravatar image muttidrhummer  ( 2023-05-17 05:42:47 -0500 )edit

Take a look at xacro block parameters if you're planning on customizing the URDF robot description anyway

danzimmerman gravatar image danzimmerman  ( 2023-05-20 13:41:33 -0500 )edit