Skip to content

Commit f26569b

Browse files
committed
Merge remote-tracking branch 'upstream/master' into gm-set-safetymodel
2 parents 678211f + 8270c1c commit f26569b

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

cereal

release/files_common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ pyextra/.gitignore
414414
pyextra/acados_template/**
415415

416416
rednose/**
417+
laika/**
417418

418419
cereal/.gitignore
419420
cereal/__init__.py

selfdrive/car/tesla/values.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CAR:
2222
FINGERPRINTS = {
2323
CAR.AP2_MODELS: [
2424
{
25-
1: 8, 3: 8, 14: 8, 21: 4, 69: 8, 109: 4, 257: 3, 264: 8, 277: 6, 280: 6, 293: 4, 296: 4, 309: 5, 325: 8, 328: 5, 336: 8, 341: 8, 360: 7, 373: 8, 389: 8, 415: 8, 513: 5, 516: 8, 518: 8, 520: 4, 522: 8, 524: 8, 526: 8, 532: 3, 536: 8, 537: 3, 538: 8, 542: 8, 551: 5, 552: 2, 556: 8, 558: 8, 568: 8, 569: 8, 574: 8, 576: 3, 577: 8, 582: 5, 583: 8, 584: 4, 585: 8, 590: 8, 601: 8, 606: 8, 608: 1, 622: 8, 627: 6, 638: 8, 641: 8, 643: 8, 692: 8, 693: 8, 695: 8, 696: 8, 697: 8, 699: 8, 700: 8, 701: 8, 702: 8, 703: 8, 704: 8, 708: 8, 709: 8, 710: 8, 711: 8, 712: 8, 728: 8, 744: 8, 760: 8, 772: 8, 775: 8, 776: 8, 777: 8, 778: 8, 782: 8, 788: 8, 791: 8, 792: 8, 796: 2, 797: 8, 798: 6, 799: 8, 804: 8, 805: 8, 807: 8, 808: 1, 811: 8, 812: 8, 813: 8, 814: 5, 815: 8, 820: 8, 823: 8, 824: 8, 829: 8, 830: 5, 836: 8, 840: 8, 845: 8, 846: 5, 848: 8, 852: 8, 853: 8, 856: 4, 857: 6, 861: 8, 862: 5, 872: 8, 876: 8, 877: 8, 879: 8, 880: 8, 882: 8, 884: 8, 888: 8, 893: 8, 894: 8, 901: 6, 904: 3, 905: 8, 906: 8, 908: 2, 909: 8, 910: 8, 912: 8, 920: 8, 921: 8, 925: 4, 926: 6, 936: 8, 941: 8, 949: 8, 952: 8, 953: 6, 968: 8, 969: 6, 970: 8, 971: 8, 977: 8, 984: 8, 987: 8, 990: 8, 1000: 8, 1001: 8, 1006: 8, 1007: 8, 1008: 8, 1010: 6, 1014: 1, 1015: 8, 1016: 8, 1017: 8, 1018: 8, 1020: 8, 1026: 8, 1028: 8, 1029: 8, 1030: 8, 1032: 1, 1033: 1, 1034: 8, 1048: 1, 1049: 8, 1061: 8, 1064: 8, 1065: 8, 1070: 8, 1080: 8, 1081: 8, 1097: 8, 1113: 8, 1129: 8, 1145: 8, 1160: 4, 1177: 8, 1281: 8, 1328: 8, 1329: 8, 1332: 8, 1335: 8, 1337: 8, 1353: 8, 1368: 8, 1412: 8, 1436: 8, 1476: 8, 1481: 8, 1497: 8, 1513: 8, 1519: 8, 1601: 8, 1605: 8, 1617: 8, 1621: 8, 1625: 8, 1800: 4, 1804: 8, 1812: 8, 1815: 8, 1816: 8, 1824: 8, 1828: 8, 1831: 8, 1832: 8, 1840: 8, 1848: 8, 1864: 8, 1880: 8, 1892: 8, 1896: 8, 1912: 8, 1960: 8, 1992: 8, 2008: 3, 2015: 8, 2043: 5, 2045: 4
25+
1: 8, 3: 8, 14: 8, 21: 4, 69: 8, 109: 4, 257: 3, 264: 8, 277: 6, 280: 6, 293: 4, 296: 4, 309: 5, 325: 8, 328: 5, 336: 8, 341: 8, 360: 7, 373: 8, 389: 8, 415: 8, 513: 5, 516: 8, 518: 8, 520: 4, 522: 8, 524: 8, 526: 8, 532: 3, 536: 8, 537: 3, 538: 8, 542: 8, 551: 5, 552: 2, 556: 8, 558: 8, 568: 8, 569: 8, 574: 8, 576: 3, 577: 8, 582: 5, 583: 8, 584: 4, 585: 8, 590: 8, 601: 8, 606: 8, 608: 1, 622: 8, 627: 6, 638: 8, 641: 8, 643: 8, 692: 8, 693: 8, 695: 8, 696: 8, 697: 8, 699: 8, 700: 8, 701: 8, 702: 8, 703: 8, 704: 8, 708: 8, 709: 8, 710: 8, 711: 8, 712: 8, 728: 8, 744: 8, 760: 8, 772: 8, 775: 8, 776: 8, 777: 8, 778: 8, 782: 8, 788: 8, 791: 8, 792: 8, 796: 2, 797: 8, 798: 6, 799: 8, 804: 8, 805: 8, 807: 8, 808: 1, 811: 8, 812: 8, 813: 8, 814: 5, 815: 8, 820: 8, 823: 8, 824: 8, 829: 8, 830: 5, 836: 8, 840: 8, 845: 8, 846: 5, 848: 8, 852: 8, 853: 8, 856: 4, 857: 6, 861: 8, 862: 5, 872: 8, 876: 8, 877: 8, 879: 8, 880: 8, 882: 8, 884: 8, 888: 8, 893: 8, 894: 8, 901: 6, 904: 3, 905: 8, 906: 8, 908: 2, 909: 8, 910: 8, 912: 8, 920: 8, 921: 8, 925: 4, 926: 6, 936: 8, 941: 8, 949: 8, 952: 8, 953: 6, 968: 8, 969: 6, 970: 8, 971: 8, 977: 8, 984: 8, 987: 8, 990: 8, 1000: 8, 1001: 8, 1006: 8, 1007: 8, 1008: 8, 1010: 6, 1014: 1, 1015: 8, 1016: 8, 1017: 8, 1018: 8, 1020: 8, 1026: 8, 1028: 8, 1029: 8, 1030: 8, 1032: 1, 1033: 1, 1034: 8, 1048: 1, 1049: 8, 1061: 8, 1064: 8, 1065: 8, 1070: 8, 1080: 8, 1081: 8, 1097: 8, 1113: 8, 1129: 8, 1145: 8, 1160: 4, 1177: 8, 1281: 8, 1328: 8, 1329: 8, 1332: 8, 1335: 8, 1337: 8, 1353: 8, 1368: 8, 1412: 8, 1436: 8, 1476: 8, 1481: 8, 1497: 8, 1513: 8, 1519: 8, 1601: 8, 1605: 8, 1617: 8, 1621: 8, 1625: 8, 1665: 8, 1800: 4, 1804: 8, 1812: 8, 1815: 8, 1816: 8, 1824: 8, 1828: 8, 1831: 8, 1832: 8, 1840: 8, 1848: 8, 1864: 8, 1880: 8, 1892: 8, 1896: 8, 1912: 8, 1960: 8, 1992: 8, 2008: 3, 2015: 8, 2043: 5, 2045: 4
2626
},
2727
],
2828
CAR.AP1_MODELS: [

selfdrive/locationd/laikad.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ def __init__(self, valid_const=("GPS", "GLONASS"), auto_update=False, valid_ephe
3939
self.save_ephemeris = save_ephemeris
4040
self.load_cache()
4141
self.posfix_functions = {constellation: get_posfix_sympy_fun(constellation) for constellation in (ConstellationId.GPS, ConstellationId.GLONASS)}
42-
self.last_pos_fix = last_known_position
42+
self.last_pos_fix = last_known_position if last_known_position is not None else []
43+
self.last_pos_residual = []
44+
self.last_pos_fix_t = None
4345

4446
def load_cache(self):
4547
cache = Params().get(EPHEMERIS_CACHE)
@@ -62,23 +64,26 @@ def cache_ephemeris(self, t: GPSTime):
6264

6365
def process_ublox_msg(self, ublox_msg, ublox_mono_time: int, block=False):
6466
if ublox_msg.which == 'measurementReport':
67+
t = ublox_mono_time * 1e-9
6568
report = ublox_msg.measurementReport
6669
if report.gpsWeek > 0:
6770
latest_msg_t = GPSTime(report.gpsWeek, report.rcvTow)
6871
self.fetch_orbits(latest_msg_t + SECS_IN_MIN, block)
72+
6973
new_meas = read_raw_ublox(report)
7074
processed_measurements = process_measurements(new_meas, self.astro_dog)
7175

72-
min_measurements = 5 if any(p.constellation_id == ConstellationId.GLONASS for p in processed_measurements) else 4
73-
pos_fix, pos_fix_residual = calc_pos_fix_gauss_newton(processed_measurements, self.posfix_functions, min_measurements=min_measurements)
74-
if len(pos_fix) > 0:
75-
self.last_pos_fix = pos_fix[:3]
76-
est_pos = self.last_pos_fix
76+
if self.last_pos_fix_t is None or abs(self.last_pos_fix_t - t) >= 2:
77+
min_measurements = 5 if any(p.constellation_id == ConstellationId.GLONASS for p in processed_measurements) else 4
78+
pos_fix, pos_fix_residual = calc_pos_fix_gauss_newton(processed_measurements, self.posfix_functions, min_measurements=min_measurements)
79+
if len(pos_fix) > 0:
80+
self.last_pos_fix = pos_fix[:3]
81+
self.last_pos_residual = pos_fix_residual
82+
self.last_pos_fix_t = t
7783

78-
corrected_measurements = correct_measurements(processed_measurements, est_pos, self.astro_dog) if est_pos is not None else []
84+
corrected_measurements = correct_measurements(processed_measurements, self.last_pos_fix, self.astro_dog) if self.last_pos_fix_t is not None else []
7985

80-
t = ublox_mono_time * 1e-9
81-
self.update_localizer(est_pos, t, corrected_measurements)
86+
self.update_localizer(self.last_pos_fix, t, corrected_measurements)
8287
kf_valid = all(self.kf_valid(t))
8388
ecef_pos = self.gnss_kf.x[GStates.ECEF_POS].tolist()
8489
ecef_vel = self.gnss_kf.x[GStates.ECEF_VELOCITY].tolist()
@@ -94,7 +99,7 @@ def process_ublox_msg(self, ublox_msg, ublox_mono_time: int, block=False):
9499
"gpsTimeOfWeek": report.rcvTow,
95100
"positionECEF": measurement_msg(value=ecef_pos, std=pos_std, valid=kf_valid),
96101
"velocityECEF": measurement_msg(value=ecef_vel, std=vel_std, valid=kf_valid),
97-
"positionFixECEF": measurement_msg(value=pos_fix, std=pos_fix_residual, valid=len(pos_fix) > 0),
102+
"positionFixECEF": measurement_msg(value=self.last_pos_fix, std=self.last_pos_residual, valid=self.last_pos_fix_t == t),
98103
"ubloxMonoTime": ublox_mono_time,
99104
"correctedMeasurements": meas_msgs
100105
}
@@ -116,7 +121,7 @@ def update_localizer(self, est_pos, t: float, measurements: List[GNSSMeasurement
116121
cloudlog.error("Time gap of over 10s detected, gnss kalman reset")
117122
elif not valid[2]:
118123
cloudlog.error("Gnss kalman filter state is nan")
119-
if est_pos is not None:
124+
if len(est_pos) > 0:
120125
cloudlog.info(f"Reset kalman filter with {est_pos}")
121126
self.init_gnss_localizer(est_pos)
122127
else:
@@ -211,13 +216,13 @@ def kf_add_observations(gnss_kf: GNSSKalman, t: float, measurements: List[GNSSMe
211216
m_arr = m.as_array()
212217
if m.constellation_id == ConstellationId.GPS:
213218
ekf_data[ObservationKind.PSEUDORANGE_GPS].append(m_arr)
214-
ekf_data[ObservationKind.PSEUDORANGE_RATE_GPS].append(m_arr)
215219
elif m.constellation_id == ConstellationId.GLONASS:
216220
ekf_data[ObservationKind.PSEUDORANGE_GLONASS].append(m_arr)
217-
ekf_data[ObservationKind.PSEUDORANGE_RATE_GLONASS].append(m_arr)
218-
221+
ekf_data[ObservationKind.PSEUDORANGE_RATE_GPS] = ekf_data[ObservationKind.PSEUDORANGE_GPS]
222+
ekf_data[ObservationKind.PSEUDORANGE_RATE_GLONASS] = ekf_data[ObservationKind.PSEUDORANGE_GLONASS]
219223
for kind, data in ekf_data.items():
220-
gnss_kf.predict_and_observe(t, kind, data)
224+
if len(data) >0:
225+
gnss_kf.predict_and_observe(t, kind, data)
221226

222227

223228
class CacheSerializer(json.JSONEncoder):

selfdrive/locationd/models/gnss_helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import numpy as np
2+
from laika.raw_gnss import GNSSMeasurement
23

34
def parse_prr(m):
4-
from laika.raw_gnss import GNSSMeasurement
55
sat_pos_vel_i = np.concatenate((m[GNSSMeasurement.SAT_POS],
66
m[GNSSMeasurement.SAT_VEL]))
77
R_i = np.atleast_2d(m[GNSSMeasurement.PRR_STD]**2)
88
z_i = m[GNSSMeasurement.PRR]
99
return z_i, R_i, sat_pos_vel_i
1010

11-
1211
def parse_pr(m):
13-
from laika.raw_gnss import GNSSMeasurement
1412
pseudorange = m[GNSSMeasurement.PR]
1513
pseudorange_stdev = m[GNSSMeasurement.PR_STD]
1614
sat_pos_freq_i = np.concatenate((m[GNSSMeasurement.SAT_POS],

selfdrive/ui/qt/onroad.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,28 @@ NvgWindow::NvgWindow(VisionStreamType type, QWidget* parent) : fps_filter(UI_FRE
172172
void NvgWindow::updateState(const UIState &s) {
173173
const int SET_SPEED_NA = 255;
174174
const SubMaster &sm = *(s.sm);
175+
176+
const bool cs_alive = sm.alive("controlsState");
177+
const bool nav_alive = sm.alive("navInstruction") && sm["navInstruction"].getValid();
178+
175179
const auto cs = sm["controlsState"].getControlsState();
176180

177-
float set_speed = cs.getVCruise();
181+
float set_speed = cs_alive ? cs.getVCruise() : SET_SPEED_NA;
178182
bool cruise_set = set_speed > 0 && (int)set_speed != SET_SPEED_NA;
179183
if (cruise_set && !s.scene.is_metric) {
180184
set_speed *= KM_TO_MILE;
181185
}
182-
float cur_speed = std::max(0.0, sm["carState"].getCarState().getVEgo() * (s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH));
186+
187+
float cur_speed = cs_alive ? std::max<float>(0.0, sm["carState"].getCarState().getVEgo()) : 0.0;
188+
cur_speed *= s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH;
183189

184190
auto speed_limit_sign = sm["navInstruction"].getNavInstruction().getSpeedLimitSign();
185-
float speed_limit = sm["navInstruction"].getValid() ? sm["navInstruction"].getNavInstruction().getSpeedLimit() : 0.0;
191+
float speed_limit = nav_alive ? sm["navInstruction"].getNavInstruction().getSpeedLimit() : 0.0;
186192
speed_limit *= (s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH);
187193

188194
setProperty("speedLimit", speed_limit);
189-
setProperty("has_us_speed_limit", sm["navInstruction"].getValid() && speed_limit_sign == cereal::NavInstruction::SpeedLimitSign::MUTCD);
190-
setProperty("has_eu_speed_limit", sm["navInstruction"].getValid() && speed_limit_sign == cereal::NavInstruction::SpeedLimitSign::VIENNA);
195+
setProperty("has_us_speed_limit", nav_alive && speed_limit_sign == cereal::NavInstruction::SpeedLimitSign::MUTCD);
196+
setProperty("has_eu_speed_limit", nav_alive && speed_limit_sign == cereal::NavInstruction::SpeedLimitSign::VIENNA);
191197

192198
setProperty("is_cruise_set", cruise_set);
193199
setProperty("speed", cur_speed);

tools/sim/Dockerfile.sim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ COPY ./third_party $HOME/openpilot/third_party
1818
COPY ./pyextra $HOME/openpilot/pyextra
1919
COPY ./site_scons $HOME/openpilot/site_scons
2020
COPY ./rednose $HOME/openpilot/rednose
21+
COPY ./laika $HOME/openpilot/laika
2122
COPY ./common $HOME/openpilot/common
2223
COPY ./opendbc $HOME/openpilot/opendbc
2324
COPY ./cereal $HOME/openpilot/cereal

0 commit comments

Comments
 (0)