Repository Summary

Checkout URI https://github.com/ForteFibre/parameter_expression.git
VCS Type git
VCS Version main
Last Updated 2025-07-16
Dev Status DEVELOPED
Released UNRELEASED
Tags No category tags.
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Packages

Name Version
parameter_expression 0.0.1

README

parameter_expression

A ROS 2 package that allows using mathematical expressions in dynamic parameters using the muParser library.

Overview

The parameter_expression package provides a C++ class that enables ROS 2 nodes to use mathematical expressions as parameter values. Instead of static numeric values, you can use expressions like "sin(0.5) * 2 + 1" which will be evaluated dynamically when the parameter is set.

Features

  • Dynamic Expression Evaluation: Parameters can be set as mathematical expressions that are evaluated in real-time
  • Mathematical Functions: Supports common mathematical functions like sin, cos, tan, atan2, etc (powered by muParser).
  • Type Flexibility: Automatically handles different parameter types (int, double, string expressions)
  • Error Handling: Provides error messages for invalid expressions

Dependencies

  • rclcpp: ROS 2 C++ client library
  • muParser: Mathematical expression parser library

Usage

Basic Usage

Include the header in your ROS 2 node:

#include <parameter_expression/parameter_expression.hpp>

Also, ensure you have the necessary dependencies in your package.xml and CMakeLists.txt:

<depend>parameter_expression</depend>

find_package(parameter_expression REQUIRED)

target_link_libraries(
  your_node
  parameter_expression::parameter_expression
)

Create a parameter expression in your node:

class MyNode : public rclcpp::Node
{
public:
  MyNode() : Node("my_node")
  {
    // Create a parameter expression with default value 0.0
    expression_param_ = std::make_shared<parameter_expression::ParameterExpression>(*this, "my_expression", 0.0);
  }

  void some_function()
  {
    // Get the current evaluated value
    double value = expression_param_->get();
    RCLCPP_INFO(this->get_logger(), "Expression value: %f", value);
  }

private:
  parameter_expression::ParameterExpression::SharedPtr expression_param_;
};

Setting Parameters

You can set the parameter using various methods:

Via Command Line

ros2 param set /my_node my_expression "sin(3.14159/2) * 100"

Via Launch File or parameter YAML file

<launch>
  <node pkg="your_package" exec="your_node" name="my_node">
    <param name="my_expression" value="2 * _pi * 0.5" />
  </node>
</launch>

Advanced Usage

Custom Parameter Descriptor

rcl_interfaces::msg::ParameterDescriptor descriptor;
descriptor.description = "A mathematical expression for calculation";
descriptor.additional_constraints = "Must be a valid mathematical expression";

auto expression_param = std::make_shared<parameter_expression::ParameterExpression>(
  *this, "advanced_expression", 1.0, descriptor);

File truncated at 100 lines see the full file

Repository Summary

Checkout URI https://github.com/ForteFibre/parameter_expression.git
VCS Type git
VCS Version main
Last Updated 2025-07-16
Dev Status DEVELOPED
Released UNRELEASED
Tags No category tags.
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Packages

Name Version
parameter_expression 0.0.1

README

parameter_expression

A ROS 2 package that allows using mathematical expressions in dynamic parameters using the muParser library.

Overview

The parameter_expression package provides a C++ class that enables ROS 2 nodes to use mathematical expressions as parameter values. Instead of static numeric values, you can use expressions like "sin(0.5) * 2 + 1" which will be evaluated dynamically when the parameter is set.

Features

  • Dynamic Expression Evaluation: Parameters can be set as mathematical expressions that are evaluated in real-time
  • Mathematical Functions: Supports common mathematical functions like sin, cos, tan, atan2, etc (powered by muParser).
  • Type Flexibility: Automatically handles different parameter types (int, double, string expressions)
  • Error Handling: Provides error messages for invalid expressions

Dependencies

  • rclcpp: ROS 2 C++ client library
  • muParser: Mathematical expression parser library

Usage

Basic Usage

Include the header in your ROS 2 node:

#include <parameter_expression/parameter_expression.hpp>

Also, ensure you have the necessary dependencies in your package.xml and CMakeLists.txt:

<depend>parameter_expression</depend>

find_package(parameter_expression REQUIRED)

target_link_libraries(
  your_node
  parameter_expression::parameter_expression
)

Create a parameter expression in your node:

class MyNode : public rclcpp::Node
{
public:
  MyNode() : Node("my_node")
  {
    // Create a parameter expression with default value 0.0
    expression_param_ = std::make_shared<parameter_expression::ParameterExpression>(*this, "my_expression", 0.0);
  }

  void some_function()
  {
    // Get the current evaluated value
    double value = expression_param_->get();
    RCLCPP_INFO(this->get_logger(), "Expression value: %f", value);
  }

private:
  parameter_expression::ParameterExpression::SharedPtr expression_param_;
};

Setting Parameters

You can set the parameter using various methods:

Via Command Line

ros2 param set /my_node my_expression "sin(3.14159/2) * 100"

Via Launch File or parameter YAML file

<launch>
  <node pkg="your_package" exec="your_node" name="my_node">
    <param name="my_expression" value="2 * _pi * 0.5" />
  </node>
</launch>

Advanced Usage

Custom Parameter Descriptor

rcl_interfaces::msg::ParameterDescriptor descriptor;
descriptor.description = "A mathematical expression for calculation";
descriptor.additional_constraints = "Must be a valid mathematical expression";

auto expression_param = std::make_shared<parameter_expression::ParameterExpression>(
  *this, "advanced_expression", 1.0, descriptor);

File truncated at 100 lines see the full file

Repo symbol

parameter_expression repository

Repository Summary

Checkout URI https://github.com/ForteFibre/parameter_expression.git
VCS Type git
VCS Version main
Last Updated 2025-07-16
Dev Status DEVELOPED
Released UNRELEASED
Tags No category tags.
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Packages

Name Version
parameter_expression 0.0.1

README

parameter_expression

A ROS 2 package that allows using mathematical expressions in dynamic parameters using the muParser library.

Overview

The parameter_expression package provides a C++ class that enables ROS 2 nodes to use mathematical expressions as parameter values. Instead of static numeric values, you can use expressions like "sin(0.5) * 2 + 1" which will be evaluated dynamically when the parameter is set.

Features

  • Dynamic Expression Evaluation: Parameters can be set as mathematical expressions that are evaluated in real-time
  • Mathematical Functions: Supports common mathematical functions like sin, cos, tan, atan2, etc (powered by muParser).
  • Type Flexibility: Automatically handles different parameter types (int, double, string expressions)
  • Error Handling: Provides error messages for invalid expressions

Dependencies

  • rclcpp: ROS 2 C++ client library
  • muParser: Mathematical expression parser library

Usage

Basic Usage

Include the header in your ROS 2 node:

#include <parameter_expression/parameter_expression.hpp>

Also, ensure you have the necessary dependencies in your package.xml and CMakeLists.txt:

<depend>parameter_expression</depend>

find_package(parameter_expression REQUIRED)

target_link_libraries(
  your_node
  parameter_expression::parameter_expression
)

Create a parameter expression in your node:

class MyNode : public rclcpp::Node
{
public:
  MyNode() : Node("my_node")
  {
    // Create a parameter expression with default value 0.0
    expression_param_ = std::make_shared<parameter_expression::ParameterExpression>(*this, "my_expression", 0.0);
  }

  void some_function()
  {
    // Get the current evaluated value
    double value = expression_param_->get();
    RCLCPP_INFO(this->get_logger(), "Expression value: %f", value);
  }

private:
  parameter_expression::ParameterExpression::SharedPtr expression_param_;
};

Setting Parameters

You can set the parameter using various methods:

Via Command Line

ros2 param set /my_node my_expression "sin(3.14159/2) * 100"

Via Launch File or parameter YAML file

<launch>
  <node pkg="your_package" exec="your_node" name="my_node">
    <param name="my_expression" value="2 * _pi * 0.5" />
  </node>
</launch>

Advanced Usage

Custom Parameter Descriptor

rcl_interfaces::msg::ParameterDescriptor descriptor;
descriptor.description = "A mathematical expression for calculation";
descriptor.additional_constraints = "Must be a valid mathematical expression";

auto expression_param = std::make_shared<parameter_expression::ParameterExpression>(
  *this, "advanced_expression", 1.0, descriptor);

File truncated at 100 lines see the full file

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository

Repo symbol

parameter_expression repository