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

How to pass constants using a .idl file directly ?

asked 2020-07-08 20:28:08 -0500

Jeremy_z gravatar image

I'm using ros2 eloquent and trying to write a .idl message directly so that it could be compatible with Fast-DDS; I'm trying to pass constants in the .idl file. The file I wrote looks like

module package_name{
    module idl {
        struct exmaple_msg{
            // constants
           uint32 CONSTANT = 0;
       };
   };
};

I failed to pass it through rosidl_generate_interfaces; Could you give an correct syntax to write it and how to use it later ?

edit retag flag offensive close merge delete

Comments

1

I would suggest to create a .msg file with just a constant and after building the package look at / copy the generated .idl file.

Dirk Thomas gravatar image Dirk Thomas  ( 2020-07-10 15:46:12 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-07-16 09:40:34 -0500

MrCheesecake gravatar image

Have a look under Constants of this link https://mhanckow.students.wmi.amu.edu...
I think you have to use const before the constant like in C++.

Also this is an example of what rosidl_generate_interfaces generates:

ROS2 ConstTest.msg:

uint8 CONST1=1
uint8 CONST2=2
uint8 CONST3=3

uint8 data

ConstTest.idl:

module package_name {
  module msg {
    module ConstTest_Constants {
      const uint8 FAILSAFE_MODE1 = 1;
      const uint8 FAILSAFE_MODE2 = 2;
      const uint8 FAILSAFE_MODE3 = 3;
    };
    struct ConstTest {
      uint8 data;
    };
  };
};
edit flag offensive delete link more

Question Tools

Stats

Asked: 2020-07-08 20:28:08 -0500

Seen: 345 times

Last updated: Jul 16 '20