From 534fba94504de7f92499be03aa8216d79c2aed9b Mon Sep 17 00:00:00 2001 From: ATATC Date: Fri, 4 Oct 2024 18:57:34 -0400 Subject: [PATCH] Removed data from memory and supported `report_rate`. (#432) --- leads_vec_rc/cli.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/leads_vec_rc/cli.py b/leads_vec_rc/cli.py index d4342b6..c58c931 100644 --- a/leads_vec_rc/cli.py +++ b/leads_vec_rc/cli.py @@ -11,7 +11,7 @@ from leads import require_config, L, DataContainer from leads.comm import Service, Client, start_client, create_client, Callback, Connection, ConnectionBase -from leads.data_persistence import DataPersistence, Vector, CSV, DEFAULT_HEADER_FULL, VISUAL_HEADER_FULL +from leads.data_persistence import DataPersistence, CSV, DEFAULT_HEADER_FULL, VISUAL_HEADER_FULL from leads_vec_rc.config import Config config: Config = require_config() @@ -24,10 +24,6 @@ CAR_CENTER_OF_MASS: float = config.get("car_center_of_mass", .25) time_stamp_record: DataPersistence[int] = DataPersistence(2000) -speed_record: DataPersistence[float] = DataPersistence(2000) -acceleration_record: DataPersistence[Vector[float]] = DataPersistence(2000) -voltage_record: DataPersistence[float] = DataPersistence(2000) -gps_record: DataPersistence[Vector[float]] = DataPersistence(2000) csv: CSV | None = None @@ -37,7 +33,7 @@ def try_create_csv(data: dict[str, Any]) -> None: return csv = CSV(f"{config.data_dir}/{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}.csv", VISUAL_HEADER_FULL if set(VISUAL_HEADER_FULL).issubset(data.keys()) else DEFAULT_HEADER_FULL, - time_stamp_record, voltage_record, speed_record) + time_stamp_record) register(csv.close) @@ -70,6 +66,8 @@ def on_receive(self, service: Service, msg: bytes) -> None: try: d = loads(msg.decode()) mg = CAR_MASS * 2.451675 + d["report_rate"] = 1000 * num_ts / (time_stamp_record[-1] - time_stamp_record[0]) if (num_ts := len( + time_stamp_record)) > 1 else 0 f_forward = CAR_MASS * d["forward_acceleration"] * CAR_CENTER_OF_MASS * .5 / CAR_WIDTH f_lateral = CAR_MASS * d["lateral_acceleration"] * CAR_CENTER_OF_MASS * .5 / CAR_LENGTH d["cfc_fl"] = mg - f_lateral - f_forward @@ -77,16 +75,11 @@ def on_receive(self, service: Service, msg: bytes) -> None: d["cfc_rl"] = mg - f_lateral + f_forward d["cfc_rr"] = mg + f_lateral + f_forward self.current_data = d - acceleration_record.append(Vector(d["forward_acceleration"], d["lateral_acceleration"], - d["vertical_acceleration"])) - gps_record.append(Vector(d["latitude"], d["longitude"])) if config.save_data: try_create_csv(d) csv.write_frame(*(d[key] for key in csv.header())) else: time_stamp_record.append(int(d["t"])) - speed_record.append(d["speed"]) - voltage_record.append(d["voltage"]) except JSONDecodeError: pass @@ -124,11 +117,6 @@ async def time_stamp() -> list[int]: return time_stamp_record.to_list() -@app.get("/speed") -async def speed() -> list[float]: - return speed_record.to_list() - - @app.get("/time_lap") async def time_lap() -> str: callback.client.send(b"time_lap")