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

Revision history [back]

click to hide/show revision 1
initial version

Looking at the repo and your own comment it seems you might not be loading the parameters in this node / not running both nodes at the same time?

Given the file a_location.yaml containing:

foo:
  bar: [0.194717, -0.592676, 0.042564]

The python code to set a generic parameter in rospy should be:


#! /usr/bin/env python

import yaml
import rospy
import rospkg


def load_parameters():
    rospack = rospkg.RosPack()
    path_loc = rospack.get_path("a_pkg") + "/config/a_location.yaml"
    with open(path_loc, 'r') as doc:
        loc = yaml.load(doc)

    x_foo_bar = loc["foo"]["bar"][0]
    y_foo_bar = loc["foo"]["bar"][1]
    z_foo_bar = loc["foo"]["bar"][2]

    rospy.set_param("location", {'x': x_foo_bar, 'y': y_foo_bar, 'z': z_foo_bar})

    # do something


if __name__ == '__main__':
    rospy.init_node('my_node', anonymous=True)
    load_parameters()

Looking at the repo and your own comment it seems you might not be loading the parameters in this node / not running both nodes at the same time?

Given the file a_location.yaml containing:

foo:
  bar: [0.194717, -0.592676, 0.042564]

The python code to set a generic parameter in rospy should be:

 #! /usr/bin/env python

import yaml
import rospy
import rospkg


def load_parameters():
    rospack = rospkg.RosPack()
    path_loc = rospack.get_path("a_pkg") + "/config/a_location.yaml"
    with open(path_loc, 'r') as doc:
        loc = yaml.load(doc)

    x_foo_bar = loc["foo"]["bar"][0]
    y_foo_bar = loc["foo"]["bar"][1]
    z_foo_bar = loc["foo"]["bar"][2]

    rospy.set_param("location", {'x': x_foo_bar, 'y': y_foo_bar, 'z': z_foo_bar})

    # do something


if __name__ == '__main__':
    rospy.init_node('my_node', anonymous=True)
    load_parameters()

EDIT: let's redo the example for vesc.yaml

vesc:
  max_rpm_acceleration: 0.123
#! /usr/bin/env python

import yaml
import rospy
import rospkg


def load_parameters():
    rospack = rospkg.RosPack()
    path_loc = rospack.get_path("boat_pid_controller") + "/config/vesc.yaml"
    with open(path_loc, 'r') as doc:
        parameters_vesc = yaml.load(doc)

    max_rpm_accel = parameters_vesc["vesc"]["max_rpm_acceleration"]

    rospy.set_param("max_rpm_acceleration", {max_rpm_accel})


if __name__ == '__main__':
    rospy.init_node('my_node', anonymous=True)
    load_parameters()

    # now that the parameters are loaded you can use them
    p = InterpolateThrottle()
    rospy.spin()

Looking at the repo and your own comment it seems you might not be loading the parameters in this node / not running both nodes at the same time?

Given the file a_location.yaml containing:

foo:
  bar: [0.194717, -0.592676, 0.042564]

The python code to set a generic parameter in rospy should be:

#! /usr/bin/env python

import yaml
import rospy
import rospkg


def load_parameters():
    rospack = rospkg.RosPack()
    path_loc = rospack.get_path("a_pkg") + "/config/a_location.yaml"
    with open(path_loc, 'r') as doc:
        loc = yaml.load(doc)

    x_foo_bar = loc["foo"]["bar"][0]
    y_foo_bar = loc["foo"]["bar"][1]
    z_foo_bar = loc["foo"]["bar"][2]

    rospy.set_param("location", {'x': x_foo_bar, 'y': y_foo_bar, 'z': z_foo_bar})

    # do something


if __name__ == '__main__':
    rospy.init_node('my_node', anonymous=True)
    load_parameters()

EDIT: let's redo the example for vesc.yaml

vesc:
  max_rpm_acceleration: 0.123
#! /usr/bin/env python

import yaml
import rospy
import rospkg


def load_parameters():
    rospack = rospkg.RosPack()
    path_loc = rospack.get_path("boat_pid_controller") + "/config/vesc.yaml"
    with open(path_loc, 'r') as doc:
        parameters_vesc = yaml.load(doc)

    max_rpm_accel = parameters_vesc["vesc"]["max_rpm_acceleration"]

    rospy.set_param("max_rpm_acceleration", {max_rpm_accel})
max_rpm_accel)


if __name__ == '__main__':
    rospy.init_node('my_node', anonymous=True)
    load_parameters()

    # now that the parameters are loaded you can use them
    p = InterpolateThrottle()
    rospy.spin()