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

[ROS2] calling method in Node class

asked 2020-04-08 15:19:11 -0500

jlepers gravatar image

updated 2020-04-08 15:20:18 -0500

Hi, I would like to create a node class that keeps calling a Service.

class GetObject : public rclcpp::Node
{
public:

  GetObject() : Node("main")
  {
    auto getobj = this->create_client<canopen_msgs::srv::GetObject>("/get_object");  
  }
  void Get()
  {
     // code that calls the Service
  }
}

What is the correct way of calling the Get() method ? I would like to have following structure:

int main(int argc, char *argv[])

{
    rclcpp::init(argc, argv);
    auto GetConstructor = std::make_shared<GetObject>();

    while (rclcpp::ok())
    {
        // call the Get() method

    }

    return 0;

}

Thanks !

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-06-12 09:00:25 -0500

fergs gravatar image

There is a tutorial on creating a service client using rclcpp: https://index.ros.org/doc/ros2/Tutori...

edit flag offensive delete link more

Comments

Hi, thank you for your reply, but I think you misunderstood my question. I know how to create a Service client in rclcpp and I know the basics of OOP in C++. I would like to create a node class with a get() method that I can call in a loop function. So the code in my GetObject() class works, but I don't know how to call the Get() method (a method in general) correctly in a ROS2 environment.

jlepers gravatar image jlepers  ( 2020-06-12 09:10:11 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-04-08 15:19:11 -0500

Seen: 1,020 times

Last updated: Jun 12 '20