Skip to content

Commit

Permalink
Test Record Bag
Browse files Browse the repository at this point in the history
  • Loading branch information
drago314 committed Nov 9, 2024
1 parent a38b238 commit 131c701
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ __pycache__

.config
.env
.vscode
.vscode
.bag

This comment has been minimized.

Copy link
@maxwellmlin

maxwellmlin Nov 10, 2024

Member

Should this be .mcap?

This comment has been minimized.

Copy link
@maxwellmlin

maxwellmlin Nov 10, 2024

Member

Actually, let's ignore all bag_files.

3 changes: 2 additions & 1 deletion onboard/src/system_utils/launch/record_bag.launch
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<launch>
<arg name="enable_recording" default="true" />
<node name="record_bag" pkg="system_utils" type="record_bag.py" output="screen">
<param name="enable_recording" value="$(arg enable_recording)" />
<param name="bypass" value="$(var bypass)" />
<param name="enable_recording" value="$(var enable_recording)" />
</node>
</launch>
16 changes: 12 additions & 4 deletions onboard/src/system_utils/system_utils/record_bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ def __init__(self):

# Initialize variables
self.process = None
bypass = self.declare_parameter('bypass', False).value
self.get_logger().info(f"bypass: {bypass}")
self.enable_recording = self.declare_parameter('enable_recording', False).value

# Initialize last message time to current time
self.last_msg_time = Clock().now()

# Subscribe to the voltage topic
self.create_subscription(Float64, 'sensors/voltage', self.voltage_callback, 10)
if bypass:
self.start_recording()
else:
self.create_subscription(Float64, 'sensors/voltage', self.voltage_callback, 10)

# Create a timer to check for timeout; calls check_timeout every second
self.timer = self.create_timer(1, self.check_timeout)
Expand Down Expand Up @@ -58,7 +64,7 @@ def voltage_callback(self, data: Float64):

# If voltage is above 5V and the node is not currently recording, start recording
else:
if self.process is None:
if self.process is None and self.enable_recording:
self.start_recording()

def start_recording(self):
Expand Down Expand Up @@ -103,7 +109,7 @@ def check_timeout(self):
current_time = Clock().now()
if (current_time - self.last_msg_time) > self.TIMEOUT_DURATION:
if self.process is not None:
self.get_logger().info(f"No voltage messages received for {self.TIMEOUT_DURATION.to_sec()} seconds. "
self.get_logger().info(f"No voltage messages received for {self.TIMEOUT_DURATION.nanoseconds / 1e9} seconds. "
f"Stopping recording.")
self.stop_recording()
self.shutdown_node()
Expand All @@ -126,7 +132,9 @@ def main(args=None):
pass
finally:
recorder.stop_recording()
recorder.get_logger().info("Shutting down. Stopping recording.")
if rclpy.ok():
recorder.get_logger().info("Shutting down. Stopping recording.")

recorder.destroy_node()
if rclpy.ok():
rclpy.shutdown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self):
super().__init__(self.NODE_NAME)
self._pub = self.create_publisher(SystemUsage, self.TOPIC_NAME, 10)
self._current_msg = SystemUsage()
self.run()

def get_cpu(self):
self._current_msg.cpu_percent = psutil.cpu_percent(interval=0.5)
Expand Down Expand Up @@ -46,16 +47,18 @@ def get_disk(self):
self._current_msg.disk.percentage = psutil.disk_usage('/').percent

def run(self):
r = self.create_rate(15)
while not rclpy.ok():
def timer_callback():
if rclpy.ok():
timer.cancel()
self._current_msg = SystemUsage()
self.get_cpu()
# self.get_gpu()
self.get_ram()
self.get_disk()

self._pub.publish(self._current_msg)
r.sleep()

timer = self.create_timer(1/15.0, timer_callback)

def main(args=None):
rclpy.init(args=args)
Expand Down

0 comments on commit 131c701

Please sign in to comment.