Fix mypy unreachable warning in IMU update

pull/36086/head
Srikanth6469 1 month ago
parent 8576403e41
commit f6ed11863e
  1. 20
      tools/sim/lib/common.py

@ -1,13 +1,10 @@
import math
import multiprocessing
import numpy as np
from abc import ABC, abstractmethod
from collections import namedtuple
W, H = 1928, 1208
vec3 = namedtuple("vec3", ["x", "y", "z"])
class GPSState:
@ -59,21 +56,19 @@ class SimulatorState:
@property
def speed(self):
return math.sqrt(self.velocity.x ** 2 + self.velocity.y ** 2 + self.velocity.z ** 2)
sim_state = SimulatorState()
sim_state.velocity = vec3(3.25, 10.50, 0)
sim_state.bearing = 72.51
sim_state.steering_angle = 7.87
sim_state.bearing = 72.51
sim_state.steering_angle = 7.87
class World(ABC):
def __init__(self, dual_camera):
self.dual_camera = dual_camera
self.image_lock = multiprocessing.Semaphore(value=0)
self.road_image = np.zeros((H, W, 3), dtype=np.uint8)
self.wide_road_image = np.zeros((H, W, 3), dtype=np.uint8)
self.exit_event = multiprocessing.Event()
@abstractmethod
@ -109,10 +104,8 @@ class World(ABC):
import time
now = time.monotonic()
imu = simulator_state.imu
v = simulator_state.velocity or vec3(0.0, 0.0, 0.0)
bearing_rad = math.radians(simulator_state.bearing or 0.0)
v = simulator_state.velocity if simulator_state.velocity is not None else vec3(0.0, 0.0, 0.0)
bearing_rad = math.radians(simulator_state.bearing)
prev = getattr(self, "_imu_prev", None)
if prev is None:
imu.accelerometer = vec3(0.0, 0.0, 0.0)
@ -122,16 +115,13 @@ class World(ABC):
dvx = v.x - prev["vx"]
dvy = v.y - prev["vy"]
dvz = v.z - prev["vz"]
ax = dvx / dt
ay = dvy / dt
az = dvz / dt
db = (bearing_rad - prev["bearing"] + math.pi) % (2 * math.pi) - math.pi
yaw_rate = db / dt
imu.accelerometer = vec3(ax, ay, az)
imu.gyroscope = vec3(0.0, 0.0, yaw_rate)
imu.bearing = bearing_rad
self._imu_prev = {"t": now, "vx": v.x, "vy": v.y, "vz": v.z, "bearing": bearing_rad}

Loading…
Cancel
Save