Skip to content

Commit 34ccb39

Browse files
authored
Added exclude-topic-types to record (#1582)
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
1 parent a780acb commit 34ccb39

20 files changed

+74
-27
lines changed

ros2bag/ros2bag/verb/record.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def add_arguments(self, parser, cli_name): # noqa: D102
8484
'--exclude-regex', default='',
8585
help='Exclude topics and services containing provided regular expression. '
8686
'Works on top of --all, --all-topics, or --regex.')
87+
parser.add_argument(
88+
'--exclude-topic-types', type=str, default=[], metavar='ExcludeTypes', nargs='+',
89+
help='List of topic types not being recorded. '
90+
'Works on top of --all, --all-topics, or --regex.')
8791
parser.add_argument(
8892
'--exclude-topics', type=str, metavar='Topic', nargs='+',
8993
help='List of topics not being recorded. '
@@ -230,6 +234,10 @@ def main(self, *, args): # noqa: D102
230234
return print_error('--exclude-topics argument requires either --all, --all-topics '
231235
'or --regex')
232236

237+
if args.exclude_topic_types and not (args.regex or args.all or args.all_topics):
238+
return print_error('--exclude-topic-types argument requires either --all, '
239+
'--all-topics or --regex')
240+
233241
if args.exclude_services and not (args.regex or args.all or args.all_services):
234242
return print_error('--exclude-services argument requires either --all, --all-services '
235243
'or --regex')
@@ -288,6 +296,7 @@ def main(self, *, args): # noqa: D102
288296
record_options.is_discovery_disabled = args.no_discovery
289297
record_options.topics = args.topics
290298
record_options.topic_types = args.topic_types
299+
record_options.exclude_topic_types = args.exclude_topic_types
291300
record_options.rmw_serialization_format = args.serialization_format
292301
record_options.topic_polling_interval = datetime.timedelta(
293302
milliseconds=args.polling_interval)

rosbag2_py/rosbag2_py/_transport.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class RecordOptions:
4040
compression_threads: int
4141
exclude_regex: str
4242
exclude_service_events: List[str]
43+
exclude_topic_types: List[str]
4344
exclude_topics: List[str]
4445
ignore_leaf_topics: bool
4546
include_hidden_topics: bool

rosbag2_py/src/rosbag2_py/_transport.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ PYBIND11_MODULE(_transport, m) {
371371
.def_readwrite("is_discovery_disabled", &RecordOptions::is_discovery_disabled)
372372
.def_readwrite("topics", &RecordOptions::topics)
373373
.def_readwrite("topic_types", &RecordOptions::topic_types)
374+
.def_readwrite("exclude_topic_types", &RecordOptions::exclude_topic_types)
374375
.def_readwrite("rmw_serialization_format", &RecordOptions::rmw_serialization_format)
375376
.def_readwrite("topic_polling_interval", &RecordOptions::topic_polling_interval)
376377
.def_readwrite("regex", &RecordOptions::regex)

rosbag2_tests/test/rosbag2_tests/test_rosbag2_cpp_get_service_info.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ TEST_P(Rosbag2CPPGetServiceInfoTest, get_service_info_for_bag_with_services_only
189189
storage_options.storage_id = storage_id;
190190
storage_options.uri = bag_path_str;
191191
rosbag2_transport::RecordOptions record_options =
192-
{false, true, false, {}, {}, {}, {"/rosout"}, {}, "cdr", 100ms};
192+
{false, true, false, {}, {}, {}, {"/rosout"}, {}, {}, "cdr", 100ms};
193193
auto recorder = std::make_shared<rosbag2_transport::Recorder>(
194194
std::move(writer), storage_options, record_options);
195195
recorder->record();
@@ -267,7 +267,7 @@ TEST_P(Rosbag2CPPGetServiceInfoTest, get_service_info_for_bag_with_topics_and_se
267267
storage_options.storage_id = storage_id;
268268
storage_options.uri = bag_path_str;
269269
rosbag2_transport::RecordOptions record_options =
270-
{true, true, false, {}, {}, {}, {"/rosout"}, {}, "cdr", 100ms};
270+
{true, true, false, {}, {}, {}, {"/rosout"}, {}, {}, "cdr", 100ms};
271271
auto recorder = std::make_shared<rosbag2_transport::Recorder>(
272272
std::move(writer), storage_options, record_options);
273273
recorder->record();

rosbag2_transport/include/rosbag2_transport/record_options.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct RecordOptions
3737
std::vector<std::string> topic_types;
3838
std::vector<std::string> services; // service event topic
3939
std::vector<std::string> exclude_topics;
40+
std::vector<std::string> exclude_topic_types;
4041
std::vector<std::string> exclude_service_events; // service event topic
4142
std::string rmw_serialization_format;
4243
std::chrono::milliseconds topic_polling_interval{100};

rosbag2_transport/src/rosbag2_transport/config_options_from_node_params.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ RecordOptions get_record_options_from_node_params(rclcpp::Node & node)
228228
record_options.exclude_topics = node.declare_parameter<std::vector<std::string>>(
229229
"record.exclude_topics", std::vector<std::string>());
230230

231+
record_options.exclude_topic_types = node.declare_parameter<std::vector<std::string>>(
232+
"record.exclude_topic_types", std::vector<std::string>());
233+
231234
// Convert service name to service event topic name
232235
auto exclude_service_list = node.declare_parameter<std::vector<std::string>>(
233236
"record.exclude_services", std::vector<std::string>());

rosbag2_transport/src/rosbag2_transport/record_options.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Node convert<rosbag2_transport::RecordOptions>::encode(
3232
node["is_discovery_disabled"] = record_options.is_discovery_disabled;
3333
node["topics"] = record_options.topics;
3434
node["topic_types"] = record_options.topic_types;
35+
node["exclude_topic_types"] = record_options.exclude_topic_types;
3536
node["services"] = record_options.services;
3637
node["rmw_serialization_format"] = record_options.rmw_serialization_format;
3738
node["topic_polling_interval"] = record_options.topic_polling_interval;
@@ -71,6 +72,9 @@ bool convert<rosbag2_transport::RecordOptions>::decode(
7172
optional_assign<std::string>(node, "regex", record_options.regex);
7273
optional_assign<std::string>(node, "exclude_regex", record_options.exclude_regex);
7374
optional_assign<std::vector<std::string>>(node, "exclude_topics", record_options.exclude_topics);
75+
optional_assign<std::vector<std::string>>(
76+
node, "exclude_topic_types",
77+
record_options.exclude_topic_types);
7478
optional_assign<std::vector<std::string>>(
7579
node, "exclude_services", record_options.exclude_service_events);
7680
optional_assign<std::string>(node, "node_prefix", record_options.node_prefix);

rosbag2_transport/src/rosbag2_transport/topic_filter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ bool TopicFilter::take_topic(
170170
}
171171
}
172172

173+
if (topic_type_in_list(topic_type, record_options_.exclude_topic_types)) {
174+
return false;
175+
}
176+
173177
if (topic_in_list(topic_name, record_options_.exclude_topics)) {
174178
return false;
175179
}

rosbag2_transport/test/resources/recorder_node_params.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ recorder_params_node:
99
is_discovery_disabled: true
1010
topics: ["topic", "other_topic"]
1111
topic_types: ["std_msgs/msg/Header", "geometry_msgs/msg/Pose"]
12+
exclude_topic_types: ["sensor_msgs/msg/Image"]
1213
services: ["service", "other_service"]
1314
rmw_serialization_format: "cdr"
1415
topic_polling_interval:
@@ -41,4 +42,4 @@ recorder_params_node:
4142
snapshot_mode: false
4243
custom_data: ["key1=value1", "key2=value2"]
4344
start_time_ns: 0
44-
end_time_ns: 100000
45+
end_time_ns: 100000

rosbag2_transport/test/rosbag2_transport/test_composable_recorder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ TEST_P(ComposableRecorderTests, recorder_can_parse_parameters_from_file) {
216216
EXPECT_EQ(record_options.topics, topics);
217217
std::vector<std::string> topic_types {"std_msgs/msg/Header", "geometry_msgs/msg/Pose"};
218218
EXPECT_EQ(record_options.topic_types, topic_types);
219+
std::vector<std::string> exclude_topic_types {"sensor_msgs/msg/Image"};
220+
EXPECT_EQ(record_options.exclude_topic_types, exclude_topic_types);
219221
std::vector<std::string> services {"/service/_service_event", "/other_service/_service_event"};
220222
EXPECT_EQ(record_options.services, services);
221223
EXPECT_EQ(record_options.rmw_serialization_format, "cdr");

0 commit comments

Comments
 (0)