Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2RosCpp
Commits
e5788144
Commit
e5788144
authored
Jan 11, 2019
by
Alexander David Hellwig
Browse files
Fix ROS2 generated code
parent
cc26d4ea
Pipeline
#96867
passed with stages
in 2 minutes and 15 seconds
Changes
16
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/roscpp/LanguageUnitRosCMake.java
View file @
e5788144
...
...
@@ -17,7 +17,7 @@ public class LanguageUnitRosCMake {
"\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"
+
...
...
src/main/java/de/monticore/lang/monticar/generator/roscpp/LanguageUnitRosCppAdapter.java
View file @
e5788144
...
...
@@ -81,10 +81,10 @@ public class LanguageUnitRosCppAdapter {
.
map
(
type
->
"<"
+
type
+
".h>"
)
.
forEach
(
currentBluePrint:
:
addAdditionalIncludeString
);
}
else
{
currentBluePrint
.
addAdditionalIncludeString
(
"<rclpp/rclpp.hpp>"
);
currentBluePrint
.
addAdditionalIncludeString
(
"<rcl
c
pp/rcl
c
pp.hpp>"
);
String
compName
=
NameHelper
.
getComponentNameTargetLanguage
(
componentSymbol
.
getFullName
());
currentBluePrint
.
addAdditionalIncludeString
(
"\""
+
compName
+
".h
pp
\""
);
currentBluePrint
.
addAdditionalIncludeString
(
"\"IAdapter_"
+
compName
+
".h
pp
\""
);
currentBluePrint
.
addAdditionalIncludeString
(
"\""
+
compName
+
".h\""
);
currentBluePrint
.
addAdditionalIncludeString
(
"\"IAdapter_"
+
compName
+
".h\""
);
//Add each msg include exactly once
rosPorts
.
stream
()
...
...
@@ -94,6 +94,15 @@ public class LanguageUnitRosCppAdapter {
.
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
);
}
...
...
@@ -135,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
);
});
}
...
...
@@ -177,7 +186,7 @@ public class LanguageUnitRosCppAdapter {
if
(!
isRos2Mode
())
{
initMethod
.
addInstruction
(
new
TargetCodeInstruction
(
"ros::spin();"
));
}
else
{
initMethod
.
addInstruction
(
new
TargetCodeInstruction
(
"rclcpp::spin(
"
+
classname
+
"
);"
));
initMethod
.
addInstruction
(
new
TargetCodeInstruction
(
"rclcpp::spin(
node_handle
);"
));
}
currentBluePrint
.
addMethod
(
initMethod
);
...
...
@@ -206,7 +215,7 @@ public class LanguageUnitRosCppAdapter {
if
(!
isRos2Mode
())
{
field
.
setTypeNameTargetLanguage
(
"ros::Subscriber"
);
}
else
{
field
.
setTypeNameTargetLanguage
(
"rclpp::Subscri
be
r"
);
field
.
setTypeNameTargetLanguage
(
"rcl
c
pp::Subscri
ption<"
+
getFullRosType
(
rosConnectionSymbol
)
+
">::SharedPt
r"
);
}
field
.
setName
(
name
);
uniqueSubFields
.
put
(
name
,
field
);
...
...
@@ -226,7 +235,7 @@ public class LanguageUnitRosCppAdapter {
if
(!
isRos2Mode
())
{
field
.
setTypeNameTargetLanguage
(
"ros::Publisher"
);
}
else
{
field
.
setTypeNameTargetLanguage
(
"rclpp::Publisher"
);
field
.
setTypeNameTargetLanguage
(
"rcl
c
pp::Publisher
<"
+
getFullRosType
(
rosConnectionSymbol
)
+
">::SharedPtr
"
);
}
field
.
setName
(
name
);
uniquePubFields
.
put
(
name
,
field
);
...
...
src/main/java/de/monticore/lang/monticar/generator/roscpp/helper/InitHelper.java
View file @
e5788144
...
...
@@ -23,8 +23,9 @@ public class InitHelper {
}
else
{
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
(
"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
;
}
...
...
src/main/java/de/monticore/lang/monticar/generator/roscpp/helper/PrinterHelper.java
View file @
e5788144
...
...
@@ -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
{
...
...
src/main/java/de/monticore/lang/monticar/generator/roscpp/instructions/PublishInstruction.java
View file @
e5788144
...
...
@@ -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);"
;
}
}
}
src/main/java/de/monticore/lang/monticar/generator/roscpp/instructions/SubscribeInstruction.java
View file @
e5788144
...
...
@@ -12,7 +12,7 @@ public class SubscribeInstruction extends TargetCodeInstruction {
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
+
"\",
"
+
callback
+
"
);"
;
this
.
instruction
=
subscriber
.
getNameTargetLanguageFormat
()
+
" = node_handle->create_subscription<"
+
fullRosType
+
">(\""
+
topicName
+
"\",
std::bind(&"
+
className
+
"::"
+
callback
+
", this, std::placeholders::_1)
);"
;
}
}
@Override
...
...
src/test/java/de/monticore/lang/monticar/generator/roscpp/Ros2Test.java
View file @
e5788144
...
...
@@ -23,7 +23,7 @@ public class Ros2Test extends AbstractSymtabTest{
TaggingResolver
taggingResolver
=
createSymTabAndTaggingResolver
(
"src/test/resources/"
);
RosToEmamTagSchema
.
registerTagTypes
(
taggingResolver
);
EMAComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
EMAComponentInstanceSymbol
>
resolve
(
"tests.a.comp
A
"
,
EMAComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
EMAComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
EMAComponentInstanceSymbol
>
resolve
(
"tests.a.comp
B
"
,
EMAComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
GeneratorRosCpp
generatorRosCpp
=
new
GeneratorRosCpp
();
...
...
@@ -37,7 +37,7 @@ public class Ros2Test extends AbstractSymtabTest{
@Test
public
void
testGenerateCMakeRos2
()
throws
IOException
{
TaggingResolver
taggingResolver
=
createSymTabAndTaggingResolver
(
"src/test/resources/"
);
EMAComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
EMAComponentInstanceSymbol
>
resolve
(
"tests.a.comp
A
"
,
EMAComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
EMAComponentInstanceSymbol
componentInstanceSymbol
=
taggingResolver
.<
EMAComponentInstanceSymbol
>
resolve
(
"tests.a.comp
B
"
,
EMAComponentInstanceSymbol
.
KIND
).
orElse
(
null
);
assertNotNull
(
componentInstanceSymbol
);
GeneratorRosCpp
generatorRosCpp
=
new
GeneratorRosCpp
();
...
...
src/test/resources/results/basicStructComp/CMakeLists.txt
View file @
e5788144
...
...
@@ -5,7 +5,7 @@ find_package(roscpp REQUIRED)
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
src/test/resources/results/echoCMake/CMakeLists.txt
View file @
e5788144
...
...
@@ -7,7 +7,7 @@ find_package(rosgraph_msgs REQUIRED)
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
src/test/resources/results/echoCMakeRos2/CMakeLists.txt
View file @
e5788144
cmake_minimum_required
(
VERSION 3.5
)
project
(
RosAdapter_tests_a_comp
A
)
project
(
RosAdapter_tests_a_comp
B
)
find_package
(
rclcpp REQUIRED
)
find_package
(
std_msgs REQUIRED
)
add_library
(
RosAdapter_tests_a_comp
A
RosAdapter_tests_a_comp
A
.c
xx
)
set_target_properties
(
RosAdapter_tests_a_comp
A
PROPERTIES LINKER_LANGUAGE CXX
)
target_link_libraries
(
RosAdapter_tests_a_comp
A
tests_a_comp
A
${
rclcpp_LIBRARIES
}
${
std_msgs_LIBRARIES
}
IAdapter_tests_a_compA
)
target_include_directories
(
RosAdapter_tests_a_comp
A
PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
${
std_msgs
_INCLUDE_DIRS
}
${
rclcpp
_INCLUDE_DIRS
}
)
add_library
(
RosAdapter_tests_a_comp
B
RosAdapter_tests_a_comp
B
.c
pp
)
set_target_properties
(
RosAdapter_tests_a_comp
B
PROPERTIES LINKER_LANGUAGE CXX
)
target_link_libraries
(
RosAdapter_tests_a_comp
B
tests_a_comp
B IAdapter_tests_a_compB
${
rclcpp_LIBRARIES
}
${
std_msgs_LIBRARIES
}
)
target_include_directories
(
RosAdapter_tests_a_comp
B
PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
${
rclcpp
_INCLUDE_DIRS
}
${
std_msgs
_INCLUDE_DIRS
}
)
export
(
TARGETS RosAdapter_tests_a_compA FILE RosAdapter_tests_a_compA.cmake
)
\ No newline at end of file
export
(
TARGETS RosAdapter_tests_a_compB FILE RosAdapter_tests_a_compB.cmake
)
\ No newline at end of file
src/test/resources/results/echoCMakeRos2/RosAdapter_tests_a_compA.cxx
deleted
100644 → 0
View file @
cc26d4ea
#include "RosAdapter_tests_a_compA.h"
\ No newline at end of file
src/test/resources/results/echoCMakeRos2/RosAdapter_tests_a_compB.cpp
0 → 100644
View file @
e5788144
#include "RosAdapter_tests_a_compB.h"
\ No newline at end of file
src/test/resources/results/echoCMakeRos2/RosAdapter_tests_a_comp
A
.h
→
src/test/resources/results/echoCMakeRos2/RosAdapter_tests_a_comp
B
.h
View file @
e5788144
#pragma once
#include "IAdapter_tests_a_compA.h"
#include "tests_a_compA.h"
#include "IAdapter_tests_a_compB.h"
#include "tests_a_compB.h"
#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/float64.hpp>
#include "rclcpp/rclcpp.hpp"
class
RosAdapter_tests_a_compA
:
public
IAdapter_tests_a_compA
{
tests_a_compA
*
component
;
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_comp
A
(){
RosAdapter_tests_a_comp
B
(){
}
...
...
@@ -17,15 +17,13 @@ class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
component
->
rosIn
=
msg
->
data
;
}
void
init
(
tests_a_comp
A
*
comp
){
void
init
(
tests_a_comp
B
*
comp
){
this
->
component
=
comp
;
char
*
tmp
=
strdup
(
""
);
int
i
=
1
;
rclcpp
::
init
(
i
,
&
tmp
);
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
));
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
);
}
...
...
@@ -40,4 +38,4 @@ class RosAdapter_tests_a_compA: public IAdapter_tests_a_compA{
publish_echoPublisher
();
}
};
\ No newline at end of file
};
src/test/resources/results/testInstanceArrayComp/CMakeLists.txt
View file @
e5788144
...
...
@@ -5,7 +5,7 @@ find_package(roscpp REQUIRED)
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
}
)
...
...
src/test/resources/tests/a/CompB.emam
0 → 100644
View file @
e5788144
package
tests
.
a
;
component
CompB
{
port
in
Q
rosIn
;
port
out
Q
rosOut
;
implementation
Math
{
rosOut
=
rosIn
;
}
}
\ No newline at end of file
src/test/resources/tests/a/EchoRos2.tag
0 → 100644
View file @
e5788144
package
tests
.
a
;
conforms
to
de
.
monticore
.
lang
.
monticar
.
generator
.
roscpp
.
RosToEmamTagSchema
;
tags
EchoRos2
{
tag
compB
.
rosIn
with
RosConnection
=
{
topic
=
(/
clock
,
std_msgs
/
msg
/
Float64
),
msgField
=
data
};
tag
compB
.
rosOut
with
RosConnection
=
{
topic
=
(/
echo
,
std_msgs
/
msg
/
Float64
),
msgField
=
data
};
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment