Fix mypy unreachable warning in IMU update

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

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

Loading…
Cancel
Save