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, rclcpp::NodeOptions& node_options)
19{
20 if(!rclcpp::ok())
21 {
22 rclcpp::init(/*argc*/ 0, /*argv*/ nullptr);
23 }
24 return std::make_shared<rclcpp::Node>(name, node_options);
25
26}
27
28builtin_interfaces::msg::Time ros2TimeFromYarp(double yarpTime)
29{
30 builtin_interfaces::msg::Time ros2Time;
31 uint64_t sec_part;
32 uint64_t nsec_part;
33 sec_part = int(yarpTime); // (time / 1000000000UL);
34 nsec_part = (yarpTime - sec_part)*1000000000UL;
35 ros2Time.sec = sec_part;
36 ros2Time.nanosec = (uint32_t)nsec_part;
37 return ros2Time;
38}
39
40double yarpTimeFromRos2(builtin_interfaces::msg::Time ros2Time)
41{
42 return double(ros2Time.sec) + (double(ros2Time.nanosec) / 1000000000.0);
43}
builtin_interfaces::msg::Time ros2TimeFromYarp(double yarpTime)
Definition Ros2Utils.cpp:28
double yarpTimeFromRos2(builtin_interfaces::msg::Time ros2Time)
Definition Ros2Utils.cpp:40
static rclcpp::Node::SharedPtr createNode(std::string name)
Definition Ros2Utils.cpp:9