Type inheritance examples
Example conditional inheritance - parent type example 1
OSC2 code: conditional inheritance - parent type example 1
import "$FTX/config/sim/sumo_default.osc"
import "$FTX/env/basic/exe_platforms/sumo_dsp/config/sumo_dsp_config.osc"
extend test_config:
set map = "$FTX_PACKAGES/maps/highway.xodr"
extend top.main:
do sut.car.drive(duration: 5s)
enum std_vehicle_category: [truck, car, motorcycle]
actor std_vehicle:
category: std_vehicle_category
emergency_vehicle: bool
Example: conditional inheritance - child type examples
OSC2 code: conditional inheritance -- child type examples
import "$FTX_BASIC/exe_platforms/sumo_ssp/config/sumo_config.osc"
extend test_config:
set map = "$FTX_PACKAGES/maps/hooder.xodr"
extend top.main:
do sut.car.drive(duration: 5s)
enum std_vehicle_category: [truck, car, motorcycle]
actor std_vehicle:
category: std_vehicle_category
emergency_vehicle: bool
actor std_car inherits std_vehicle(category == car):
speed: speed
actor police_car inherits std_car(emergency_vehicle == true):
siren: bool
Example: conditional inheritance - parent type example 2
OSC2 code: conditional inheritance - parent type example 2
import "$FTX_BASIC/exe_platforms/sumo_ssp/config/sumo_config.osc"
extend test_config:
set map = "$FTX_PACKAGES/maps/hooder.xodr"
extend top.main:
do sut.car.drive(duration: 5s)
enum std_vehicle_category: [truck, car, motorcycle]
actor std_vehicle:
category: std_vehicle_category
emergency_vehicle: bool
actor std_truck inherits std_vehicle(category == truck):
gears: int
actor fire_truck inherits std_truck(emergency_vehicle == true):
siren: bool
Example: is_a() type checking operator
OSC2 code: is_a() type checking operator
import "$FTX_BASIC/exe_platforms/sumo_ssp/config/sumo_config.osc"
extend test_config:
set min_test_time = 0sec
set map = "$FTX_PACKAGES/maps/hooder.xodr"
extend top.main:
car1: vehicle
var its_a_truck: bool = car1.is(box_truck)
Example: as() type casting operator
OSC2 code: as() type casting operator
import "$FTX_BASIC/exe_platforms/sumo_ssp/config/sumo_config.osc"
extend test_config:
set map = "$FTX_PACKAGES/maps/hooder.xodr"
extend sut_vehicle:
keep (model_id == truck)
extend box_truck:
num_of_wheels: int with:
keep(soft it == 6)
extend top.main:
keep(sut.car.vehicle_category == box_truck)
do serial:
sut.car.drive(duration: 10sec)
log("Truck SUT has $(sut.car.as(box_truck).num_of_wheels) wheels")
Example: scenario inheritance
OSC2 code: scenario inheritance
import "$FTX_BASIC/exe_platforms/sumo_ssp/config/sumo_config.osc"
extend test_config:
set map = "$FTX_PACKAGES/maps/hooder.xodr"
extend top.main:
do sut.car.drive(duration: 5s)
# fast_drive scenario defined under V10_vehicle
actor V10_vehicle:
first_responder: bool
scenario V10_vehicle.fast_drive:
high_speed: speed with:
keep(it in [105..130]kph)
actor police_V10 inherits V10_vehicle(first_responder == true)
# police_V10 inherits fast_drive() because it is a conditional subtype of V10_vehicle.
extend police_V10.fast_drive:
emergency_lights: bool
# the scram() scenario conditionally inherits from police_V10.fast_drive().
scenario police_V10.scram inherits fast_drive(emergency_lights == true):
siren: bool
keep(siren == true)