Skip to content

Commit 416dc57

Browse files
committed
Adding docs comments
1 parent c402d36 commit 416dc57

File tree

1 file changed

+32
-41
lines changed

1 file changed

+32
-41
lines changed

docs/src/examples/solvers/Unicycle robot copy.jl

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
using Test #src
2-
# # Example: Path planning problem solved by [Uniform grid abstraction](https://github.com/dionysos-dev/Dionysos.jl/blob/master/docs/src/manual/manual.md#solvers).
2+
# # Example: Unicycle Robot solved by [Uniform grid abstraction](https://github.com/dionysos-dev/Dionysos.jl/blob/master/docs/src/manual/manual.md#solvers).
33
#
4-
#md # [![Binder](https://mybinder.org/badge_logo.svg)](@__BINDER_ROOT_URL__/generated/Path planning.ipynb)
5-
#md # [![nbviewer](https://img.shields.io/badge/show-nbviewer-579ACA.svg)](@__NBVIEWER_ROOT_URL__/generated/Path planning.ipynb)
6-
#
7-
# This example was borrowed from [1, IX. Examples, A] whose dynamics comes from the model given in [2, Ch. 2.4].
8-
# This is a **reachability problem** for a **continuous system**.
4+
# This example was adapted from the numerical experiments in [1, Sec. 5] from Symbolically guided Model Predictive Control (SgMPC) [paper](https://doi.org/10.1016/j.ifacol.2022.09.039)..
5+
# This is a **control problem** for a **discrete-time nonlinear system**.
96
#
107
# Let us consider the 3-dimensional state space control system of the form
118
# ```math
12-
# \dot{x} = f(x, u)
9+
# x_{t+1} = f(x_t, u_t)
1310
# ```
14-
# with $f: \mathbb{R}^3 × U ↦ \mathbb{R}^3$ given by
11+
# with $f: \mathbb{R}^3 × \mathbb{R}^2 \to \mathbb{R}^3$ given by
1512
# ```math
16-
# f(x,(u_1,u_2)) = \begin{bmatrix} u_1 \cos(α+x_3)\cos(α)^{-1} \\ u_1 \sin(α+x_3)\cos(α)^{-1} \\ u_1 \tan(u_2) \end{bmatrix}
13+
# f(x, (u_1, u_2)) = \begin{bmatrix} x_1 + u_1 \cos(x_3) \\ x_2 + u_1 \sin(x_3) \\ x_3 + u_2 \ (\text{mod} \ 2\pi) \end{bmatrix}
1714
# ```
18-
# and with $U = [−1, 1] \times [−1, 1]$ and $α = \arctan(\tan(u_2)/2)$. Here, $(x_1, x_2)$ is the position and $x_3$ is the
19-
# orientation of the vehicle in the 2-dimensional plane. The control inputs $u_1$ and $u_2$ are the rear
20-
# wheel velocity and the steering angle.
21-
# The control objective is to drive the vehicle which is situated in a maze made of obstacles from an initial position to a target position.
22-
#
23-
#
24-
# In order to study the concrete system and its symbolic abstraction in a unified framework, we will solve the problem
25-
# for the sampled system with a sampling time $\tau$.
26-
# For the construction of the relations in the abstraction, it is necessary to over-approximate attainable sets of
27-
# a particular cell. In this example, we consider the used of a growth bound function [1, VIII.2, VIII.5] which is one of the possible methods to over-approximate
28-
# attainable sets of a particular cell based on the state reach by its center.
15+
# and with state and control constraints given by:
16+
# ```math
17+
# X = \left\{ (x_1, x_2)^T \in \mathbb{R}^2 \ | \ x_1^2 - x_2^2 \leq 4, \ 4x_2^2 - x_1^2 \leq 16 \right\}
18+
# ```
19+
# ```math
20+
# U = [0.2, 2] \times [-1, 1]
21+
# ```
22+
# Here, $(x_1, x_2)$ represents the 2D Cartesian coordinates and $x_3$ is the angular orientation of a mobile cart.
23+
# The control inputs $u_1$ and $u_2$ are the linear and angular velocities.
24+
# The control objective is to drive the mobile cart to a desired reference position $x_r$.
2925
#
30-
# For this reachability problem, the abstraction controller is built by solving a fixed-point equation which consists in computing the pre-image
31-
# of the target set.
26+
# Considering this as a reachability problem, we will use it to showcase the capabilities of the Uniform grid abstraction solving discrete-time problem in Dionysos.
27+
# The nonlinear constraints are handled as obstacles in the state-space.
3228

3329
# First, let us import [StaticArrays](https://github.com/JuliaArrays/StaticArrays.jl) and [Plots](https://github.com/JuliaPlots/Plots.jl).
3430
using StaticArrays, Plots, Revise
@@ -40,16 +36,15 @@ using Dionysos, JuMP
4036
# We first create a JuMP model:
4137
model = Model(Dionysos.Optimizer)
4238

43-
# Define the prediction horizon
44-
N = 5
39+
# Define the discretization step
4540
discretization_step = 0.1
4641

47-
# Define the state variables: x1(t), x2(t), x3(t) for t = 1, ..., N
42+
# Define the state variables: x1(t), x2(t), x3(t) without specifying the start value since here it's a set. We will specify the start later using constraints.
4843
x_low = [-3.5, -2.6, -pi]
4944
x_upp = -x_low
5045
@variable(model, x_low[i] <= x[i = 1:3] <= x_upp[i])
5146

52-
# Define the control variables: u1(t), u2(t) for t = 1, ..., N-1
47+
# Define the control variables: u1(t), u2(t)
5348
@variable(model, -1 <= u[1:2] <= 1)
5449

5550
# Define the dynamics
@@ -58,28 +53,18 @@ x_upp = -x_low
5853
@constraint(model, (x[3]) == x[3] + u[2])
5954

6055
# Define the initial and target sets
61-
#x_initial = [0.0, 0.0, 0.0] # Initial state
6256
x_initial = [1.0, -1.7, 0.0]
63-
#x_target = [0.5, 0.5, -pi] # Target state
6457
x_target = [sqrt(32)/3, sqrt(20)/3, -pi]
6558

66-
#@constraint(model, start(x[1]) in MOI.Interval(-0.2, 0.2))
67-
#@constraint(model, start(x[2]) in MOI.Interval(-0.2, 0.2))
68-
#@constraint(model, start(x[3]) in MOI.Interval(-0.2, 0.2))
69-
7059
@constraint(model, start(x[1]) in MOI.Interval(0.8, 1.2))
7160
@constraint(model, start(x[2]) in MOI.Interval(-1.9, -1.5))
7261
@constraint(model, start(x[3]) in MOI.Interval(-0.2, 0.2))
7362

74-
#@constraint(model, final(x[1]) in MOI.Interval(0.3, 0.7))
75-
#@constraint(model, final(x[2]) in MOI.Interval(0.3, 0.7))
76-
#@constraint(model, final(x[3]) in MOI.Interval(-3.14, 3.14))
77-
7863
@constraint(model, final(x[1]) in MOI.Interval(1.78, 1.98))
7964
@constraint(model, final(x[2]) in MOI.Interval(1.39, 1.59))
8065
@constraint(model, final(x[3]) in MOI.Interval(-3.14, 3.14))
8166

82-
# Obstacle boundaries (provided)
67+
# Obstacle boundaries computed using the function `get_obstacles` below
8368
function extract_rectangles(matrix)
8469
if isempty(matrix)
8570
return []
@@ -135,6 +120,7 @@ function get_obstacles(lb, ub, h)
135120
end
136121

137122
obstacles = get_obstacles(x_low, x_upp, discretization_step)
123+
138124
# Function to add rectangular obstacle avoidance constraints
139125

140126
for obstacle in obstacles
@@ -143,7 +129,10 @@ end
143129

144130
# ### Definition of the abstraction
145131

146-
# Definition of the grid of the state-space on which the abstraction is based (origin `x0` and state-space discretization `h`):
132+
# First we need to set the mode of the abstraction to `DIONYSOS.Optim.Abstraction.UniformGridAbstraction.DSICRETE_TIME`:
133+
set_attribute(model, "approx_mode", Dionysos.Optim.Abstraction.UniformGridAbstraction.DSICRETE_TIME)
134+
135+
# We define the system map $f$:
147136
function sys_map(x, u, _)
148137
return StaticArrays.SVector{3}(
149138
x[1] + u[1] * cos(x[3]),
@@ -153,12 +142,14 @@ function sys_map(x, u, _)
153142
end
154143
set_attribute(model, "system_map", sys_map)
155144

145+
# We define the growth bound function of $f$:
156146
function growth_bound(r, u, _)
157147
β = u[1] * r[3]
158148
return StaticArrays.SVector{3}(β, β, 0.0)
159149
end
160150
set_attribute(model, "growthbound_map", growth_bound)
161151

152+
# We define the invariant system map:
162153
function sys_inv(x, u, _)
163154
return StaticArrays.SVector{3}(
164155
x[1] - u[1] * cos((x[3] - u[2]) % (2 * π)),
@@ -168,8 +159,10 @@ function sys_inv(x, u, _)
168159
end
169160
set_attribute(model, "sys_inv_map", sys_inv)
170161

162+
# We define the time step of the system:
171163
set_attribute(model, "time_step", 1.0)
172164

165+
# Definition of the grid of the state-space on which the abstraction is based (origin `x0` and state-space discretization `h`):
173166
x0 = SVector(0.0, 0.0, 0.0);
174167
h = SVector(0.1, 0.1, 0.2);
175168
set_attribute(model, "state_grid", Dionysos.Domain.GridFree(x0, h))
@@ -179,7 +172,6 @@ u0 = SVector(1.1, 0.0);
179172
h = SVector(0.3, 0.3);
180173
set_attribute(model, "input_grid", Dionysos.Domain.GridFree(u0, h))
181174

182-
set_attribute(model, "approx_mode", Dionysos.Optim.Abstraction.UniformGridAbstraction.DSICRETE_TIME)
183175
optimize!(model)
184176

185177
# Get the results
@@ -241,5 +233,4 @@ plot!(
241233
plot!(control_trajectory; ms = 0.5)
242234

243235
# ### References
244-
# 1. G. Reissig, A. Weber and M. Rungger, "Feedback Refinement Relations for the Synthesis of Symbolic Controllers," in IEEE Transactions on Automatic Control, vol. 62, no. 4, pp. 1781-1796.
245-
# 2. K. J. Aström and R. M. Murray, Feedback systems. Princeton University Press, Princeton, NJ, 2008.
236+
# 1. Z. Azaki, A. Girard and S. Olaru, "Predictive and Symbolic Control: Performance and Safety for Non-linear Systems," in IFAC-PapersOnLine, 2022, vol. 55, no 16, pp. 290-295..

0 commit comments

Comments
 (0)