mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 10:26:52 +08:00
microRTPS bridge: make mandatory that all the uORB messages have their RTPS id
This commit is contained in:
@@ -36,6 +36,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import yaml
|
import yaml
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class Classifier():
|
class Classifier():
|
||||||
@@ -44,8 +45,11 @@ class Classifier():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, yaml_file, msg_folder):
|
def __init__(self, yaml_file, msg_folder):
|
||||||
self.msg_id_map = self.parse_yaml_msg_id_file(yaml_file)
|
|
||||||
self.msg_folder = msg_folder
|
self.msg_folder = msg_folder
|
||||||
|
self.all_msgs_list = self.set_all_msgs()
|
||||||
|
self.msg_id_map = self.parse_yaml_msg_id_file(yaml_file)
|
||||||
|
self.check_if_listed(yaml_file)
|
||||||
|
|
||||||
self.msgs_to_send = self.set_msgs_to_send()
|
self.msgs_to_send = self.set_msgs_to_send()
|
||||||
self.msgs_to_receive = self.set_msgs_to_receive()
|
self.msgs_to_receive = self.set_msgs_to_receive()
|
||||||
self.msgs_to_ignore = self.set_msgs_to_ignore()
|
self.msgs_to_ignore = self.set_msgs_to_ignore()
|
||||||
@@ -54,6 +58,13 @@ class Classifier():
|
|||||||
self.msg_files_ignore = self.set_msg_files_ignore()
|
self.msg_files_ignore = self.set_msg_files_ignore()
|
||||||
|
|
||||||
# setters (for class init)
|
# setters (for class init)
|
||||||
|
def set_all_msgs(self):
|
||||||
|
msg_list = []
|
||||||
|
for filename in os.listdir(self.msg_folder):
|
||||||
|
if '.msg' in filename:
|
||||||
|
msg_list.append(re.sub(".msg", "", filename))
|
||||||
|
return msg_list
|
||||||
|
|
||||||
def set_msgs_to_send(self):
|
def set_msgs_to_send(self):
|
||||||
send = {}
|
send = {}
|
||||||
for dict in self.msg_id_map['rtps']:
|
for dict in self.msg_id_map['rtps']:
|
||||||
@@ -87,6 +98,29 @@ class Classifier():
|
|||||||
return [os.path.join(self.msg_folder, msg + ".msg")
|
return [os.path.join(self.msg_folder, msg + ".msg")
|
||||||
for msg in self.msgs_to_ignore.keys()]
|
for msg in self.msgs_to_ignore.keys()]
|
||||||
|
|
||||||
|
def check_if_listed(self, yaml_file):
|
||||||
|
"""
|
||||||
|
Checks if all msgs are listed under the RTPS ID yaml file
|
||||||
|
"""
|
||||||
|
none_listed_msgs = []
|
||||||
|
for msg in self.all_msgs_list:
|
||||||
|
result = not any(
|
||||||
|
dict.values()[0] == msg for dict in self.msg_id_map['rtps'])
|
||||||
|
if result:
|
||||||
|
none_listed_msgs.append(msg)
|
||||||
|
|
||||||
|
if len(none_listed_msgs) > 0:
|
||||||
|
if len(none_listed_msgs) == 1:
|
||||||
|
error_msg = "The following message is not listen under "
|
||||||
|
elif len(none_listed_msgs) > 1:
|
||||||
|
error_msg = "The following messages are not listen under "
|
||||||
|
|
||||||
|
raise AssertionError(
|
||||||
|
"\n%s %s: " % (error_msg, yaml_file) + ", ".join('%s' % msg for msg in none_listed_msgs) +
|
||||||
|
"\n\nPlease add them to the yaml file with the respective ID and, if applicable, mark them" +
|
||||||
|
"to be sent or received by the micro-RTPS bridge.\n"
|
||||||
|
"NOTE: If the message has multi-topics (#TOPICS), these should be added as well.\n")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_yaml_msg_id_file(yaml_file):
|
def parse_yaml_msg_id_file(yaml_file):
|
||||||
"""
|
"""
|
||||||
@@ -128,8 +162,8 @@ if __name__ == "__main__":
|
|||||||
msg_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
msg_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
else:
|
else:
|
||||||
msg_dir = os.path.abspath(args.msgdir)
|
msg_dir = os.path.abspath(args.msgdir)
|
||||||
classifier = (Classifier(os.path.abspath(args.yaml_file), msg_dir) if os.path.isabs(args.yaml_file) \
|
classifier = (Classifier(os.path.abspath(args.yaml_file), msg_dir) if os.path.isabs(args.yaml_file)
|
||||||
else Classifier(os.path.join(msg_dir, args.yaml_file), msg_dir))
|
else Classifier(os.path.join(msg_dir, args.yaml_file), msg_dir))
|
||||||
|
|
||||||
if args.send:
|
if args.send:
|
||||||
if args.path:
|
if args.path:
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
rtps:
|
rtps:
|
||||||
- msg: actuator_armed
|
- msg: actuator_armed
|
||||||
id: 0
|
id: 0
|
||||||
- msg: actuator_control
|
- msg: actuator_controls
|
||||||
id: 1
|
id: 1
|
||||||
- msg: actuator_direct
|
- msg: actuator_direct
|
||||||
id: 2
|
id: 2
|
||||||
- msg: actuator_output
|
- msg: actuator_outputs
|
||||||
id: 3
|
id: 3
|
||||||
- msg: adc_report
|
- msg: adc_report
|
||||||
id: 4
|
id: 4
|
||||||
@@ -80,7 +80,7 @@ rtps:
|
|||||||
send: true
|
send: true
|
||||||
- msg: irlock_report
|
- msg: irlock_report
|
||||||
id: 32
|
id: 32
|
||||||
- msg: landing_target_innovation
|
- msg: landing_target_innovations
|
||||||
id: 33
|
id: 33
|
||||||
- msg: landing_target_pose
|
- msg: landing_target_pose
|
||||||
id: 34
|
id: 34
|
||||||
@@ -246,14 +246,24 @@ rtps:
|
|||||||
- msg: collision_constraints
|
- msg: collision_constraints
|
||||||
id: 107
|
id: 107
|
||||||
send: true
|
send: true
|
||||||
|
- msg: multirotor_motor_limits
|
||||||
|
id: 108
|
||||||
|
- msg: vehicle_constraints
|
||||||
|
id: 109
|
||||||
|
- msg: orbit_status
|
||||||
|
id: 110
|
||||||
|
- msg: power_monitor
|
||||||
|
id: 111
|
||||||
|
- msg: landing_gear
|
||||||
|
id: 112
|
||||||
# multi topics
|
# multi topics
|
||||||
- msg: actuator_control0
|
- msg: actuator_controls_0
|
||||||
id: 120
|
id: 120
|
||||||
- msg: actuator_control1
|
- msg: actuator_controls_1
|
||||||
id: 121
|
id: 121
|
||||||
- msg: actuator_control2
|
- msg: actuator_controls_2
|
||||||
id: 122
|
id: 122
|
||||||
- msg: actuator_control3
|
- msg: actuator_controls_3
|
||||||
id: 123
|
id: 123
|
||||||
- msg: actuator_controls_virtual_fw
|
- msg: actuator_controls_virtual_fw
|
||||||
id: 124
|
id: 124
|
||||||
|
|||||||
Reference in New Issue
Block a user