Commit dd502740 authored by Lennart Bucher's avatar Lennart Bucher
Browse files

merging all changes to this branch

parent 90b64ee2
Pipeline #186109 failed with stages
in 11 seconds
......@@ -61,6 +61,10 @@ public abstract class RosInterface {
public abstract String getRos2SetStructInstruction();
public abstract String getRosSetMatrixInstruction();
public abstract String getRos2SetMatrixInstruction();
public String getTopicType() {
return getRosConnectionSymbol().getTopicType().get();
}
......@@ -81,4 +85,13 @@ public abstract class RosInterface {
return port.getTypeReference().getReferencedSymbol() instanceof StructSymbol;
}
public boolean isMatrixInterface(){
if(!port.getTypeReference().existsReferencedSymbol()){
return false;
}
return port.getTypeReference().toString().equals("CommonMatrixType");
}
}
......@@ -33,12 +33,28 @@ public class RosPublisher extends RosInterface {
@Override
public String getRosSetStructInstruction() {
String fieldPrefix = this.rosConnectionSymbol.getMsgField().map(msgfield -> msgfield + ".").orElse("");
//return SetStructMsgInstruction.getStructInstruction(getPort(), getRosMsg(), fieldPrefix);
return SetStructMsgInstruction.getInstruction(getPort(), getRosMsg(), fieldPrefix);
}
@Override
public String getRosSetMatrixInstruction() {
String fieldPrefix = this.rosConnectionSymbol.getMsgField().map(msgfield -> msgfield + ".").orElse("");
//return SetStructMsgInstruction.getMatrixInstruction(getPort(), getRosMsg(), fieldPrefix);
return SetStructMsgInstruction.getInstruction(getPort(), getRosMsg(), fieldPrefix);
}
@Override
public String getRos2SetStructInstruction() {
String fieldPrefix = this.rosConnectionSymbol.getMsgField().map(msgfield -> msgfield + ".").orElse("");
return SetStructMsgInstruction.getInstruction(getPort(), getRos2Msg(),fieldPrefix);
//return SetStructMsgInstruction.getStructInstruction(getPort(), getRos2Msg(),fieldPrefix);
return SetStructMsgInstruction.getInstruction(getPort(), getRosMsg(), fieldPrefix);
}
@Override
public String getRos2SetMatrixInstruction() {
String fieldPrefix = this.rosConnectionSymbol.getMsgField().map(msgfield -> msgfield + ".").orElse("");
//return SetStructMsgInstruction.getMatrixInstruction(getPort(), getRos2Msg(),fieldPrefix);
return SetStructMsgInstruction.getInstruction(getPort(), getRosMsg(), fieldPrefix);
}
}
......@@ -33,12 +33,24 @@ public class RosSubscriber extends RosInterface {
@Override
public String getRosSetStructInstruction() {
String fieldPrefix = this.rosConnectionSymbol.getMsgField().map(msgfield -> msgfield + ".").orElse("");
return SetStructPortInstruction.getInstruction(getPort(), getRosMsg(), fieldPrefix);
return SetStructPortInstruction.getStructInstruction(getPort(), getRosMsg(), fieldPrefix);
}
@Override
public String getRosSetMatrixInstruction() {
String fieldPrefix = this.rosConnectionSymbol.getMsgField().map(msgfield -> msgfield + ".").orElse("");
return SetStructPortInstruction.getMatrixInstruction(getPort(), getRosMsg(), fieldPrefix);
}
@Override
public String getRos2SetStructInstruction() {
String fieldPrefix = this.rosConnectionSymbol.getMsgField().map(msgfield -> msgfield + ".").orElse("");
return SetStructPortInstruction.getInstruction(getPort(), getRos2Msg(), fieldPrefix);
return SetStructPortInstruction.getStructInstruction(getPort(), getRos2Msg(),fieldPrefix);
}
@Override
public String getRos2SetMatrixInstruction() {
String fieldPrefix = this.rosConnectionSymbol.getMsgField().map(msgfield -> msgfield + ".").orElse("");
return SetStructPortInstruction.getMatrixInstruction(getPort(), getRos2Msg(),fieldPrefix);
}
}
......@@ -39,10 +39,17 @@ ros::Publisher ${name};
<#macro callback sub>
void ${sub.getMethodName()}(const ${sub.getTypeNameInTargetLanguage()}::ConstPtr& msg){
<#if !sub.isStructInterface() && sub.getRosConnectionSymbol().getMsgField().isPresent()>
<#if !sub.isStructInterface() && !sub.isMatrixInterface() && sub.getRosConnectionSymbol().getMsgField().isPresent()>
component->${sub.getPortNameInTargetLanguage()} = msg->${sub.getRosConnectionSymbol().getMsgField().get()};
<#else>
${sub.getRosSetStructInstruction()}
<#-- ${sub.getRosSetStructInstruction()} -->
<#if sub.isMatrixInterface()>
${sub.getRosSetMatrixInstruction()}
<#else>
${sub.getRosSetStructInstruction()}
</#if>
</#if>
}
</#macro>
......
/* (c) https://github.com/MontiCore/monticore */
#pragma once
#include "IAdapter_tests_structs_arrayHandlingComp.h"
#include "tests_structs_arrayHandlingComp.h"
......
......@@ -6,7 +6,9 @@
#include <std_msgs/ByteMultiArray.h>
#include <std_msgs/Float64MultiArray.h>
#include <std_msgs/Int32MultiArray.h>
class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_matrixTypesComp{
tests_structs_matrixTypesComp* component;
ros::Subscriber _name1Subscriber;
ros::Subscriber _name2Subscriber;
......@@ -24,34 +26,56 @@ class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_ma
int i = 0;
ros::init(i, &tmp, "RosAdapter_tests_structs_matrixTypesComp_node");
ros::NodeHandle node_handle = ros::NodeHandle();
_name1Subscriber = node_handle.subscribe("/name1", 5, &RosAdapter_tests_structs_matrixTypesComp::_name1Callback, this, ros::TransportHints().tcpNoDelay());
_name2Subscriber = node_handle.subscribe("/name2", 5, &RosAdapter_tests_structs_matrixTypesComp::_name2Callback, this, ros::TransportHints().tcpNoDelay());
_name3Publisher = node_handle.advertise<std_msgs::ByteMultiArray>("/name3",5);
_name4Publisher = node_handle.advertise<std_msgs::Int32MultiArray>("/name4",5);
ros::spin();
}
void _name1Callback(const std_msgs::Float64MultiArray::ConstPtr& msg){
int counter = 0;
for(int i0 = 0; i0 < 3; i0++){
for(int i1 = 0; i1 < 1; i1++){
(component->in1)(i0, i1) = msg->data[counter];
counter++;
}
}
}
void _name2Callback(const std_msgs::ByteMultiArray::ConstPtr& msg){
int counter = 0;
for(int i0 = 0; i0 < 4; i0++){
for(int i1 = 0; i1 < 4; i1++){
(component->in2)(i0, i1) = msg->data[counter] != 0;
counter++;
}
}
}
void _name1Callback(const std_msgs::Float64MultiArray::ConstPtr& msg){
int counter = 0;
for(int i0 = 0; i0 < 3; i0++){
for(int i1 = 0; i1 < 1; i1++){
if(0 <= counter && counter <= 0){
(component->in1)(i0, i1) = msg->data[counter];
}
else if(0 > counter){
(component->in1)(i0, i1+0-0+1) = 0;
}
else{
(component->in1)(i0, i1) = 0;
}
counter++;
}
}
}
void _name2Callback(const std_msgs::ByteMultiArray::ConstPtr& msg){
int counter = 0;
for(int i0 = 0; i0 < 4; i0++){
for(int i1 = 0; i1 < 4; i1++){
if(0 <= counter && counter <= 3){
(component->in2)(i0, i1) = msg->data[counter] != 0;
}
else if(0 > counter){
(component->in2)(i0, i1+3-0+1) = 0;
}
else{
(component->in2)(i0, i1) = 0;
}
counter++;
}
}
}
void publish_name3Publisher(){
std_msgs::ByteMultiArray tmpMsg;
......@@ -66,7 +90,6 @@ class RosAdapter_tests_structs_matrixTypesComp: public IAdapter_tests_structs_ma
_name3Publisher.publish(tmpMsg);
}
void publish_name4Publisher(){
std_msgs::Int32MultiArray tmpMsg;
tmpMsg.data.resize(2 * 4);
......
package tests.structs;
conforms to de.monticore.lang.monticar.generator.roscpp.RosToEmamTagSchema;
tags ArrayHandling{
tag arrayHandlingComp.in1 with RosConnection = {topic = (/name1, std_msgs/Float64MultiArray), msgField = data[:]};
tag arrayHandlingComp.in2 with RosConnection = {topic = (/name2, std_msgs/ByteMultiArray)};
tag arrayHandlingComp.in3 with RosConnection = {topic = (/name3, nav_msgs/Path), msgField = poses[:].pose.orientation.x};
tag arrayHandlingComp.in4 with RosConnection = {topic = (/name4, nav_msgs/Path), msgField = poses[2:6].pose.orientation.x};
tag arrayHandlingComp.out1 with RosConnection = {topic = (/name5, std_msgs/ByteMultiArray)};
tag arrayHandlingComp.out2 with RosConnection = {topic = (/name6, std_msgs/Int32MultiArray)};
}
Markdown is supported
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