minor bug fixes in sim (#20286)

* order doensn't matter

* order doensn't matter

* minor fixes

* minor fixes

* not blocking ctrl-c

* removing weather params

* removing type ignore
pull/20295/head
iejMac 4 years ago committed by GitHub
parent 92c5bbf92d
commit 072cdcad6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      tools/sim/bridge.py
  2. 4
      tools/sim/lib/keyboard_ctrl.py

@ -1,13 +1,14 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# type: ignore import argparse
import atexit
import carla # pylint: disable=import-error import carla # pylint: disable=import-error
import time
import math import math
import atexit
import numpy as np import numpy as np
import time
import threading import threading
from typing import Any
import cereal.messaging as messaging import cereal.messaging as messaging
import argparse
from common.params import Params from common.params import Params
from common.realtime import Ratekeeper, DT_DMON from common.realtime import Ratekeeper, DT_DMON
from lib.can import can_function from lib.can import can_function
@ -19,12 +20,6 @@ parser.add_argument('--joystick', action='store_true')
parser.add_argument('--town', type=str, default='Town04') parser.add_argument('--town', type=str, default='Town04')
parser.add_argument('--spawn_point', dest='num_selected_spawn_point', parser.add_argument('--spawn_point', dest='num_selected_spawn_point',
type=int, default=16) type=int, default=16)
parser.add_argument('--cloudiness', default=0.1, type=float)
parser.add_argument('--precipitation', default=0.0, type=float)
parser.add_argument('--precipitation_deposits', default=0.0, type=float)
parser.add_argument('--wind_intensity', default=0.0, type=float)
parser.add_argument('--sun_azimuth_angle', default=15.0, type=float)
parser.add_argument('--sun_altitude_angle', default=75.0, type=float)
args = parser.parse_args() args = parser.parse_args()
W, H = 1164, 874 W, H = 1164, 874
@ -131,7 +126,7 @@ def can_function_runner(vs):
i+=1 i+=1
def go(q): def bridge(q):
# setup CARLA # setup CARLA
client = carla.Client("127.0.0.1", 2000) client = carla.Client("127.0.0.1", 2000)
@ -170,15 +165,6 @@ def go(q):
camera = world.spawn_actor(blueprint, transform, attach_to=vehicle) camera = world.spawn_actor(blueprint, transform, attach_to=vehicle)
camera.listen(cam_callback) camera.listen(cam_callback)
world.set_weather(carla.WeatherParameters(
cloudiness=args.cloudiness,
precipitation=args.precipitation,
precipitation_deposits=args.precipitation_deposits,
wind_intensity=args.wind_intensity,
sun_azimuth_angle=args.sun_azimuth_angle,
sun_altitude_angle=args.sun_altitude_angle
))
# reenable IMU # reenable IMU
imu_bp = blueprint_library.find('sensor.other.imu') imu_bp = blueprint_library.find('sensor.other.imu')
imu = world.spawn_actor(imu_bp, transform, attach_to=vehicle) imu = world.spawn_actor(imu_bp, transform, attach_to=vehicle)
@ -286,17 +272,6 @@ def go(q):
steer_out = steer_rate_limit(old_steer, steer_out) steer_out = steer_rate_limit(old_steer, steer_out)
old_steer = steer_out old_steer = steer_out
# OP Exit conditions
# if throttle_out > 0.3:
# cruise_button = CruiseButtons.CANCEL
# is_openpilot_engaged = False
# if brake_out > 0.3:
# cruise_button = CruiseButtons.CANCEL
# is_openpilot_engaged = False
# if steer_out > 0.3:
# cruise_button = CruiseButtons.CANCEL
# is_openpilot_engaged = False
else: else:
if throttle_out==0 and old_throttle>0: if throttle_out==0 and old_throttle>0:
if throttle_ease_out_counter>0: if throttle_ease_out_counter>0:
@ -348,6 +323,13 @@ def go(q):
rk.keep_time() rk.keep_time()
def go(q: Any):
while 1:
try:
bridge(q)
except RuntimeError:
print("Restarting bridge...")
if __name__ == "__main__": if __name__ == "__main__":
# make sure params are in a good state # make sure params are in a good state
set_params_enabled() set_params_enabled()
@ -357,7 +339,7 @@ if __name__ == "__main__":
params.put("CalibrationParams", '{"calib_radians": [0,0,0], "valid_blocks": 20}') params.put("CalibrationParams", '{"calib_radians": [0,0,0], "valid_blocks": 20}')
from multiprocessing import Process, Queue from multiprocessing import Process, Queue
q = Queue() q: Any = Queue()
p = Process(target=go, args=(q,)) p = Process(target=go, args=(q,))
p.daemon = True p.daemon = True
p.start() p.start()

@ -2,7 +2,7 @@ import sys
import termios import termios
import time import time
from termios import (BRKINT, CS8, CSIZE, ECHO, ICANON, ICRNL, IEXTEN, INPCK, from termios import (BRKINT, CS8, CSIZE, ECHO, ICANON, ICRNL, IEXTEN, INPCK,
ISIG, ISTRIP, IXON, PARENB, VMIN, VTIME) ISTRIP, IXON, PARENB, VMIN, VTIME)
from typing import Any from typing import Any
# Indexes for termios list. # Indexes for termios list.
@ -24,7 +24,7 @@ def getch():
#mode[OFLAG] = mode[OFLAG] & ~(OPOST) #mode[OFLAG] = mode[OFLAG] & ~(OPOST)
mode[CFLAG] = mode[CFLAG] & ~(CSIZE | PARENB) mode[CFLAG] = mode[CFLAG] & ~(CSIZE | PARENB)
mode[CFLAG] = mode[CFLAG] | CS8 mode[CFLAG] = mode[CFLAG] | CS8
mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG) mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON | IEXTEN)
mode[CC][VMIN] = 1 mode[CC][VMIN] = 1
mode[CC][VTIME] = 0 mode[CC][VTIME] = 0
termios.tcsetattr(fd, termios.TCSAFLUSH, mode) termios.tcsetattr(fd, termios.TCSAFLUSH, mode)

Loading…
Cancel
Save