Commit dc5a74ce authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Add working ROS2 Adapter as result for testcase

parent 0e0436f7
cmake_minimum_required(VERSION 3.5)
project (RosAdapter_tests_a_compA)
find_package(automated_driving_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rosgraph_msgs REQUIRED)
find_package(std_msgs REQUIRED)
add_library(RosAdapter_tests_a_compA RosAdapter_tests_a_compA.h)
add_library(RosAdapter_tests_a_compA RosAdapter_tests_a_compA.cxx)
set_target_properties(RosAdapter_tests_a_compA PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(RosAdapter_tests_a_compA tests_a_compA ${automated_driving_msgs_LIBRARIES} ${rclcpp_LIBRARIES} ${rosgraph_msgs_LIBRARIES})
target_include_directories(RosAdapter_tests_a_compA PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${automated_driving_msgs_INCLUDE_DIRS} ${rclcpp_INCLUDE_DIRS} ${rosgraph_msgs_INCLUDE_DIRS})
target_link_libraries(RosAdapter_tests_a_compA tests_a_compA ${rclcpp_LIBRARIES} ${std_msgs_LIBRARIES} IAdapter_tests_a_compA)
target_include_directories(RosAdapter_tests_a_compA PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${std_msgs_INCLUDE_DIRS} ${rclcpp_INCLUDE_DIRS})
export(TARGETS RosAdapter_tests_a_compA FILE RosAdapter_tests_a_compA.cmake)
\ No newline at end of file
#include "RosAdapter_tests_a_compA.h"
\ No newline at end of file
#pragma once
#include "IAdapter_tests_a_compA.hpp"
#include "tests_a_compA.hpp"
#include <automated_driving_msgs/StampedFloat64.hpp>
#include <rclpp/rclpp.hpp>
#include <rosgraph_msgs/Clock.hpp>
#include "IAdapter_tests_a_compA.h"
#include "tests_a_compA.h"
#include <std_msgs/msg/float64.hpp>
#include "rclcpp/rclcpp.hpp"
class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
tests_a_compA* component;
rclpp::Subscriber _clockSubscriber;
rclpp::Publisher _echoPublisher;
rclcpp::Subscription<std_msgs::msg::Float64>::SharedPtr _clockSubscriber;
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr _echoPublisher;
public:
RosAdapter_tests_a_compA(){
}
void _clockCallback(const rosgraph_msgs::Clock::SharedPtr msg){
component->rosIn = msg->clock.toSec();
void _clockCallback(const std_msgs::msg::Float64::SharedPtr msg){
component->rosIn = msg->data;
}
void init(tests_a_compA* comp){
this->component = comp;
char* tmp = strdup("");
int i = 0;
int i = 1;
rclcpp::init(i, &tmp);
_clockSubscriber = node_handle->create_subscription<rosgraph_msgs::Clock>("/clock", _clockCallback);
_echoPublisher = node_handle->create_publisher<automated_driving_msgs::StampedFloat64>("/echo");
rclcpp::spin(RosAdapter_tests_a_compA);
auto node_handle = rclcpp::Node::make_shared("RosAdapter_tests_a_compA");
_clockSubscriber = node_handle->create_subscription<std_msgs::msg::Float64>("/clock", std::bind(&RosAdapter_tests_a_compA::_clockCallback, this, std::placeholders::_1));
_echoPublisher = node_handle->create_publisher<std_msgs::msg::Float64>("/echo");
rclcpp::spin(node_handle);
}
void publish_echoPublisher(){
automated_driving_msgs::StampedFloat64 tmpMsg;
std_msgs::msg::Float64 tmpMsg;
tmpMsg.data = component->rosOut;
_echoPublisher.publish(tmpMsg);
_echoPublisher->publish(tmpMsg);
}
void tick(){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment