Skip to content

Commit

Permalink
changes to scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
tcdanielh committed Apr 12, 2024
1 parent ba63352 commit 63d7b07
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 23 deletions.
3 changes: 3 additions & 0 deletions examples/airsim/demoDrone.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ behavior FindAdversary(speed = 5):
interrupt when self can see drone1:
# when I can see adversary, follow it
do Follow(drone1)
# interrupt when distance from self to drone1 < 10:
# # when I can see adversary (i'm within 10 meters of it), follow it
# do Follow(drone1)
interrupt when distance from self to drone1 < 2:
# when I get within 2 meters of adversary, terminate scenario
terminate
Expand Down
10 changes: 7 additions & 3 deletions examples/airsim/flyFromBlockToBlock.scenic
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# NOTE: add your world info path here
# param worldInfoPath = "[YOUR PATH HERE]"
param worldInfoPath = "C:/Users/piegu/Scenic/examples/airsim/worldInfo/droneBlocks"

model scenic.simulators.airsim.model

# Spawns 10 arbritrary static obstacles on the ground
# drone patrols to these positions uniformly randomly

platforms = []
ground = getPrexistingObj("ground")
Expand All @@ -27,5 +29,7 @@ for plat in platforms:
point = new Point on plat
points.append(point.position)

drone1 = new Drone at Uniform(*points) + (0,0,1),
with behavior Patrol(points,True)
ego = new Drone at Uniform(*points) + (0,0,1),
with behavior Patrol(points,True)

terminate after 30 seconds
20 changes: 16 additions & 4 deletions examples/airsim/followDrone.scenic
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import math

# NOTE: add your world info path here
# param worldInfoPath = "[YOUR PATH HERE]"
param worldInfoPath = "C:/Users/piegu/Scenic/examples/airsim/worldInfo/droneBlocks"

# Spawns 1 drone (ego) that patrols specific points, drone 2 follows ego

param timestep = .1

Expand All @@ -24,10 +26,20 @@ behavior Follow(target, speed = 5,tolerance = 2, offset = (0,0,1)):
take SetVelocity(velocity)
wait

behavior Patrol(positions, loop=True, smooth = False, speed = 5,tolerance = 2):
while True:
for pos in positions:
do FlyToPosition(pos,speed=speed,pidMode= not smooth,tolerance=tolerance)

if not loop:
return


drone1 = new Drone at (0,0,0),
ego = new Drone at (0,0,0),
with behavior Patrol([(-1,2,2),(1,4,2),(-1,4,2),(-1,2,4),(1,2,4),(1,4,4),(-1,4,4)],True)

drone2 = new Drone at (0,1,0),
with behavior Follow(drone1)
with behavior Follow(ego)

terminate after 10 seconds

record final (distance to drone2) as dist
40 changes: 37 additions & 3 deletions examples/airsim/multi_drone.scenic
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
# NOTE: add your world info path here
# param worldInfoPath = "[YOUR PATH HERE]"
param worldInfoPath = "C:/Users/piegu/Scenic/examples/airsim/worldInfo/droneBlocks"

# Spawns 3 drones that fly to random positions


model scenic.simulators.airsim.model

# Flies the drone to a position
behavior FlyToPosition(newPos, speed = 5,tolerance = 1,pidMode = True):
# pidMode is true if we want the drone to slow down as it reaches its destination

client = simulation().client

ground = getPrexistingObj("ground")

if pidMode:
newPos = scenicToAirsimVector(toVector(newPos))
do waitForPromise(createPromise(
client.moveToPositionAsync(
newPos.x_val,
newPos.y_val,
newPos.z_val,
velocity=speed,
vehicle_name=self.realObjName,
)
))
else:
while True:
direction = newPos -self.position
distance = magnitude(direction)

if distance < tolerance:
break
direction= (direction/distance)*speed
take SetVelocity(direction)
wait


return

for i in range(3):
new Drone at (Range(-10,10),Range(-10,10),Range(0,10)),
with behavior FlyToPosition((Range(-10,10),Range(-10,10),Range(0,10)))
with behavior FlyToPosition((Range(-30,10),Range(-30,10),Range(0,30)))

terminate after 10 seconds
1 change: 1 addition & 0 deletions src/scenic/simulators/airsim/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from scenic.core.type_support import toVector
from scenic.core.vectors import Orientation, Vector
# TODO: Uncomment this out to use PX4 drones/MAVSDK.
# import scenic.simulators.airsim.MavsdkUtils as mavutils
from scenic.syntax.veneer import verbosePrint

Expand Down
18 changes: 9 additions & 9 deletions src/scenic/simulators/airsim/simulatorCar.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ def setup(self):

# move all cars to offscreen position
self.client.simPause(False)
for i, car in enumerate(self.startCars):
newPose = airsim.Pose(
position_val=scenicToAirsimVector(self.simulator.idleStoragePos)
+ airsim.Vector3r(i, 0, 0)
)
self.client.enableApiControl(True, car)
self.client.simSetVehiclePose(
vehicle_name=car, pose=newPose, ignore_collision=False
)
# for i, car in enumerate(self.startCars):
# newPose = airsim.Pose(
# position_val=scenicToAirsimVector(self.simulator.idleStoragePos)
# + airsim.Vector3r(i, 0, 0)
# )
# self.client.enableApiControl(True, car)
# self.client.simSetVehiclePose(
# vehicle_name=car, pose=newPose, ignore_collision=False
# )

self.client.simPause(True)

Expand Down
8 changes: 4 additions & 4 deletions src/scenic/simulators/airsim/verifai_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# return True
# super().__init__(specification)

path_to_scenic_script = 'C:/Users/piegu/Scenic/examples/airsim/multi_drone.scenic'
path_to_scenic_script = 'C:/Users/piegu/Scenic/examples/airsim/followDrone.scenic'
sampler = ScenicSampler.fromScenario(path_to_scenic_script)

class confidence_spec(specification_monitor):
def __init__(self):
def specification(traj):
return bool(traj['yTrue'] == traj['yPred'])
def specification(simulation):
return simulation.result.records['dist'] < 3
super().__init__(specification)

MAX_ITERS = 1
Expand All @@ -38,7 +38,7 @@ def specification(traj):

falsifier = generic_falsifier(sampler=sampler,
falsifier_params=falsifier_params,
# monitor=confidence_spec,
monitor=confidence_spec,
server_class=ScenicServer,
server_options=server_options)
falsifier.run_falsifier()
Expand Down

0 comments on commit 63d7b07

Please sign in to comment.