Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters not set from the command-line using new syntax #860

Closed
jacobperron opened this issue Sep 20, 2019 · 9 comments
Closed

Parameters not set from the command-line using new syntax #860

jacobperron opened this issue Sep 20, 2019 · 9 comments
Labels
bug Something isn't working

Comments

@jacobperron
Copy link
Member

jacobperron commented Sep 20, 2019

Bug report

Required Info:

  • Operating System:
    • Ubuntu 18.04
  • Installation type:
    • source
  • Version or commit hash:
  • DDS implementation:
    • N/A
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

Create a simple node that echos a parameter:

#include <iostream>
#include <memory>

#include "rclcpp/rclcpp.hpp"

class FooNode : public rclcpp::Node
{
public:
  explicit FooNode(const rclcpp::NodeOptions options = rclcpp::NodeOptions())
  : Node("foo_node", options)
  { 
    auto param_value = this->declare_parameter("foo", "bar");
    std::cout << "param value: " << param_value << std::endl;
  }
};

int main(int argc, char** argv)
{
  rclcpp::init(argc, argv);

  auto node = std::make_shared<FooNode>();

  rclcpp::spin(node);

  return 0;
}

Run the node and try to set the parameter "foo":

./foo --ros-args -p foo:=jacob

Expected behavior

The node prints the value set from the command line:

param value: jacob

Actual behavior

The node prints the default value:

param value: bar

Additional information

Passing the parameter via a YAML file works fine, e.g

params.yaml

foo_node:
  ros__parameters:
    foo: "jacob"

and running

./foo --ros-args --params-file params.yaml
@jacobperron jacobperron added the bug Something isn't working label Sep 20, 2019
@jacobperron
Copy link
Member Author

@hidmic FYI

@hidmic
Copy link
Contributor

hidmic commented Sep 20, 2019

Alright, it looks like in between changes to rcl and how the command line looks like, the last round of changes was left forgotten in my local clones of rclcpp and rclpy. Which also means things are not being tested properly. My bad. I'll clean it up, add tests and send it.

@jacobperron
Copy link
Member Author

I'll clean it up, add tests and send it.

🙇‍♂️

@jacobperron
Copy link
Member Author

@hidmic Looks like this was fixed? Though I don't know by what changes exactly.

@hidmic
Copy link
Contributor

hidmic commented Oct 3, 2019

Yes it was! By ros2/rcl#508 and #865. Closing.

@hidmic hidmic closed this as completed Oct 3, 2019
@hamaney
Copy link

hamaney commented Apr 2, 2020

I see this issue in rclpy.
I don't know how to check the version/branch I am on, but I installed ros2 using
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64,arm64] http://packages.ros.org/ros2/ubuntu lsb_release -cs main" > /etc/apt/sources.list.d/ros2-latest.list'

the question seems to be related
https://answers.ros.org/question/348149/confision-about-ros2-rclpy-parameter/?answer=348191#post-id-348191

@jacobperron
Copy link
Member Author

@hamaney If you installed ROS 2 with apt, then the major version should be name of the package(s) you install (e.g. ros-dashing-desktop). Furthermore, it should also appear in the path of the setup file you source (e.g. source /opt/ros/dashing/setup.bash). If you are still not sure which version of ROS 2 you have installed, you can try echoing the environment variable ROS_DISTRO (e.g. on Linux: echo $ROS_DISTRO).

As pointed out on ROS answers, this method for passing ROS parameters is only supported since ROS 2 Eloquent. So if you are using ROS 2 Dashing, it will not work. If you continue to have problems, please comment on ROS Answers (or create a new question) with details about your installation. This lets other users benefit from the answer. (GitHub tickets are not as visible)

@hamaney
Copy link

hamaney commented Apr 3, 2020

Sorry, my mistake. I know the distro of ROS2 that I am using, which is Dashing as you mentioned.
I was under the impression that ROS2 versioning is the destro name and number. That's why I asked how to find more info about what I am running. Thanks for your help.

@jacobperron
Copy link
Member Author

jacobperron commented Apr 4, 2020

@hamaney No worries. Because ROS follows a federated model for packages, each package has a version number, but ROS distro as a whole just has a name (e.g. Dashing). If you want to know the particular version of a package, you can use the following ros2pkg command:

# Get the version of rclcpp
ros2 pkg xml rclcpp --tag version

nnmm pushed a commit to ApexAI/rclcpp that referenced this issue Jul 9, 2022
ros2#860)

* Allow forward slashes within a parameter name rule in argument parsing

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants