Commit 74e258ed authored by Evgeny Kusmenko's avatar Evgeny Kusmenko
Browse files

Merge branch 'ros2_test' into 'master'

Ros2

See merge request !10
parents b0ab2898 43d7f8c9
Pipeline #101025 passed with stages
in 2 minutes and 44 seconds
......@@ -9,7 +9,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-roscpp-generator</artifactId>
<version>0.1.1-SNAPSHOT</version>
<version>0.1.2-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......@@ -17,7 +17,7 @@
<!-- .. SE-Libraries .................................................. -->
<se-commons.version>1.7.7</se-commons.version>
<Embedded-MontiArc-Math.version>0.1.4-SNAPSHOT</Embedded-MontiArc-Math.version>
<Embedded-MontiArc-Math.version>0.1.7-SNAPSHOT</Embedded-MontiArc-Math.version>
<Embedded-montiarc-math-rosmsg-generator.version>0.1.1-SNAPSHOT</Embedded-montiarc-math-rosmsg-generator.version>
<!-- .. Libraries .................................................. -->
......
......@@ -23,6 +23,15 @@ public class GeneratorRosCpp {
private String generationTargetPath;
private boolean generateCMake = false;
private boolean ros2Mode = false;
public boolean isRos2Mode() {
return ros2Mode;
}
public void setRos2Mode(boolean ros2Mode) {
this.ros2Mode = ros2Mode;
}
public void setGenerateCMake(boolean generateCMake) {
this.generateCMake = generateCMake;
......@@ -81,6 +90,7 @@ public class GeneratorRosCpp {
FileContent apdapter = new FileContent();
LanguageUnitRosCppAdapter languageUnitRosCppAdapter = new LanguageUnitRosCppAdapter();
languageUnitRosCppAdapter.setRos2Mode(this.isRos2Mode());
Optional<BluePrintCPP> currentBluePrint = languageUnitRosCppAdapter.generateBluePrint(component);
if(currentBluePrint.isPresent()) {
......@@ -103,7 +113,7 @@ public class GeneratorRosCpp {
if (generateCMake) {
LanguageUnitRosCMake languageUnitRosCMake = new LanguageUnitRosCMake();
res.add(languageUnitRosCMake.generate(component, languageUnitRosCppAdapter.getAdditionalPackages()));
res.addAll(languageUnitRosCMake.generate(component, languageUnitRosCppAdapter.getAdditionalPackages(),isRos2Mode()));
}
res.add(apdapter);
......
......@@ -15,21 +15,25 @@ public class LanguageUnitRosCMake {
"\n" +
"<packages>\n" +
"\n" +
"add_library(<name> <name>.h)\n" +
"add_library(<name> <name>.cpp)\n" +
"set_target_properties(<name> PROPERTIES LINKER_LANGUAGE CXX)\n" +
"target_link_libraries(<name> <compName> <libraries>)\n" +
"target_link_libraries(<name> <compName> IAdapter_<compName> <libraries>)\n" +
"target_include_directories(<name> PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} <include_dirs>)\n" +
"<dependency>\n" +
"\n" +
"export(TARGETS <name> FILE <name>.cmake)";
FileContent generate(EMAComponentInstanceSymbol componentInstanceSymbol, List<String> additionalPackages) {
List<FileContent> generate(EMAComponentInstanceSymbol componentInstanceSymbol, List<String> additionalPackages, boolean isRos2Mode) {
FileContent fileContent = new FileContent();
fileContent.setFileName("CMakeLists.txt");
List<String> allPackages = new ArrayList<>();
allPackages.addAll(additionalPackages);
allPackages.add("roscpp");
if(!isRos2Mode) {
allPackages.add("roscpp");
}else{
allPackages.add("rclcpp");
}
List<String> distinctSortedPackages = allPackages.stream()
.distinct()
......@@ -66,7 +70,15 @@ public class LanguageUnitRosCMake {
.replace("<dependency>", dependency);
fileContent.setFileContent(content);
return fileContent;
List<FileContent> result = new ArrayList<>();
result.add(fileContent);
FileContent cppFile = new FileContent();
cppFile.setFileName(name + ".cpp");
cppFile.setFileContent("#include \""+ name +".h\"");
result.add(cppFile);
return result;
}
}
......@@ -3,6 +3,7 @@ package de.monticore.lang.monticar.generator.roscpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol;
import de.monticore.lang.monticar.generator.roscpp.helper.InitHelper;
import de.monticore.lang.monticar.generator.roscpp.util.*;
import de.monticore.lang.monticar.generator.roscpp.helper.NameHelper;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
......@@ -23,6 +24,15 @@ public class LanguageUnitRosCppAdapter {
private List<MsgConverter> msgConverts = new ArrayList<>();
private List<String> additionalPackages = new ArrayList<>();
private Map<RosMsg, MCTypeReference<? extends MCTypeSymbol>> usedRosMsgs = new HashMap<>();
private boolean ros2Mode = false;
public boolean isRos2Mode() {
return ros2Mode;
}
public void setRos2Mode(boolean ros2Mode) {
this.ros2Mode = ros2Mode;
}
public List<String> getAdditionalPackages() {
return additionalPackages;
......@@ -54,21 +64,48 @@ public class LanguageUnitRosCppAdapter {
}
private void generateIncludes(EMAComponentInstanceSymbol componentSymbol, List<EMAPortSymbol> rosPorts, BluePrintCPP currentBluePrint) {
currentBluePrint.addAdditionalIncludeString("<ros/ros.h>");
String compName = NameHelper.getComponentNameTargetLanguage(componentSymbol.getFullName());
currentBluePrint.addAdditionalIncludeString("\"" + compName + ".h\"");
currentBluePrint.addAdditionalIncludeString("\"IAdapter_" + compName + ".h\"");
//Add each msg include exactly once
rosPorts.stream()
.map(EMAPortSymbol::getMiddlewareSymbol)
.map(Optional::get)
.map(mws -> (RosConnectionSymbol) mws)
.map(RosConnectionSymbol::getTopicType)
.map(Optional::get)
.peek(topicType -> additionalPackages.add(NameHelper.getPackageOfMsgType(topicType)))
.map(type -> "<" + type + ".h>")
.forEach(currentBluePrint::addAdditionalIncludeString);
if(!isRos2Mode()) {
currentBluePrint.addAdditionalIncludeString("<ros/ros.h>");
String compName = NameHelper.getComponentNameTargetLanguage(componentSymbol.getFullName());
currentBluePrint.addAdditionalIncludeString("\"" + compName + ".h\"");
currentBluePrint.addAdditionalIncludeString("\"IAdapter_" + compName + ".h\"");
//Add each msg include exactly once
rosPorts.stream()
.map(EMAPortSymbol::getMiddlewareSymbol)
.map(Optional::get)
.map(mws -> (RosConnectionSymbol) mws)
.map(RosConnectionSymbol::getTopicType)
.map(Optional::get)
.peek(topicType -> additionalPackages.add(NameHelper.getPackageOfMsgType(topicType)))
.map(type -> "<" + type + ".h>")
.forEach(currentBluePrint::addAdditionalIncludeString);
}else{
currentBluePrint.addAdditionalIncludeString("<rclcpp/rclcpp.hpp>");
String compName = NameHelper.getComponentNameTargetLanguage(componentSymbol.getFullName());
currentBluePrint.addAdditionalIncludeString("\"" + compName + ".h\"");
currentBluePrint.addAdditionalIncludeString("\"IAdapter_" + compName + ".h\"");
//Add each msg include exactly once
rosPorts.stream()
.map(EMAPortSymbol::getMiddlewareSymbol)
.map(Optional::get)
.map(mws -> (RosConnectionSymbol) mws)
.map(RosConnectionSymbol::getTopicType)
.map(Optional::get)
.peek(topicType -> additionalPackages.add(NameHelper.getPackageOfMsgType(topicType)))
.map(type ->{
if(type.contains("/msg/")) {
String[] parts = type.split("/");
parts[parts.length - 1] = parts[parts.length - 1].substring(0, 1).toLowerCase() + parts[parts.length - 1].substring(1);
return String.join("/", parts);
}else{
return type;
}
})
.map(type -> "<" + type + ".hpp>")
.forEach(currentBluePrint::addAdditionalIncludeString);
}
msgConverts.stream()
.map(MsgConverter::getAdditionalIncludes)
......@@ -107,7 +144,7 @@ public class LanguageUnitRosCppAdapter {
publishers.keySet().forEach(var -> {
Method method = topicToMethod.get(publishers.get(var).getTopicName().get());
method.addInstruction(new PublishInstruction(var));
method.addInstruction(new PublishInstruction(var, ros2Mode));
currentBluePrint.addMethod(method);
});
}
......@@ -132,26 +169,25 @@ public class LanguageUnitRosCppAdapter {
compPointer.setName("comp");
initMethod.addParameter(compPointer);
initMethod.addInstruction(new TargetCodeInstruction("this->component = comp;"));
initMethod.addInstruction(new TargetCodeInstruction("char* tmp = strdup(\"\");"));
initMethod.addInstruction(new TargetCodeInstruction("int i = 0;"));
initMethod.addInstruction(new TargetCodeInstruction("ros::init(i, &tmp, \"" + classname + "_node\");"));
initMethod.addInstruction(new TargetCodeInstruction("ros::NodeHandle node_handle = ros::NodeHandle();"));
InitHelper.getInitInstructions(classname,isRos2Mode()).forEach(initMethod::addInstruction);
//subs
subscribers.keySet().stream()
.map(var -> new SubscribeInstruction(classname, var, subscribers.get(var).getTopicName().get(), getTopicNameTargetLanguage(subscribers.get(var).getTopicName().get()) + "Callback"))
.map(var -> new SubscribeInstruction(classname, var, subscribers.get(var).getTopicName().get(), getTopicNameTargetLanguage(subscribers.get(var).getTopicName().get()) + "Callback", isRos2Mode(), getFullRosType(subscribers.get(var))))
.distinct()
.sorted(Comparator.comparing(SubscribeInstruction::getTargetLanguageInstruction))
.forEach(initMethod::addInstruction);
publishers.keySet().stream()
.map(var -> new AdvertiseInstruction(var, getFullRosType(publishers.get(var)), publishers.get(var).getTopicName().get()))
.map(var -> new AdvertiseInstruction(var, getFullRosType(publishers.get(var)), publishers.get(var).getTopicName().get(),isRos2Mode()))
.distinct()
.sorted(Comparator.comparing(AdvertiseInstruction::getTargetLanguageInstruction))
.forEach(initMethod::addInstruction);
initMethod.addInstruction(new TargetCodeInstruction("ros::spin();"));
if(!isRos2Mode()) {
initMethod.addInstruction(new TargetCodeInstruction("ros::spin();"));
}else{
initMethod.addInstruction(new TargetCodeInstruction("rclcpp::spin(node_handle);"));
}
currentBluePrint.addMethod(initMethod);
}
......@@ -176,7 +212,11 @@ public class LanguageUnitRosCppAdapter {
String name = getTopicNameTargetLanguage(rosConnectionSymbol.getTopicName().get()).toLowerCase() + "Subscriber";
if (!uniqueSubFields.containsKey(name)) {
Variable field = new Variable();
field.setTypeNameTargetLanguage("ros::Subscriber");
if(!isRos2Mode()) {
field.setTypeNameTargetLanguage("ros::Subscriber");
}else{
field.setTypeNameTargetLanguage("rclcpp::Subscription<" + getFullRosType(rosConnectionSymbol) + ">::SharedPtr");
}
field.setName(name);
uniqueSubFields.put(name, field);
currBluePrint.addVariable(field);
......@@ -192,7 +232,11 @@ public class LanguageUnitRosCppAdapter {
String name = getTopicNameTargetLanguage(rosConnectionSymbol.getTopicName().get()).toLowerCase() + "Publisher";
if (!uniquePubFields.containsKey(name)) {
Variable field = new Variable();
field.setTypeNameTargetLanguage("ros::Publisher");
if(!isRos2Mode()) {
field.setTypeNameTargetLanguage("ros::Publisher");
}else{
field.setTypeNameTargetLanguage("rclcpp::Publisher<" + getFullRosType(rosConnectionSymbol) + ">::SharedPtr");
}
field.setName(name);
uniquePubFields.put(name, field);
currBluePrint.addVariable(field);
......@@ -235,7 +279,12 @@ public class LanguageUnitRosCppAdapter {
Method method = new Method(getTopicNameTargetLanguage(rosCon.getTopicName().get()) + "Callback", "void");
Variable tmpParam = new Variable();
tmpParam.setName("msg");
tmpParam.setTypeNameTargetLanguage("const " + getFullRosType(rosCon) + "::ConstPtr&");
if(!isRos2Mode())
{
tmpParam.setTypeNameTargetLanguage("const " + getFullRosType(rosCon) + "::ConstPtr&");
}else{
tmpParam.setTypeNameTargetLanguage("const " + getFullRosType(rosCon) + "::SharedPtr");
}
method.addParameter(tmpParam);
uniqueMethods.put(rosCon.getTopicName().get(), method);
}
......
package de.monticore.lang.monticar.generator.roscpp.helper;
import de.monticore.lang.monticar.generator.roscpp.util.Instruction;
import de.monticore.lang.monticar.generator.roscpp.util.TargetCodeInstruction;
import java.util.ArrayList;
import java.util.List;
public class InitHelper {
private InitHelper(){
}
public static List<Instruction> getInitInstructions(String classname, boolean isRos2){
List<Instruction> result = new ArrayList<>();
if (!isRos2){
result.add(new TargetCodeInstruction("this->component = comp;"));
result.add(new TargetCodeInstruction("char* tmp = strdup(\"\");"));
result.add(new TargetCodeInstruction("int i = 0;"));
result.add(new TargetCodeInstruction("ros::init(i, &tmp, \"" + classname + "_node\");"));
result.add(new TargetCodeInstruction("ros::NodeHandle node_handle = ros::NodeHandle();"));
}else{
result.add(new TargetCodeInstruction("this->component = comp;"));
result.add(new TargetCodeInstruction("char* tmp = strdup(\"\");"));
result.add(new TargetCodeInstruction("int i = 1;"));
result.add(new TargetCodeInstruction("rclcpp::init(i, &tmp);"));
result.add(new TargetCodeInstruction("auto node_handle = rclcpp::Node::make_shared(\""+ classname +"\");"));
}
return result;
}
}
......@@ -5,7 +5,9 @@ import de.monticore.lang.monticar.generator.roscpp.util.Method;
import de.monticore.lang.monticar.generator.roscpp.util.Variable;
import de.monticore.lang.monticar.generator.roscpp.util.BluePrintCPP;
import java.util.Arrays;
import java.util.Comparator;
import java.util.stream.Collectors;
public class PrinterHelper {
......
......@@ -8,10 +8,13 @@ import java.util.Objects;
public class AdvertiseInstruction extends TargetCodeInstruction {
private static final int MSG_QUEUE_SIZE = 5;
public AdvertiseInstruction(Variable publisher, String fullRosType, String topicName) {
this.instruction = publisher.getNameTargetLanguageFormat() + " = node_handle.advertise<" + fullRosType + ">(\"" + topicName + "\"," + MSG_QUEUE_SIZE + ");";
public AdvertiseInstruction(Variable publisher, String fullRosType, String topicName, boolean isRos2) {
if (!isRos2) {
this.instruction = publisher.getNameTargetLanguageFormat() + " = node_handle.advertise<" + fullRosType + ">(\"" + topicName + "\"," + MSG_QUEUE_SIZE + ");";
}else{
this.instruction = publisher.getNameTargetLanguageFormat() + " = node_handle->create_publisher<" + fullRosType + ">(\"" + topicName + "\");";
}
}
@Override
public boolean equals(Object other) {
if (!(other instanceof AdvertiseInstruction)) return false;
......
......@@ -5,7 +5,11 @@ import de.monticore.lang.monticar.generator.roscpp.util.Variable;
public class PublishInstruction extends TargetCodeInstruction {
public PublishInstruction(Variable publisher) {
this.instruction = publisher.getNameTargetLanguageFormat() + ".publish(tmpMsg);";
public PublishInstruction(Variable publisher, boolean ros2Mode) {
if(!ros2Mode) {
this.instruction = publisher.getNameTargetLanguageFormat() + ".publish(tmpMsg);";
}else{
this.instruction = publisher.getNameTargetLanguageFormat() + "->publish(tmpMsg);";
}
}
}
......@@ -8,10 +8,13 @@ import java.util.Objects;
public class SubscribeInstruction extends TargetCodeInstruction {
private static final int MSG_QUEUE_SIZE = 5;
public SubscribeInstruction(String className, Variable subscriber, String topicName, String callback) {
this.instruction = subscriber.getNameTargetLanguageFormat() + " = node_handle.subscribe(\"" + topicName + "\" ," + MSG_QUEUE_SIZE + ",&" + className + "::" + callback + ", this, ros::TransportHints().tcpNoDelay());";
public SubscribeInstruction(String className, Variable subscriber, String topicName, String callback, boolean isRos2, String fullRosType) {
if (!isRos2) {
this.instruction = subscriber.getNameTargetLanguageFormat() + " = node_handle.subscribe(\"" + topicName + "\" ," + MSG_QUEUE_SIZE + ",&" + className + "::" + callback + ", this, ros::TransportHints().tcpNoDelay());";
} else {
this.instruction = subscriber.getNameTargetLanguageFormat() + " = node_handle->create_subscription<" + fullRosType + ">(\"" + topicName + "\", std::bind(&" + className + "::" + callback + ", this, std::placeholders::_1));";
}
}
@Override
public boolean equals(Object other) {
if (!(other instanceof SubscribeInstruction)) return false;
......
package de.monticore.lang.monticar.generator.roscpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema;
import de.monticore.lang.monticar.generator.roscpp.helper.TagHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class Ros2Test extends AbstractSymtabTest{
//TODO: change resources/results/echoRos2 to ros2
@Test
public void echoCMakeRos2() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
RosToEmamTagSchema.registerTagTypes(taggingResolver);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<EMAComponentInstanceSymbol>resolve("tests.a.compB", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
GeneratorRosCpp generatorRosCpp = new GeneratorRosCpp();
generatorRosCpp.setGenerationTargetPath("./target/generated-sources-rclcpp/echoCMakeRos2/");
generatorRosCpp.setGenerateCMake(true);
generatorRosCpp.setRos2Mode(true);
List<File> files = TagHelper.resolveAndGenerate(generatorRosCpp, taggingResolver, componentInstanceSymbol);
testFilesAreEqual(files, "echoCMakeRos2/");
}
@Test
public void testGenerateCMakeRos2() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<EMAComponentInstanceSymbol>resolve("tests.a.compB", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
GeneratorRosCpp generatorRosCpp = new GeneratorRosCpp();
generatorRosCpp.setGenerationTargetPath("./target/generated-sources-rclcpp/CMakeRos2/");
generatorRosCpp.setGenerateCMake(true);
generatorRosCpp.setRos2Mode(true);
List<File> files = generatorRosCpp.generateFiles(componentInstanceSymbol, taggingResolver);
List<String> fileNames = files.stream()
.map(File::getName)
.collect(Collectors.toList());
assertTrue(fileNames.contains("CMakeLists.txt"));
}
}
......@@ -3,9 +3,9 @@ project (RosAdapter_tests_msg_basicStructComp)
find_package(roscpp REQUIRED)
add_library(RosAdapter_tests_msg_basicStructComp RosAdapter_tests_msg_basicStructComp.h)
add_library(RosAdapter_tests_msg_basicStructComp RosAdapter_tests_msg_basicStructComp.cpp)
set_target_properties(RosAdapter_tests_msg_basicStructComp PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(RosAdapter_tests_msg_basicStructComp tests_msg_basicStructComp ${roscpp_LIBRARIES} ${struct_msgs_LIBRARIES})
target_link_libraries(RosAdapter_tests_msg_basicStructComp tests_msg_basicStructComp IAdapter_tests_msg_basicStructComp ${roscpp_LIBRARIES} ${struct_msgs_LIBRARIES})
target_include_directories(RosAdapter_tests_msg_basicStructComp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${roscpp_INCLUDE_DIRS} ${struct_msgs_INCLUDE_DIRS})
add_dependencies(RosAdapter_tests_msg_basicStructComp struct_msgs_generate_messages)
export(TARGETS RosAdapter_tests_msg_basicStructComp FILE RosAdapter_tests_msg_basicStructComp.cmake)
\ No newline at end of file
#include "RosAdapter_tests_msg_basicStructComp.h"
\ No newline at end of file
......@@ -5,9 +5,9 @@ find_package(automated_driving_msgs REQUIRED)
find_package(roscpp REQUIRED)
find_package(rosgraph_msgs REQUIRED)
add_library(RosAdapter_tests_a_compA RosAdapter_tests_a_compA.h)
add_library(RosAdapter_tests_a_compA RosAdapter_tests_a_compA.cpp)
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} ${roscpp_LIBRARIES} ${rosgraph_msgs_LIBRARIES})
target_link_libraries(RosAdapter_tests_a_compA tests_a_compA IAdapter_tests_a_compA ${automated_driving_msgs_LIBRARIES} ${roscpp_LIBRARIES} ${rosgraph_msgs_LIBRARIES})
target_include_directories(RosAdapter_tests_a_compA PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${automated_driving_msgs_INCLUDE_DIRS} ${roscpp_INCLUDE_DIRS} ${rosgraph_msgs_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
cmake_minimum_required(VERSION 3.5)
project (RosAdapter_tests_a_compB)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
add_library(RosAdapter_tests_a_compB RosAdapter_tests_a_compB.cpp)
set_target_properties(RosAdapter_tests_a_compB PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(RosAdapter_tests_a_compB tests_a_compB IAdapter_tests_a_compB ${rclcpp_LIBRARIES} ${std_msgs_LIBRARIES})
target_include_directories(RosAdapter_tests_a_compB PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${rclcpp_INCLUDE_DIRS} ${std_msgs_INCLUDE_DIRS})
export(TARGETS RosAdapter_tests_a_compB FILE RosAdapter_tests_a_compB.cmake)
\ No newline at end of file
#include "RosAdapter_tests_a_compB.h"
\ No newline at end of file
#pragma once
#include "IAdapter_tests_a_compB.h"
#include "tests_a_compB.h"
#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/float64.hpp>
class RosAdapter_tests_a_compB: public IAdapter_tests_a_compB{
tests_a_compB* component;
rclcpp::Subscription<std_msgs::msg::Float64>::SharedPtr _clockSubscriber;
rclcpp::Publisher<std_msgs::msg::Float64>::SharedPtr _echoPublisher;
public:
RosAdapter_tests_a_compB(){
}
void _clockCallback(const std_msgs::msg::Float64::SharedPtr msg){
component->rosIn = msg->data;
}
void init(tests_a_compB* comp){
this->component = comp;
char* tmp = strdup("");
int i = 1;
rclcpp::init(i, &tmp);
auto node_handle = rclcpp::Node::make_shared("RosAdapter_tests_a_compB");
_clockSubscriber = node_handle->create_subscription<std_msgs::msg::Float64>("/clock", std::bind(&RosAdapter_tests_a_compB::_clockCallback, this, std::placeholders::_1));
_echoPublisher = node_handle->create_publisher<std_msgs::msg::Float64>("/echo");
rclcpp::spin(node_handle);
}
void publish_echoPublisher(){
std_msgs::msg::Float64 tmpMsg;
tmpMsg.data = component->rosOut;
_echoPublisher->publish(tmpMsg);
}
void tick(){
publish_echoPublisher();
}
};
......@@ -3,9 +3,9 @@ project (RosAdapter_test_instanceArrayComp_basicPorts_1_)
find_package(roscpp REQUIRED)
add_library(RosAdapter_test_instanceArrayComp_basicPorts_1_ RosAdapter_test_instanceArrayComp_basicPorts_1_.h)
add_library(RosAdapter_test_instanceArrayComp_basicPorts_1_ RosAdapter_test_instanceArrayComp_basicPorts_1_.cpp)
set_target_properties(RosAdapter_test_instanceArrayComp_basicPorts_1_ PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(RosAdapter_test_instanceArrayComp_basicPorts_1_ test_instanceArrayComp_basicPorts_1_ ${roscpp_LIBRARIES})
target_link_libraries(RosAdapter_test_instanceArrayComp_basicPorts_1_ test_instanceArrayComp_basicPorts_1_ IAdapter_test_instanceArrayComp_basicPorts_1_ ${roscpp_LIBRARIES})
target_include_directories(RosAdapter_test_instanceArrayComp_basicPorts_1_ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${roscpp_INCLUDE_DIRS})
......
#include "RosAdapter_test_instanceArrayComp_basicPorts_1_.h"
\ No newline at end of file
package tests.a;
component CompB{
port in Q rosIn;
port out Q rosOut;
implementation Math{
rosOut = rosIn;
}
}
\ No newline at end of file
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