Skip to content

Commit

Permalink
add laubloomis exmaple
Browse files Browse the repository at this point in the history
  • Loading branch information
lyg1597 committed Mar 5, 2024
1 parent ce6129f commit e2d501f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 22 deletions.
34 changes: 25 additions & 9 deletions demo/dryvr_demo/dryvr_agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Example agent.
from re import L
from typing import Tuple, List

import numpy as np
Expand All @@ -8,6 +9,30 @@
from verse.map import LaneMap
from verse.parser import ControllerIR

class LaubLoomisAgent(BaseAgent):
def __init__(self, id, code = None, file_name = None):
self.decision_logic: ControllerIR = ControllerIR.empty()
self.id = id
self.init_cont = None
self.init_disc = None
self.static_parameters = None
self.uncertain_parameters = None

def dynamics(self, x, t):
x1, x2, x3,\
x4, x5, x6,\
x7 = x

dx1 = 1.4*x3-0.9*x1
dx2 = 2.5*x5-1.5*x2
dx3 = 0.6*x7-0.8*x2*x3
dx4 = 2-1.3*x3*x4
dx5 = 0.7*x1-x4*x5
dx6 = 0.3*x1-3.1*x6
dx7 = 1.8*x6-1.5*x2*x7

return [dx1,dx2,dx3,dx4,dx5,dx6,dx7]

class QuadrotorAgent(BaseAgent):
def __init__(self, id, code = None, file_name = None):
self.decision_logic: ControllerIR = ControllerIR.empty()
Expand Down Expand Up @@ -57,12 +82,3 @@ def dynamics(self, x, t):
du1 = 0

return [dx1,dx2,dx3,dx4,dx5,dx6,dx7,dx8,dx9,dx10,dx11,dx12,du1]

def TC_simulate(self, mode, initialSet, time_horizon, time_step, map=None):
y0 = initialSet
t = np.round(np.arange(0.0, time_horizon+time_step/2, time_step), 8)
trace = odeint(func = self.dynamics, y0 = y0, t = t)
t = t.reshape((-1,1))
trace = np.hstack((t, trace))
return trace

40 changes: 40 additions & 0 deletions demo/dryvr_demo/laubloomis_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from dryvr_agent import LaubLoomisAgent
from verse import Scenario, ScenarioConfig
from verse.plotter.plotter2D import *

import plotly.graph_objects as go
from enum import Enum, auto

class AgentMode(Enum):
Default = auto()

if __name__ == "__main__":
scenario = Scenario(ScenarioConfig(parallel=False))
W = 0.1

agent = LaubLoomisAgent('laub')
scenario.add_agent(agent)
# The initial position of the quadrotor is uncertain in
# all directions within [−0.4, 0.4] [m] and also the velocity
# is uncertain within [−0.4, 0.4] [m/s] for all directions

# The inertial (north) position x1, the inertial (east) position x2,
# the altitude x3, the longitudinal velocity x4,
# the lateral velocity x5, the vertical velocity x6,
# the roll angle x7, the pitch angle x8,
# the yaw angle x9, the roll rate x10,
# the pitch rate x11, and the yaw rate x12.
scenario.set_init(
[
[[1.2-W, 1.05-W, 1.5-W, 2.4-W, 1-W, 0.1-W, 0.45-W],
[1.2+W, 1.05+W, 1.5+W, 2.4+W, 1+W, 0.1+W, 0.45+W]]
],
[
(AgentMode.Default, )
]
)
traces = scenario.verify(20, 0.01)

fig = go.Figure()
fig = reachtube_tree(traces, None, fig, 0, 4, [1,3], "lines", "trace")
fig.show()
20 changes: 7 additions & 13 deletions verse/agents/base_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from verse.parser.parser import ControllerIR
import numpy as np
from scipy.integrate import ode
from scipy.integrate import ode, odeint
import copy


Expand Down Expand Up @@ -85,15 +85,9 @@ def TC_simulate(self, mode, initialSet, time_horizon, time_step, map=None):
map: LaneMap, optional
Provided if the map is used
"""
num_points = int(np.ceil(time_horizon / time_step))
trace = np.zeros((num_points + 1, 1 + len(initialSet)))
trace[1:, 0] = [round(i * time_step, 10) for i in range(num_points)]
trace[0, 1:] = initialSet
for i in range(num_points):
result = ode(self.dynamic)
result.set_initial_value(initialSet)
res: np.ndarray = result.integrate(result.t + time_step)
initialSet = res.flatten()
trace[i + 1, 0] = time_step * (i + 1)
trace[i + 1, 1:] = initialSet
return np.array(trace)
y0 = initialSet
t = np.round(np.arange(0.0, time_horizon+time_step/2, time_step), 8)
trace = odeint(func = self.dynamics, y0 = y0, t = t)
t = t.reshape((-1,1))
trace = np.hstack((t, trace))
return trace

0 comments on commit e2d501f

Please sign in to comment.