Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Add current time to log file #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions sw/log_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def log_decorator(fn, logfile="/tmp/log.csv"):
# Add the header line
cols = ["tick", "dt"] # Timing
cols = ["time", "tick", "dt"] # Timing
cols += ["x", "y", "vel_x", "vel_y"] # State
cols += ["pitch", "roll"] # Action
cols += ["status", "error_response"] # Error status
Expand All @@ -25,8 +25,9 @@ def log_decorator(fn, logfile="/tmp/log.csv"):
# Acts like a normal controller function
def decorated_fn(state):
nonlocal prev_time, tick
dt = time.time() - prev_time
prev_time = time.time()
now = time.time()
dt = now - prev_time
prev_time = now
tick += 1

# Run the actual controller
Expand All @@ -45,10 +46,10 @@ def decorated_fn(state):
# Deconstruct action
pitch, roll = action
# combine all to a list for the log
l = [tick, dt] + [x, y, vel_x, vel_y] + [pitch, roll] + [status, resp]
l = [now, tick, dt] + [x, y, vel_x, vel_y] + [pitch, roll] + [status, resp]

# combine all to a list for the log
# l = [tick, dt] + state + action + [status + resp]
# l = [now, tick, dt] + state + action + [status + resp]

# round floats to 5 digits
l = [f"{n:8.5f}" if type(n) is float else n for n in l]
Expand Down