Added smoke test for sensor_tick check

This commit is contained in:
doterop 2021-01-20 19:12:19 +01:00
parent 5b59d9ad14
commit fa2cde9ace
1 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,64 @@
# Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma de
# Barcelona (UAB).
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
from . import SyncSmokeTest
import carla
import time
class Sensor():
def __init__(self, world, bp_sensor, sensor_tick):
self.bp_sensor = bp_sensor
bp_sensor.set_attribute("sensor_tick", str(sensor_tick))
self.sensor = world.spawn_actor(bp_sensor, carla.Transform())
self.sensor.listen(lambda sensor_data: self.listen(sensor_data))
self.num_ticks = 0
def destroy(self):
self.sensor.destroy()
def listen(self, sensor_data):
self.num_ticks += 1
class TestSensorTickTime(SyncSmokeTest):
def test_sensor_tick_time(self):
print("TestSensorTickTime.test_sensor_tick_time")
bp_lib = self.world.get_blueprint_library()
sensor_exception = {
"sensor.camera.dvs",
"sensor.other.obstacle"
}
spawned_sensors = []
sensor_tick = 1.0
for bp_sensor in bp_lib.filter("sensor.*"):
if bp_sensor.id in sensor_exception:
continue
if bp_sensor.has_attribute("sensor_tick"):
spawned_sensors.append(Sensor(self.world, bp_sensor, sensor_tick))
num_ticks = 10
for _ in range(0, num_ticks):
self.world.tick()
time.sleep(1.0)
dt = 0.05 # self.settings.fixed_delta_seconds
total_time = num_ticks * dt
num_sensor_ticks = total_time/sensor_tick
print("Total time: {} = {} x {}".format(total_time, num_ticks, self.settings.fixed_delta_seconds))
print("Expected sensor ticks: {}".format(num_sensor_ticks))
for sensor in spawned_sensors:
print("{} ticks {} _".format(sensor.bp_sensor.id, sensor.num_ticks))
self.assertEqual(sensor.num_ticks, num_sensor_ticks,
"\n\n {} does not match tick count".format(sensor.bp_sensor.id))
sensor.destroy()