mros2 icon indicating copy to clipboard operation
mros2 copied to clipboard

Compilation Error When Multiple Topics Share the Same Data Type

Open tmori opened this issue 3 months ago • 0 comments

問題のコード

https://github.com/mROS-base/mros2/blob/4d51853fbfe98151ec74693405c4b4fc21502539/mros2_header_generator/templates_generator.py#L60

該当の変数は、pubMsgTypesとsubMsgTypesで、生成コードが同じ型のものが複数出て来ると思います。

修正方法

重複するものを削ればOK

--- a/mros2_header_generator/templates_generator.py
+++ b/mros2_header_generator/templates_generator.py
@@ -55,9 +55,11 @@ def main():
                 includeFile = '#include "' + includeFile + '.hpp"'
                 includeFiles.append(includeFile)
                 
+    unique_pubMsgTypes = list(set(pubMsgTypes))
+    unique_subMsgTypes = list(set(subMsgTypes))
     env = Environment(loader=FileSystemLoader(path.dirname(__file__)))
     template = env.get_template('templates.tpl')
-    datatext = template.render({ "includeFiles":includeFiles, "pubMsgTypes":pubMsgTypes, "subMsgTypes":subMsgTypes  })
+    datatext = template.render({ "includeFiles":includeFiles, "pubMsgTypes":unique_pubMsgTypes, "subMsgTypes":unique_subMsgTypes  })
 
     outfile_path = os.path.join(outdir, "templates.hpp")
     outtemp_path = os.path.join(outdir, "templates.hpp.tmp")

tmori avatar Apr 08 '24 06:04 tmori