Skip to content

Commit 9dc8b0f

Browse files
authored
Aj/metrics recording (#314)
* Create bag directory if does not exist * Fix typo in reading launch arg * Add bags to launch file * Add RECORD_BAGS env variable to toggle record bags from launch * Add docs for bag logging
1 parent addc846 commit 9dc8b0f

File tree

11 files changed

+55
-10
lines changed

11 files changed

+55
-10
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ BEHAVIOR_LAUNCH_FILE="behavior.launch.xml"
6363
# offboard API streaming out. this is so that ports don't conflict for multi-agent FCU communication
6464
OFFBOARD_BASE_PORT=14540
6565
ONBOARD_BASE_PORT=14580
66+
67+
RECORD_BAGS="false" # "true" or "false"
6668
# ===============================================
6769

6870
# =========== GROUND CONTROL STATION ============

common/ros_packages/bag_recorder_pid/bag_record_pid/bag_record_node.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ def __init__(self):
3737
self.active = False
3838
self.cfg = yaml.safe_load(open(self.cfg_path))
3939

40-
# Exit if it does not exist.
40+
# Create output directory if it doesn't exist
4141
if not os.path.exists(self.output_dir):
42-
self.get_logger().error(f"Output directory {self.output_dir} does not exist.")
43-
rclpy.shutdown()
44-
return
42+
self.get_logger().info(f"Output directory {self.output_dir} does not exist. Creating it.")
43+
os.makedirs(self.output_dir, exist_ok=True)
4544
os.chdir(self.output_dir)
4645

4746
self.command_prefix = ["ros2", "bag", "record", "-s", "mcap"]

docs/robot/logging/index.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
# Logging
1+
# Logging
2+
3+
## Bag Recording
4+
5+
AirStack provides automated bag recording capabilities for capturing ROS2 topic data during flights. The main node for bag recording is located at [common/ros_packages/bag_recorder_pid](../../common/ros_packages/bag_recorder_pid). For detailed configuration options and implementation details, please consult the README in that directory.
6+
7+
### Enabling Bag Recording
8+
9+
To enable bag recording, prepend `RECORD_BAGS=true` to the airstack up command:
10+
11+
```bash
12+
RECORD_BAGS=true airstack up robot
13+
```
14+
15+
The BehaviorTree will automatically trigger topic recording once the drone takes off. Recorded bags will appear in the `./robot/bags` directory.

gcs/bags/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# list of all ros2 bag files to ignore
2+
*.mcap
3+
*.mcap.index
4+
*.mcap.meta
5+
*.mcap.bag
6+
*.mcap.bag.index
7+
*.mcap.bag.meta
8+
*.db3
9+
*.db3.index
10+
*.db3.meta
11+
*.yaml

gcs/docker/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ services:
2323
service: gcs-base
2424
network_mode: host
2525
volumes:
26-
- $HOME/bags/:/bags
26+
- $HOME/bags:/bags
2727
- ../../robot/ros_ws/src/robot_bringup/rviz/:/bags/rviz
2828
- ../../plot:/plot

gcs/docker/gcs-base-docker-compose.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@ services:
5050
# autonomy stack stuff
5151
- ../..:/root/AirStack
5252
- ../../common/ros_packages:/root/AirStack/gcs/ros_ws/src/common:rw # common ROS packages
53-
- ../../common/ros_packages/fastdds.xml:/root/AirStack/gcs/ros_ws/fastdds.xml:rw # fastdds.xml
53+
- ../../common/ros_packages/fastdds.xml:/root/AirStack/gcs/ros_ws/fastdds.xml:rw # fastdds.xml
54+
# bags
55+
- ../bags:/bags:rw

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ nav:
112112
- docs/robot/static_transforms/index.md
113113
- Logging:
114114
- docs/robot/logging/index.md
115+
- common/ros_packages/bag_recorder_pid/README.md
115116
- Ground Control Station:
116117
- docs/ground_control_station/index.md
117118
- Usage:

robot/bags/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# list of all ros2 bag files to ignore
2+
*.mcap
3+
*.mcap.index
4+
*.mcap.meta
5+
*.mcap.bag
6+
*.mcap.bag.index
7+
*.mcap.bag.meta
8+
*.db3
9+
*.db3.index
10+
*.db3.meta
11+
*.yaml

robot/docker/robot-base-docker-compose.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ services:
3535
- ONBOARD_BASE_PORT=${ONBOARD_BASE_PORT}
3636
# URDF Robot Description
3737
- ROBOT_URDF_FILE_PATH=${ROBOT_DESCRIPTION_PACKAGE}/urdf/${ROBOT_URDF_FILE}
38+
# Record bags
39+
- RECORD_BAGS=${RECORD_BAGS}
3840
deploy:
3941
# let it use the GPU
4042
resources:
@@ -59,4 +61,6 @@ services:
5961
- ../..:/root/AirStack
6062
- ../../common/ros_packages:/root/AirStack/robot/ros_ws/src/common:rw # common ROS packages
6163
- ../../common/ros_packages/fastdds.xml:/root/AirStack/robot/ros_ws/fastdds.xml:rw # fastdds.xml
64+
# bags
65+
- ../bags:/bags:rw
6266

robot/ros_ws/src/logging/logging_bringup/launch/logging.launch.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!-- LOGGING -->
22
<launch>
3+
<arg name="record_bag" default="false" />
34

4-
<group if="$(arg record_bag)">
5+
<group if="$(var record_bag)">
56
<node name="bag_record" pkg="bag_record_pid" exec="bag_record_node">
67
<param name="cfg_path" value="$(find-pkg-share logging_bringup)/config/log.yaml" />
78
<param name="output_dir" value="/bags" />

0 commit comments

Comments
 (0)