Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions selfdrive/ui/mici/layouts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def _setup_callbacks(self):
self._onroad_layout.set_click_callback(lambda: self._scroll_to(self._home_layout))
device.add_interactive_timeout_callback(self._on_interactive_timeout)

def show_event(self):
self._scroller.show_event()

def hide_event(self):
self._scroller.hide_event()

def _scroll_to(self, layout: Widget):
layout_x = int(layout.rect.x)
self._scroller.scroll_to(layout_x, smooth=True)
Expand Down
26 changes: 24 additions & 2 deletions selfdrive/ui/mici/layouts/settings/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,27 @@
from openpilot.selfdrive.ui.lib.prime_state import PrimeType
from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.widgets.nav_widget import NavWidget
from openpilot.system.ui.lib.wifi_manager import WifiManager, Network, MeteredType, ConnectStatus, normalize_ssid
from openpilot.system.ui.lib.wifi_manager import WifiManager, Network, MeteredType, ConnectStatus, SecurityType, normalize_ssid


class WifiNetworkButton(BigButton):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._lock_txt = gui_app.texture("icons_mici/settings/network/new/lock.png", 28, 36)
self._draw_lock = False

def set_draw_lock(self, draw: bool):
self._draw_lock = draw

def _draw_content(self, btn_y: float):
super()._draw_content(btn_y)
# Render lock icon at lower right of wifi icon if secured
if self._draw_lock:
icon_x = self._rect.x + self._rect.width - 30 - self._txt_icon.width
icon_y = btn_y + 30
lock_x = icon_x + self._txt_icon.width - self._lock_txt.width + 7
lock_y = icon_y + self._txt_icon.height - self._lock_txt.height + 8
rl.draw_texture_ex(self._lock_txt, (lock_x, lock_y), 0.0, 1.0, rl.WHITE)


class NetworkLayoutMici(NavWidget):
Expand Down Expand Up @@ -68,7 +88,7 @@ def network_metered_callback(value: str):
self._wifi_medium_txt = gui_app.texture("icons_mici/settings/network/wifi_strength_medium.png", 64, 47)
self._wifi_full_txt = gui_app.texture("icons_mici/settings/network/wifi_strength_full.png", 64, 47)

self._wifi_button = BigButton("wi-fi", "not connected", self._wifi_slash_txt, scroll=True)
self._wifi_button = WifiNetworkButton("wi-fi", "not connected", self._wifi_slash_txt, scroll=True)
self._wifi_button.set_click_callback(lambda: gui_app.push_widget(self._wifi_ui))

# ******** Advanced settings ********
Expand Down Expand Up @@ -131,8 +151,10 @@ def _update_state(self):
if display_network is not None:
strength = WifiIcon.get_strength_icon_idx(display_network.strength)
self._wifi_button.set_icon(self._wifi_full_txt if strength == 2 else self._wifi_medium_txt if strength == 1 else self._wifi_low_txt)
self._wifi_button.set_draw_lock(display_network.security_type not in (SecurityType.OPEN, SecurityType.UNSUPPORTED))
else:
self._wifi_button.set_icon(self._wifi_slash_txt)
self._wifi_button.set_draw_lock(False)

def show_event(self):
super().show_event()
Expand Down
3 changes: 3 additions & 0 deletions selfdrive/ui/mici/layouts/settings/network/wifi_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def network(self) -> Network:

@property
def _show_forget_btn(self):
if self._network.is_tethering:
return False

return (self._is_saved and not self._wrong_password) or self._is_connecting

def _handle_mouse_release(self, mouse_pos: MousePos):
Expand Down
8 changes: 5 additions & 3 deletions system/ui/lib/wifi_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,19 @@ class Network:
ssid: str
strength: int
security_type: SecurityType
is_tethering: bool

@classmethod
def from_dbus(cls, ssid: str, aps: list["AccessPoint"]) -> "Network":
def from_dbus(cls, ssid: str, aps: list["AccessPoint"], is_tethering: bool) -> "Network":
# we only want to show the strongest AP for each Network/SSID
strongest_ap = max(aps, key=lambda ap: ap.strength)
security_type = get_security_type(strongest_ap.flags, strongest_ap.wpa_flags, strongest_ap.rsn_flags)

return cls(
ssid=ssid,
strength=strongest_ap.strength,
strength=100 if is_tethering else strongest_ap.strength,
security_type=security_type,
is_tethering=is_tethering,
)


Expand Down Expand Up @@ -820,7 +822,7 @@ def worker():
# catch all for parsing errors
cloudlog.exception(f"Failed to parse AP properties for {ap_path}")

networks = [Network.from_dbus(ssid, ap_list) for ssid, ap_list in aps.items()]
networks = [Network.from_dbus(ssid, ap_list, ssid == self._tethering_ssid) for ssid, ap_list in aps.items()]
networks.sort(key=lambda n: (n.ssid != self._wifi_state.ssid, not self.is_connection_saved(n.ssid), -n.strength, n.ssid.lower()))
self._networks = networks

Expand Down
7 changes: 6 additions & 1 deletion system/ui/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,12 @@ def _render(self, _):
# draw black fade on left and right
fade_width = 20
rl.draw_rectangle_gradient_h(int(self._rect.x + self._rect.width - fade_width), int(self._rect.y), fade_width, int(self._rect.height), rl.BLANK, rl.BLACK)
if self._scroll_state != ScrollState.STARTING:

# stop drawing left fade once text scrolls past
text_width = visible_sizes[0].x if visible_sizes else 0
first_copy_in_view = self._scroll_offset + text_width > 0
draw_left_fade = self._scroll_state != ScrollState.STARTING and first_copy_in_view
if draw_left_fade:
rl.draw_rectangle_gradient_h(int(self._rect.x), int(self._rect.y), fade_width, int(self._rect.height), rl.BLACK, rl.BLANK)

rl.end_scissor_mode()
Expand Down
33 changes: 32 additions & 1 deletion tools/sim/bridge/metadrive/metadrive_world.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ctypes
import functools
import math
import multiprocessing
import numpy as np
import time
Expand All @@ -9,7 +10,7 @@
from openpilot.tools.sim.bridge.common import QueueMessage, QueueMessageType
from openpilot.tools.sim.bridge.metadrive.metadrive_process import (metadrive_process, metadrive_simulation_state,
metadrive_vehicle_state)
from openpilot.tools.sim.lib.common import SimulatorState, World
from openpilot.tools.sim.lib.common import SimulatorState, World, vec3
from openpilot.tools.sim.lib.camerad import W, H


Expand Down Expand Up @@ -58,6 +59,10 @@ def __init__(self, status_q, config, test_duration, test_run, dual_camera=False)
self.reset_time = 0
self.should_reset = False

self.prev_velocity = None
self.prev_bearing = 0.0
self.prev_sensor_time = time.monotonic()

def apply_controls(self, steer_angle, throttle_out, brake_out):
if (time.monotonic() - self.reset_time) > 2:
self.vc[0] = steer_angle
Expand Down Expand Up @@ -91,6 +96,32 @@ def read_sensors(self, state: SimulatorState):
state.gps.from_xy(curr_pos)
state.valid = True

# Derive IMU sensor values from vehicle state changes
now = time.monotonic()
dt = now - self.prev_sensor_time
state.imu.bearing = md_vehicle.bearing

if dt > 0 and self.prev_velocity is not None:
# Accelerometer: derivative of velocity + gravity on z-axis
state.imu.accelerometer = vec3(
(md_vehicle.velocity.x - self.prev_velocity.x) / dt,
(md_vehicle.velocity.y - self.prev_velocity.y) / dt,
-9.81
)

# Gyroscope: yaw rate from bearing change (bearing is in degrees)
dbearing = md_vehicle.bearing - self.prev_bearing
if dbearing > 180:
dbearing -= 360
elif dbearing < -180:
dbearing += 360
yaw_rate = math.radians(dbearing) / dt
state.imu.gyroscope = vec3(0, 0, yaw_rate)

self.prev_velocity = md_vehicle.velocity
self.prev_bearing = md_vehicle.bearing
self.prev_sensor_time = now

is_engaged = state.is_engaged
if is_engaged and self.first_engage is None:
self.first_engage = time.monotonic()
Expand Down
Loading