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

Starting a node twice, with differend parameters

asked 2021-10-15 04:52:01 -0500

ros_max gravatar image

Hallo ,

I want to start my node twice, but it shoud have differend parameter for my COM-Path. Here is my code:

ros::init(argc, argv, "dc2412_upsd");
ros::NodeHandle nh1;



    ros::param::get("/read_attempt",loop);
    ros::param::get("/com_path", string_var);


      DC2412 communication(string_var);           //create a objekt 
      pcommunication=&communication;


  ros::ServiceServer service1 = nh1.advertiseService("input_voltage", InputVoltage);
  ros::ServiceServer service2 = nh1.advertiseService("output_voltage", OutputVoltage);
  ros::ServiceServer service3 = nh1.advertiseService("vcap_voltage", VcapVoltage);
  ros::ServiceServer service4 = nh1.advertiseService("set_time_to_shutdown", SetTimeToShutdown);
  ros::ServiceServer service5 = nh1.advertiseService("cap_esr_measurment",CapEsrMeasurment);
  ros::ServiceServer service6 = nh1.advertiseService("cap_esr",CapEsr);
  ros::ServiceServer service7 = nh1.advertiseService("input_current",InputCurrent);
  ros::ServiceServer service8 = nh1.advertiseService("charge_current",ChargeCurrent);    
  ros::Publisher pub1 = nh1.advertise<std_msgs::Int64>("monitorregister",1);
  ros::Publisher pub2 = nh1.advertise<std_msgs::Int64>("chargeregister",1);

my launch file:

<launch>
    <rosparam command="load" file="$(find ros_dc2412_upsd)config/config.yaml" />
     <!--<node pkg="turtlesim" name="sim1" type="turtlesim_node"/>-->

     <group ns="dc1">
          <node pkg="ros_dc2412_upsd" name="sim" type="dc2412_node"/>
     </group>

     <group ns="dc2">
          <node pkg="ros_dc2412_upsd" name="sim" type="dc2412_node"/>
     </group>

</launch>

my parameter file:

com_path : '/dev/ttyS5'
read_attempt : 10

So is it somehow possible? Maybe with the NodeHandle?

Thanks for your help

edit retag flag offensive close merge delete

Comments

An observation:

  ros::ServiceServer service1 = nh1.advertiseService("input_voltage", InputVoltage);
  ros::ServiceServer service2 = nh1.advertiseService("output_voltage", OutputVoltage);
  ros::ServiceServer service3 = nh1.advertiseService("vcap_voltage", VcapVoltage);
  ros::ServiceServer service4 = nh1.advertiseService("set_time_to_shutdown", SetTimeToShutdown);
  ros::ServiceServer service5 = nh1.advertiseService("cap_esr_measurment",CapEsrMeasurment);
  ros::ServiceServer service6 = nh1.advertiseService("cap_esr",CapEsr);
  ros::ServiceServer service7 = nh1.advertiseService("input_current",InputCurrent);
  ros::ServiceServer service8 = nh1.advertiseService("charge_current",ChargeCurrent);

are these services used to configure the node (ie: set parameters / settings after starting it)?

If they are, perhaps using dynamic_reconfigure would be more idiomatic.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-15 05:24:10 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-15 04:55:04 -0500

gvdhoorn gravatar image

updated 2021-10-15 04:58:31 -0500

Note that your question is almost a duplicate of #q146486, but I've answered it again, as your title specifically mentions "with different parameters".


You have two options:

  1. use private parameters: those are relative to the node itself. This is also suggested in #q146486.

    You'd have to move your rosparam element and make it a child of each node element (so you'd have two of them, loading different parameter files)

  2. move the rosparam element inside the group you've created. So again, you'd create two files, one for each node

In either case, you can't do this:

ros::param::get("/read_attempt",loop);

as the / there makes the parameter name a fully resolved one, which can't be namespaced and will always look at the global parameter space.

Remove the / and it would immediately become a relative parameter, which will be resolved against the current 'active' namespace.

edit flag offensive delete link more

Comments

Can you give we some code for the solution. I dont know how to replace this code:

ros::param::get("/read_attempt",loop);

so both nodes access different parameters

ros_max gravatar image ros_max  ( 2021-10-15 07:24:28 -0500 )edit

I'm not sure I understand. The only difference would be removing the /:

ros::param::get("read_attempt", loop);

I would recommend to review wiki/roscpp/Overview/Parameter Server, perhaps specifically the section on private parameters. Additionally: wiki/Names - Graph Resource Names.

Similar to Windows/Linux/OSX path names, anything starting with a / is absolute, it cannot be (easily) namespaced, and is always relative to the global root namespace.

Anything without a starting / is relative, and will always be looked up relative to the namespace of the node looking for it.

So if you place parameters in the node's namespace, and don't use absolute names, things should just work.

Private parameters are even more 'local': they are only seen by one specific node.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-15 07:32:27 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-10-15 04:52:01 -0500

Seen: 340 times

Last updated: Oct 15 '21