ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

Rosparam load without overriding

asked 2014-06-13 12:09:55 -0500

crpizarr gravatar image

Is there a way to load a .yaml file without overriding parameters? I have two independent .launch files that depend on the same .yaml file storing the configuration of the package, but one section of the package (corresponding to a one .launch file) might change the parameters (without dumping into the .yaml file), and the other section needs to get the newest parameters, which in this case would be those in the parameter server, not in the .yaml file.

Thanks in advance

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-06-13 12:13:21 -0500

ahendrix gravatar image

I don't believe you can do this with rosparam.

Instead, you should architect your launch files so that this isn't a problem. Perhaps you could create a third launch file just for loading parameters at startup?

edit flag offensive delete link more
0

answered 2014-10-06 12:22:40 -0500

romay gravatar image

updated 2014-10-06 16:29:07 -0500

I ran into the same issue and ended up creating this script:

#!/bin/bash
# $0 is the script name, $1 id the first ARG, $2 is second...

if [ "$2" = "" ]
then
  echo "Usage: $0 <filename> <namespace>"
else
  dump_command="rosparam dump"
  load_command="rosparam load"

  FILE="$1"  
  NAMESPACE="$2"
  IS_NAMESPACE=$(rosparam list | /bin/egrep "$NAMESPACE")

  if [ -z "$IS_NAMESPACE" ];
  then
    echo "No previous Namespace found, simply loading new parameters"
    command="$load_command $FILE $NAMESPACE"
    eval $command
  else           

    #Dumps the current parameters in the server
    command="$dump_command dump_tmp.txt $NAMESPACE"
    eval $command

    #Temporarly loads the new parameters
    command="$load_command $FILE $NAMESPACE"
    eval $command

    #Dumps the new parameters
    command="$dump_command load_tmp.txt $NAMESPACE"
    eval $command

    #Appends both files
    cat dump_tmp.txt >> load_tmp.txt

    #Loads all the new parameters
    command="$load_command load_tmp.txt $NAMESPACE"
    eval $command

    #Remove temporary files
    rm load_tmp.txt
    rm dump_tmp.txt
  fi
fi

I called this script file "rosparam_append" and it takes as arguments the new .yaml file to append and the namespace (if there's no namespace, the simple rosparam load command is executed)

Example:

rosparam_append [path/to/your].yaml /[your_namespace]

you can use this script in your launch file (from this answer):

<node name    = "rosparam_append_node" 
      pkg     = "your-package-name"
      type    = "rosparam_append"
      args    = "$(find your-package-name)/path/to/your.yaml /your/namespace"/>

remember to give executable permissions to the script with:

chmod 755 rosparam_append

hope it helps

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-06-13 12:09:55 -0500

Seen: 1,173 times

Last updated: Oct 06 '14