Skip to content

Commit

Permalink
Merge pull request #80 from Caltech-AMBER/configure-ros-params-yaml
Browse files Browse the repository at this point in the history
Configure Additional Declared ROS Parameters in YAML File
  • Loading branch information
alberthli authored Jul 23, 2024
2 parents 627f0ea + 3997b2a commit cab333e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
7 changes: 7 additions & 0 deletions obelisk/cpp/zoo/include/position_setpoint_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PositionSetpointController : public obelisk::ObeliskController<obelisk_con
PositionSetpointController(const std::string& name)
: obelisk::ObeliskController<obelisk_control_msgs::msg::PositionSetpoint,
obelisk_estimator_msgs::msg::EstimatedState>(name) {
// example of params_path
std::string file_string = this->get_parameter("params_path").as_string();
std::string obk_root = std::getenv("OBELISK_ROOT");
std::filesystem::path file_path(obk_root);
Expand All @@ -28,6 +29,12 @@ class PositionSetpointController : public obelisk::ObeliskController<obelisk_con
std::string contents;
params_file >> contents;
amplitude_ = std::stof(contents);

// example of setting other configurable params in the node
this->declare_parameter<std::string>("test_param", "default_value");
std::string test_param_value;
this->get_parameter("test_param", test_param_value);
RCLCPP_INFO_STREAM(this->get_logger(), "test_param: " << test_param_value);
}

protected:
Expand Down
8 changes: 4 additions & 4 deletions obelisk/python/obelisk_py/core/utils/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ def get_parameters_dict(node_settings: Dict) -> Dict:
parameters_dict = (
{"callback_group_settings": callback_group_settings} if callback_group_settings is not None else {}
)
if "params_path" in node_settings:
parameters_dict["params_path"] = node_settings["params_path"]
if "params" in node_settings:
parameters_dict.update(node_settings["params"])
parameters_dict.update(pub_settings_dict)
parameters_dict.update(sub_settings_dict)
parameters_dict.update(timer_settings_dict)
Expand Down Expand Up @@ -189,10 +193,6 @@ def _single_component_launch_actions(node_settings: Dict, suffix: Optional[int]
package = node_settings["pkg"]
executable = node_settings["executable"]
parameters_dict = get_parameters_dict(node_settings)

if "params_path" in node_settings:
parameters_dict["params_path"] = node_settings["params_path"]

launch_actions = []
component_node = LifecycleNode(
namespace="",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ExamplePositionSetpointController(ObeliskController):
def __init__(self, node_name: str = "example_position_setpoint_controller") -> None:
"""Initialize the example position setpoint controller."""
super().__init__(node_name)
self.declare_parameter("test_param", "default_value")
self.get_logger().info(f"test_param: {self.get_parameter('test_param').get_parameter_value().string_value}")

def on_configure(self, state: LifecycleState) -> TransitionCallbackReturn:
"""Configure the controller."""
Expand Down
2 changes: 2 additions & 0 deletions obelisk_ws/src/obelisk_ros/config/dummy_cpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ onboard:
executable: example_position_setpoint_controller
params_path: /obelisk_ws/src/obelisk_ros/config/dummy_params.txt
# callback_groups:
params:
test_param: value_configured_in_yaml
publishers:
- ros_parameter: pub_ctrl_setting
# key: pub1
Expand Down
2 changes: 2 additions & 0 deletions obelisk_ws/src/obelisk_ros/config/dummy_py.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ onboard:
- pkg: obelisk_control_py
executable: example_position_setpoint_controller
# callback_groups:
params:
test_param: value_configured_in_yaml
publishers:
- ros_parameter: pub_ctrl_setting
topic: /obelisk/dummy/ctrl
Expand Down

0 comments on commit cab333e

Please sign in to comment.