mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-01 03:43:46 +08:00
cereal cleanup part 2 (#20092)
* car stuff * thermal * Revert "car stuff" This reverts commit 77fd1c65ebd01abfa8493ae12c9e6b14f7ada976. * panda state * camera stuff * start deg * most is building * builds * planner + controls run * fix up paramsd * cleanup * process replay passes * fix webcam build * camerad * no more frame * thermald * ui * paramsd * camera replay * fix long tests * fix camerad tests * maxSteeringAngle * bump cereal * more frame * cereal master old-commit-hash: 312b681a46b8153314a8420611b6479dd6f70dfc
This commit is contained in:
@@ -46,7 +46,7 @@ def steer_thread():
|
||||
if joystick is not None:
|
||||
axis_3 = clip(-joystick.testJoystick.axes[3] * 1.05, -1., 1.) # -1 to 1
|
||||
actuators.steer = axis_3
|
||||
actuators.steerAngle = axis_3 * 43. # deg
|
||||
actuators.steeringAngleDeg = axis_3 * 43. # deg
|
||||
axis_1 = clip(-joystick.testJoystick.axes[1] * 1.05, -1., 1.) # -1 to 1
|
||||
actuators.gas = max(axis_1, 0.)
|
||||
actuators.brake = max(-axis_1, 0.)
|
||||
@@ -67,7 +67,7 @@ def steer_thread():
|
||||
CC.actuators.gas = actuators.gas
|
||||
CC.actuators.brake = actuators.brake
|
||||
CC.actuators.steer = actuators.steer
|
||||
CC.actuators.steerAngle = actuators.steerAngle
|
||||
CC.actuators.steeringAngleDeg = actuators.steeringAngleDeg
|
||||
CC.hudControl.visualAlert = hud_alert
|
||||
CC.hudControl.setSpeed = 20
|
||||
CC.cruiseControl.cancel = pcm_cancel_cmd
|
||||
|
||||
@@ -98,8 +98,8 @@ void LogReader::mergeEvents(int dled) {
|
||||
|
||||
// hack
|
||||
// TODO: rewrite with callback
|
||||
if (event.which() == cereal::Event::ENCODE_IDX) {
|
||||
auto ee = event.getEncodeIdx();
|
||||
if (event.which() == cereal::Event::ROAD_ENCODE_IDX) {
|
||||
auto ee = event.getRoadEncodeIdx();
|
||||
eidx_local.insert(ee.getFrameId(), qMakePair(ee.getSegmentNum(), ee.getSegmentId()));
|
||||
}
|
||||
|
||||
|
||||
@@ -153,14 +153,14 @@ void Unlogger::process() {
|
||||
auto ee = msg.getRoot<cereal::Event>();
|
||||
ee.setLogMonoTime(nanos_since_boot());
|
||||
|
||||
if (e.which() == cereal::Event::FRAME) {
|
||||
auto fr = msg.getRoot<cereal::Event>().getFrame();
|
||||
if (e.which() == cereal::Event::ROAD_CAMERA_STATE) {
|
||||
auto fr = msg.getRoot<cereal::Event>().getRoadCameraState();
|
||||
|
||||
// TODO: better way?
|
||||
auto it = eidx.find(fr.getFrameId());
|
||||
if (it != eidx.end()) {
|
||||
auto pp = *it;
|
||||
//qDebug() << fr.getFrameId() << pp;
|
||||
//qDebug() << fr.getRoadCameraStateId() << pp;
|
||||
|
||||
if (frs->find(pp.first) != frs->end()) {
|
||||
auto frm = (*frs)[pp.first];
|
||||
|
||||
@@ -35,7 +35,7 @@ def ui_thread(addr, frame_address):
|
||||
|
||||
camera_surface = pygame.surface.Surface((_FULL_FRAME_SIZE[0] * SCALE, _FULL_FRAME_SIZE[1] * SCALE), 0, 24).convert()
|
||||
|
||||
frame = messaging.sub_sock('frame', conflate=True)
|
||||
frame = messaging.sub_sock('roadCameraState', conflate=True)
|
||||
|
||||
img = np.zeros((_FULL_FRAME_SIZE[1], _FULL_FRAME_SIZE[0], 3), dtype='uint8')
|
||||
imgff = np.zeros((_FULL_FRAME_SIZE[1], _FULL_FRAME_SIZE[0], 3), dtype=np.uint8)
|
||||
@@ -46,10 +46,10 @@ def ui_thread(addr, frame_address):
|
||||
|
||||
# ***** frame *****
|
||||
fpkt = messaging.recv_one(frame)
|
||||
yuv_img = fpkt.frame.image
|
||||
yuv_img = fpkt.roadCameraState.image
|
||||
|
||||
if fpkt.frame.transform:
|
||||
yuv_transform = np.array(fpkt.frame.transform).reshape(3, 3)
|
||||
if fpkt.roadCameraState.transform:
|
||||
yuv_transform = np.array(fpkt.roadCameraState.transform).reshape(3, 3)
|
||||
else:
|
||||
# assume frame is flipped
|
||||
yuv_transform = np.array([[-1.0, 0.0, _FULL_FRAME_SIZE[0] - 1],
|
||||
|
||||
+8
-8
@@ -53,9 +53,9 @@ def ui_thread(addr, frame_address):
|
||||
camera_surface = pygame.surface.Surface((640, 480), 0, 24).convert()
|
||||
top_down_surface = pygame.surface.Surface((UP.lidar_x, UP.lidar_y), 0, 8)
|
||||
|
||||
frame = messaging.sub_sock('frame', addr=addr, conflate=True)
|
||||
frame = messaging.sub_sock('roadCameraState', addr=addr, conflate=True)
|
||||
sm = messaging.SubMaster(['carState', 'longitudinalPlan', 'carControl', 'radarState', 'liveCalibration', 'controlsState',
|
||||
'liveTracks', 'modelV2', 'liveMpc', 'liveParameters', 'lateralPlan', 'frame'], addr=addr)
|
||||
'liveTracks', 'modelV2', 'liveMpc', 'liveParameters', 'lateralPlan', 'roadCameraState'], addr=addr)
|
||||
|
||||
img = np.zeros((480, 640, 3), dtype='uint8')
|
||||
imgff = None
|
||||
@@ -109,7 +109,7 @@ def ui_thread(addr, frame_address):
|
||||
|
||||
# ***** frame *****
|
||||
fpkt = messaging.recv_one(frame)
|
||||
rgb_img_raw = fpkt.frame.image
|
||||
rgb_img_raw = fpkt.roadCameraState.image
|
||||
|
||||
num_px = len(rgb_img_raw) // 3
|
||||
if rgb_img_raw and num_px in _FULL_FRAME_SIZE.keys():
|
||||
@@ -134,15 +134,15 @@ def ui_thread(addr, frame_address):
|
||||
|
||||
w = sm['controlsState'].lateralControlState.which()
|
||||
if w == 'lqrState':
|
||||
angle_steers_k = sm['controlsState'].lateralControlState.lqrState.steerAngle
|
||||
angle_steers_k = sm['controlsState'].lateralControlState.lqrState.steeringAngleDeg
|
||||
elif w == 'indiState':
|
||||
angle_steers_k = sm['controlsState'].lateralControlState.indiState.steerAngle
|
||||
angle_steers_k = sm['controlsState'].lateralControlState.indiState.steeringAngleDeg
|
||||
else:
|
||||
angle_steers_k = np.inf
|
||||
|
||||
plot_arr[:-1] = plot_arr[1:]
|
||||
plot_arr[-1, name_to_arr_idx['angle_steers']] = sm['carState'].steeringAngle
|
||||
plot_arr[-1, name_to_arr_idx['angle_steers_des']] = sm['carControl'].actuators.steerAngle
|
||||
plot_arr[-1, name_to_arr_idx['angle_steers']] = sm['carState'].steeringAngleDeg
|
||||
plot_arr[-1, name_to_arr_idx['angle_steers_des']] = sm['carControl'].actuators.steeringAngleDeg
|
||||
plot_arr[-1, name_to_arr_idx['angle_steers_k']] = angle_steers_k
|
||||
plot_arr[-1, name_to_arr_idx['gas']] = sm['carState'].gas
|
||||
plot_arr[-1, name_to_arr_idx['computer_gas']] = sm['carControl'].actuators.gas
|
||||
@@ -195,7 +195,7 @@ def ui_thread(addr, frame_address):
|
||||
info_font.render("LONG CONTROL STATE: " + str(sm['controlsState'].longControlState), True, YELLOW),
|
||||
info_font.render("LONG MPC SOURCE: " + str(sm['longitudinalPlan'].longitudinalPlanSource), True, YELLOW),
|
||||
None,
|
||||
info_font.render("ANGLE OFFSET (AVG): " + str(round(sm['liveParameters'].angleOffsetAverage, 2)) + " deg", True, YELLOW),
|
||||
info_font.render("ANGLE OFFSET (AVG): " + str(round(sm['liveParameters'].angleOffsetAverageDeg, 2)) + " deg", True, YELLOW),
|
||||
info_font.render("ANGLE OFFSET (INSTANT): " + str(round(sm['liveParameters'].angleOffset, 2)) + " deg", True, YELLOW),
|
||||
info_font.render("STIFFNESS: " + str(round(sm['liveParameters'].stiffnessFactor * 100., 2)) + " %", True, YELLOW),
|
||||
info_font.render("STEER RATIO: " + str(round(sm['liveParameters'].steerRatio, 2)), True, YELLOW)
|
||||
|
||||
@@ -27,11 +27,11 @@ def replay(route, loop):
|
||||
lr = LogReader(f"cd:/{route}/rlog.bz2")
|
||||
fr = FrameReader(f"cd:/{route}/fcamera.hevc", readahead=True)
|
||||
|
||||
# Build mapping from frameId to segmentId from encodeIdx, type == fullHEVC
|
||||
# Build mapping from frameId to segmentId from roadEncodeIdx, type == fullHEVC
|
||||
msgs = [m for m in lr if m.which() not in IGNORE]
|
||||
msgs = sorted(msgs, key=lambda m: m.logMonoTime)
|
||||
times = [m.logMonoTime for m in msgs]
|
||||
frame_idx = {m.encodeIdx.frameId: m.encodeIdx.segmentId for m in msgs if m.which() == 'encodeIdx' and m.encodeIdx.type == 'fullHEVC'}
|
||||
frame_idx = {m.roadEncodeIdx.frameId: m.roadEncodeIdx.segmentId for m in msgs if m.which() == 'roadEncodeIdx' and m.roadEncodeIdx.type == 'fullHEVC'}
|
||||
|
||||
socks = {}
|
||||
lag = 0
|
||||
@@ -45,11 +45,11 @@ def replay(route, loop):
|
||||
start_time = time.time()
|
||||
w = msg.which()
|
||||
|
||||
if w == 'frame':
|
||||
if w == 'roadCameraState':
|
||||
try:
|
||||
img = fr.get(frame_idx[msg.frame.frameId], pix_fmt="rgb24")
|
||||
img = img[0][:, :, ::-1] # Convert RGB to BGR, which is what the camera outputs
|
||||
msg.frame.image = img.flatten().tobytes()
|
||||
msg.roadCameraState.image = img.flatten().tobytes()
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
|
||||
|
||||
+11
-11
@@ -49,9 +49,9 @@ class UnloggerWorker(object):
|
||||
poller = zmq.Poller()
|
||||
poller.register(commands_socket, zmq.POLLIN)
|
||||
|
||||
# We can't publish frames without encodeIdx, so add when it's missing.
|
||||
if "frame" in pub_types:
|
||||
pub_types["encodeIdx"] = None
|
||||
# We can't publish frames without roadEncodeIdx, so add when it's missing.
|
||||
if "roadCameraState" in pub_types:
|
||||
pub_types["roadEncodeIdx"] = None
|
||||
|
||||
# gc.set_debug(gc.DEBUG_LEAK | gc.DEBUG_OBJECTS | gc.DEBUG_STATS | gc.DEBUG_SAVEALL |
|
||||
# gc.DEBUG_UNCOLLECTABLE)
|
||||
@@ -86,11 +86,11 @@ class UnloggerWorker(object):
|
||||
continue
|
||||
|
||||
# **** special case certain message types ****
|
||||
if typ == "encodeIdx" and msg.encodeIdx.type == fullHEVC:
|
||||
# this assumes the encodeIdx always comes before the frame
|
||||
if typ == "roadEncodeIdx" and msg.roadEncodeIdx.type == fullHEVC:
|
||||
# this assumes the roadEncodeIdx always comes before the frame
|
||||
self._frame_id_lookup[
|
||||
msg.encodeIdx.frameId] = msg.encodeIdx.segmentNum, msg.encodeIdx.segmentId
|
||||
#print "encode", msg.encodeIdx.frameId, len(self._readahead), route_time
|
||||
msg.roadEncodeIdx.frameId] = msg.roadEncodeIdx.segmentNum, msg.roadEncodeIdx.segmentId
|
||||
#print "encode", msg.roadEncodeIdx.frameId, len(self._readahead), route_time
|
||||
self._readahead.appendleft((typ, msg, route_time, cookie))
|
||||
|
||||
def _send_logs(self, data_socket):
|
||||
@@ -98,7 +98,7 @@ class UnloggerWorker(object):
|
||||
typ, msg, route_time, cookie = self._readahead.pop()
|
||||
smsg = msg.as_builder()
|
||||
|
||||
if typ == "frame":
|
||||
if typ == "roadCameraState":
|
||||
frame_id = msg.frame.frameId
|
||||
|
||||
# Frame exists, make sure we have a framereader.
|
||||
@@ -135,7 +135,7 @@ class UnloggerWorker(object):
|
||||
self._lr = MultiLogIterator(route.log_paths(), wraparound=True)
|
||||
if self._frame_reader is not None:
|
||||
self._frame_reader.close()
|
||||
if "frame" in pub_types or "encodeIdx" in pub_types:
|
||||
if "roadCameraState" in pub_types or "roadEncodeIdx" in pub_types:
|
||||
# reset frames for a route
|
||||
self._frame_id_lookup = {}
|
||||
self._frame_reader = RouteFrameReader(
|
||||
@@ -313,8 +313,8 @@ def absolute_time_str(s, start_time):
|
||||
def _get_address_mapping(args):
|
||||
if args.min is not None:
|
||||
services_to_mock = [
|
||||
'thermal', 'can', 'health', 'sensorEvents', 'gpsNMEA', 'frame', 'encodeIdx',
|
||||
'model', 'features', 'liveLocation',
|
||||
'deviceState', 'can', 'pandaState', 'sensorEvents', 'gpsNMEA', 'roadCameraState', 'roadEncodeIdx',
|
||||
'modelV2', 'liveLocation',
|
||||
]
|
||||
elif args.enabled is not None:
|
||||
services_to_mock = args.enabled
|
||||
|
||||
+10
-10
@@ -32,7 +32,7 @@ REPEAT_COUNTER = 5
|
||||
PRINT_DECIMATION = 100
|
||||
STEER_RATIO = 15.
|
||||
|
||||
pm = messaging.PubMaster(['frame', 'sensorEvents', 'can'])
|
||||
pm = messaging.PubMaster(['roadCameraState', 'sensorEvents', 'can'])
|
||||
sm = messaging.SubMaster(['carControl','controlsState'])
|
||||
|
||||
class VehicleState:
|
||||
@@ -59,13 +59,13 @@ def cam_callback(image):
|
||||
img = np.reshape(img, (H, W, 4))
|
||||
img = img[:, :, [0, 1, 2]].copy()
|
||||
|
||||
dat = messaging.new_message('frame')
|
||||
dat.frame = {
|
||||
dat = messaging.new_message('roadCameraState')
|
||||
dat.roadCameraState = {
|
||||
"frameId": image.frame,
|
||||
"image": img.tostring(),
|
||||
"transform": [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
|
||||
}
|
||||
pm.send('frame', dat)
|
||||
pm.send('roadCameraState', dat)
|
||||
frame_id += 1
|
||||
|
||||
def imu_callback(imu):
|
||||
@@ -81,18 +81,18 @@ def imu_callback(imu):
|
||||
dat.sensorEvents[1].gyroUncalibrated.v = [imu.gyroscope.x, imu.gyroscope.y, imu.gyroscope.z]
|
||||
pm.send('sensorEvents', dat)
|
||||
|
||||
def health_function():
|
||||
pm = messaging.PubMaster(['health'])
|
||||
def panda_state_function():
|
||||
pm = messaging.PubMaster(['pandaState'])
|
||||
while 1:
|
||||
dat = messaging.new_message('health')
|
||||
dat = messaging.new_message('pandaState')
|
||||
dat.valid = True
|
||||
dat.health = {
|
||||
dat.pandaState = {
|
||||
'ignitionLine': True,
|
||||
'pandaType': "blackPanda",
|
||||
'controlsAllowed': True,
|
||||
'safetyModel': 'hondaNidec'
|
||||
}
|
||||
pm.send('health', dat)
|
||||
pm.send('pandaState', dat)
|
||||
time.sleep(0.5)
|
||||
|
||||
def fake_gps():
|
||||
@@ -197,7 +197,7 @@ def go(q):
|
||||
vehicle_state = VehicleState()
|
||||
|
||||
# launch fake car threads
|
||||
threading.Thread(target=health_function).start()
|
||||
threading.Thread(target=panda_state_function).start()
|
||||
threading.Thread(target=fake_driver_monitoring).start()
|
||||
threading.Thread(target=fake_gps).start()
|
||||
threading.Thread(target=can_function_runner, args=(vehicle_state,)).start()
|
||||
|
||||
@@ -35,7 +35,7 @@ def receiver_thread():
|
||||
|
||||
context = zmq.Context()
|
||||
s = messaging.sub_sock(context, 9002, addr=addr)
|
||||
frame_sock = messaging.pub_sock(context, service_list['frame'].port)
|
||||
frame_sock = messaging.pub_sock(context, service_list['roadCameraState'].port)
|
||||
|
||||
ctx = av.codec.codec.Codec('hevc', 'r').create()
|
||||
ctx.decode(av.packet.Packet(start.decode("hex")))
|
||||
@@ -64,10 +64,10 @@ def receiver_thread():
|
||||
#print 'ms to make yuv:', (t1-t2)*1000
|
||||
#print 'tsEof:', ts
|
||||
|
||||
dat = messaging.new_message('frame')
|
||||
dat.frame.image = yuv_img
|
||||
dat.frame.timestampEof = ts
|
||||
dat.frame.transform = map(float, list(np.eye(3).flatten()))
|
||||
dat = messaging.new_message('roadCameraState')
|
||||
dat.roadCameraState.image = yuv_img
|
||||
dat.roadCameraState.timestampEof = ts
|
||||
dat.roadCameraState.transform = map(float, list(np.eye(3).flatten()))
|
||||
frame_sock.send(dat.to_bytes())
|
||||
|
||||
if PYGAME:
|
||||
|
||||
Reference in New Issue
Block a user