YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Ros2Utils.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "Ros2Utils.h"
7
8
9rclcpp::Node::SharedPtr NodeCreator::createNode(std::string name)
10{
11 if(!rclcpp::ok())
12 {
13 rclcpp::init(/*argc*/ 0, /*argv*/ nullptr);
14 }
15 return std::make_shared<rclcpp::Node>(name);
16
17}
18rclcpp::Node::SharedPtr NodeCreator::createNode(std::string name, std::string name_space)
19{
20 if(!rclcpp::ok())
21 {
22 rclcpp::init(/*argc*/ 0, /*argv*/ nullptr);
23 }
24 return std::make_shared<rclcpp::Node>(name, name_space);
25
26}
27rclcpp::Node::SharedPtr NodeCreator::createNode(std::string name, std::string name_space, rclcpp::NodeOptions& node_options)
28{
29 if(!rclcpp::ok())
30 {
31 rclcpp::init(/*argc*/ 0, /*argv*/ nullptr);
32 }
33 return std::make_shared<rclcpp::Node>(name, name_space, node_options);
34}
35rclcpp::Node::SharedPtr NodeCreator::createNode(std::string name, rclcpp::NodeOptions& node_options)
36{
37 if(!rclcpp::ok())
38 {
39 rclcpp::init(/*argc*/ 0, /*argv*/ nullptr);
40 }
41 return std::make_shared<rclcpp::Node>(name, node_options);
42
43}
44
45builtin_interfaces::msg::Time ros2TimeFromYarp(double yarpTime)
46{
47 builtin_interfaces::msg::Time ros2Time;
48 uint64_t sec_part;
49 uint64_t nsec_part;
50 sec_part = int(yarpTime); // (time / 1000000000UL);
51 nsec_part = (yarpTime - sec_part)*1000000000UL;
52 ros2Time.sec = sec_part;
53 ros2Time.nanosec = (uint32_t)nsec_part;
54 return ros2Time;
55}
56
57double yarpTimeFromRos2(builtin_interfaces::msg::Time ros2Time)
58{
59 return double(ros2Time.sec) + (double(ros2Time.nanosec) / 1000000000.0);
60}
builtin_interfaces::msg::Time ros2TimeFromYarp(double yarpTime)
Definition Ros2Utils.cpp:45
double yarpTimeFromRos2(builtin_interfaces::msg::Time ros2Time)
Definition Ros2Utils.cpp:57
static rclcpp::Node::SharedPtr createNode(std::string name)
Definition Ros2Utils.cpp:9