Files
kogger-transpondeur-continu/driver/log_add_diff.py
Poulpe 9a158f5c5f Initial: ContinuousTransponder wrapper for Kogger USBL
High-level Python wrapper around the upstream cosma-tech/kogger_acousticAntenna
driver. Configures a Kogger acoustic antenna as a permanent slave transponder
in a single start() call: address filter, echo filter, optional TDMA sync slot,
permanent response window, and Python callbacks for each ping received.

No modification to the upstream driver — only composes existing public methods
in the right order. Snapshot of upstream driver included read-only under driver/
for reference.

Includes:
- transponder_continu.py (302 lines): the wrapper class + CLI
- examples/auv_slave.py (79 lines): usage example with logging
- README.md: design rationale, usage, multi-AUV TDMA, watchdog, hardware wiring
- driver/: snapshot of cosma-tech/kogger_acousticAntenna at commit 1b539f9
  ('Add index slot for multi pinger', 2025-03-11)

Built for Cosma context (USV master + N AUVs slaves) following the design
conversation in Discord #ping-pong-ping (2026-04-27). See poulpe/ping-pong-ping
on Gitea for the interactive demo of the protocol.
2026-04-27 22:08:44 +00:00

52 lines
1.7 KiB
Python
Executable File

#! /usr/bin/env python
import csv
from datetime import datetime
def calculate_diff(input_file, output_file):
last_values = {}
output_rows = []
with open(input_file, 'r') as infile:
reader = csv.reader(infile)
for row in reader:
timestamp_str, metric, value_str = row
timestamp = datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S.%f')
value = float(value_str)
output_rows.append(row)
if metric in last_values:
last_timestamp, last_value = last_values[metric]
time_diff = (timestamp - last_timestamp).total_seconds()
if time_diff > 0:
value_diff = value - last_value
if metric in ["Azimuth", "Elev"]:
value_diff = (value_diff + 90) % 180 - 90
value_diff = value_diff / time_diff
output_rows.append([timestamp_str, f"{metric}_diff", f"{value_diff:.6f}"])
last_values[metric] = (timestamp, value)
with open(output_file, 'w', newline='') as outfile:
writer = csv.writer(outfile)
writer.writerows(output_rows)
if __name__ == "__main__":
import sys
if len(sys.argv) != 3 and len(sys.argv) != 2:
print("Usage: python process_log.py <input_file> <output_file>")
sys.exit(1)
input_file = sys.argv[1]
if sys.argv == 3:
output_file = sys.argv[2]
else:
name, extension = input_file.rsplit('.', 1)
# Add "_diff" to the name and then add the extension back
output_file = f"{name}_diff.{extension}"
print("Generate new diff file :"+str(output_file))
calculate_diff(input_file, output_file)