generated from husarion/rosbot-autonomy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_filter.sh
executable file
·60 lines (44 loc) · 1.6 KB
/
create_filter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Exit if no arguments are provided
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <topic_name1> <topic_name2> ... <topic_nameN>"
exit 1
fi
echo "Analyzing topics"
{
echo "allowlist:"
# Loop over each topic provided as argument
for TOPIC in "$@"; do
# Fetch details using 'ros2 topic info'
INFO=$(ros2 topic info -v $TOPIC)
# Extract type of the message
TYPE=$(echo "$INFO" | grep "Type:" | awk '{print $2}')
# Convert ROS2 message type to DDS type dynamically
PACKAGE_NAME=$(echo $TYPE | cut -d'/' -f1)
MSG_NAME=$(echo $TYPE | cut -d'/' -f3)
# Construct DDS_TYPE using the parsed package and message names
DDS_TYPE="${PACKAGE_NAME}::msg::dds_::${MSG_NAME}_"
# Check if conversion is successful
if [ -z "$DDS_TYPE" ]; then
echo "Error during type conversion for topic $TOPIC."
continue
fi
# Extract QoS settings
RELIABILITY=$(echo "$INFO" | grep "Reliability:" | awk '{print $2}')
DURABILITY=$(echo "$INFO" | grep "Durability:" | awk '{print $2}')
# Convert QoS settings to the desired format
RELIABILITY_BOOL="false"
[ "$RELIABILITY" == "RELIABLE" ] && RELIABILITY_BOOL="true"
DURABILITY_BOOL="false"
[ "$DURABILITY" == "TRANSIENT_LOCAL" ] && DURABILITY_BOOL="true"
# Print entry for current topic with QoS settings
echo " - name: rt$TOPIC"
echo " type: $DDS_TYPE"
echo " qos:"
echo " reliability: $RELIABILITY_BOOL"
echo " durability: $DURABILITY_BOOL"
done
echo "blocklist: []"
echo "builtin-topics: []"
} > new-filter.yaml
echo "Done! new-filter.yaml file created!"