Skip to content

rm JuliaSimCompiler #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ version = "0.3.2"
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
JuliaSimCompiler = "8391cb6b-4921-5777-4e45-fd9aab8cb88d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MeshIO = "7269a6da-0436-5bbc-96c2-40638cbb6118"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Expand All @@ -17,42 +16,40 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"


[extensions]
Render = ["Makie"]
URDF = ["LightXML", "Graphs", "MetaGraphsNext", "JuliaFormatter"]

[compat]
CoordinateTransformations = "0.6"
DataInterpolations = "5, 6"
DataInterpolations = "8"
FileIO = "1"
Graphs = "1.0"
JuliaFormatter = "1.0"
JuliaSimCompiler = "0.1.12"
LightXML = "0.9"
LinearAlgebra = "1.6"
MeshIO = "0.4"
MetaGraphsNext = "0.7"
ModelingToolkit = "9"
ModelingToolkit = "10"
ModelingToolkitStandardLibrary = "2.7.2"
Rotations = "1.4"
SparseArrays = "1"
StaticArrays = "1"
julia = "1"

[extras]
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["OrdinaryDiffEq", "Test", "JuliaFormatter", "LightXML", "Graphs", "MetaGraphsNext"]
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
ControlSystemsMTK = "687d7614-c7e5-45fc-bfc3-9ee385575c88"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
JuliaSimCompiler = "8391cb6b-4921-5777-4e45-fd9aab8cb88d"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
Expand Down
6 changes: 3 additions & 3 deletions docs/src/examples/free_motion.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This example demonstrates how a free-floating [`Body`](@ref) can be simulated. T
using Multibody
using ModelingToolkit
using Plots
using JuliaSimCompiler
# using JuliaSimCompiler
using OrdinaryDiffEq

t = Multibody.t
Expand All @@ -18,7 +18,7 @@ world = Multibody.world
eqs = [connect(world.frame_b, freeMotion.frame_a)
connect(freeMotion.frame_b, body.frame_a)]

@named model = ODESystem(eqs, t,
@named model = System(eqs, t,
systems = [world;
freeMotion;
body])
Expand Down Expand Up @@ -60,7 +60,7 @@ eqs = [connect(bar2.frame_a, world.frame_b)
connect(spring1.frame_a, world.frame_b)
connect(body.frame_b, spring2.frame_b)]

@named model = ODESystem(eqs, t,
@named model = System(eqs, t,
systems = [
world,
body,
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/gearbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The [`GearConstraint`](@ref) has two rotational axes which do not have to be par
using Multibody
using ModelingToolkit
using Plots
using JuliaSimCompiler
# using JuliaSimCompiler
using OrdinaryDiffEq

t = Multibody.t
Expand Down Expand Up @@ -46,7 +46,7 @@ eqs = [connect(world.frame_b, gearConstraint.bearing)
connect(mounting1D.flange_b, torque2.support)
connect(fixed.frame_b, mounting1D.frame_a)]

@named model = ODESystem(eqs, t, systems = [world; systems])
@named model = System(eqs, t, systems = [world; systems])
cm = complete(model)
ssys = structural_simplify(multibody(model))
prob = ODEProblem(ssys, [
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/gyroscopic_effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The system consists of a pendulum suspended in a spherical joint, a joint withou
using Multibody
using ModelingToolkit
using Plots
using JuliaSimCompiler
# using JuliaSimCompiler
using OrdinaryDiffEq

t = Multibody.t
Expand All @@ -36,7 +36,7 @@ connections = [
connect(trans.frame_b, body2.frame_a)
]

@named model = ODESystem(connections, t, systems = [world; systems])
@named model = System(connections, t, systems = [world; systems])
model = complete(model)
ssys = structural_simplify(multibody(model))

Expand Down
8 changes: 4 additions & 4 deletions docs/src/examples/kinematic_loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import ModelingToolkitStandardLibrary.Mechanical.Rotational
using Plots
using OrdinaryDiffEq
using LinearAlgebra
using JuliaSimCompiler
# using JuliaSimCompiler

t = Multibody.t
D = Differential(t)
Expand Down Expand Up @@ -73,7 +73,7 @@ connections = [
connect(j2.support, damper2.flange_b)

]
@named fourbar = ODESystem(connections, t, systems = [world; systems])
@named fourbar = System(connections, t, systems = [world; systems])
fourbar = complete(fourbar)
ssys = structural_simplify(multibody(fourbar))
prob = ODEProblem(ssys, [fourbar.j1.phi => 0.1], (0.0, 10.0))
Expand Down Expand Up @@ -144,7 +144,7 @@ connections = [connect(j2.frame_b, b2.frame_a)
connect(b0.frame_a, world.frame_b)
connect(b0.frame_b, j2.frame_a)
]
@named fourbar2 = ODESystem(connections, t, systems = [world; systems])
@named fourbar2 = System(connections, t, systems = [world; systems])
fourbar2 = complete(fourbar2)
ssys = structural_simplify(multibody(fourbar2))

Expand Down Expand Up @@ -185,7 +185,7 @@ connections = [connect(j2.frame_b, b2.frame_a)
connect(b3.frame_b, j2.frame_a)
]

@named fourbar_analytic = ODESystem(connections, t, systems = [world; systems])
@named fourbar_analytic = System(connections, t, systems = [world; systems])
fourbar_analytic = complete(fourbar_analytic)
ssys_analytic = structural_simplify(multibody(fourbar_analytic))
prob = ODEProblem(ssys_analytic, [], (0.0, 1.4399))
Expand Down
22 changes: 11 additions & 11 deletions docs/src/examples/pendulum.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This beginners tutorial will start by modeling a pendulum pivoted around the ori
To start, we load the required packages
```@example pendulum
using ModelingToolkit
using Multibody, JuliaSimCompiler
using Multibody
using OrdinaryDiffEq # Contains the ODE solver we will use
using Plots
```
Expand Down Expand Up @@ -39,13 +39,13 @@ connections = [
nothing # hide
```

With all components and connections defined, we can create an `ODESystem` like so:
With all components and connections defined, we can create an `System` like so:
```@example pendulum
@named model = ODESystem(connections, t, systems=[world, joint, body])
@named model = System(connections, t, systems=[world, joint, body])
model = complete(model)
nothing # hide
```
The `ODESystem` is the fundamental model type in ModelingToolkit used for multibody-type models.
The `System` is the fundamental model type in ModelingToolkit used for multibody-type models.

Before we can simulate the system, we must perform model check using the function [`multibody`](@ref) and compilation using [`structural_simplify`](@ref)
```@example pendulum
Expand Down Expand Up @@ -92,7 +92,7 @@ connections = [connect(world.frame_b, joint.frame_a)
connect(joint.support, damper.flange_a)
connect(body.frame_a, joint.frame_b)]

@named model = ODESystem(connections, t, systems = [world, joint, body, damper])
@named model = System(connections, t, systems = [world, joint, body, damper])
model = complete(model)
ssys = structural_simplify(multibody(model))

Expand Down Expand Up @@ -125,7 +125,7 @@ connections = [connect(world.frame_b, joint.frame_a)
connect(joint.support, damper.flange_a, spring.flange_a)
connect(body_0.frame_a, joint.frame_b)]

@named model = ODESystem(connections, t, systems = [world, joint, body_0, damper, spring])
@named model = System(connections, t, systems = [world, joint, body_0, damper, spring])
model = complete(model)
ssys = structural_simplify(multibody(model))

Expand All @@ -152,7 +152,7 @@ In the example above, we introduced a prismatic joint to model the oscillating m
connections = [connect(world.frame_b, multibody_spring.frame_a)
connect(root_body.frame_a, multibody_spring.frame_b)]

@named model = ODESystem(connections, t, systems = [world, multibody_spring, root_body])
@named model = System(connections, t, systems = [world, multibody_spring, root_body])
model = complete(model)
ssys = structural_simplify(multibody(model))

Expand All @@ -170,7 +170,7 @@ Internally, the [`Multibody.Spring`](@ref) contains a `Translational.Spring`, at
push!(connections, connect(multibody_spring.spring2d.flange_a, damper.flange_a))
push!(connections, connect(multibody_spring.spring2d.flange_b, damper.flange_b))

@named model = ODESystem(connections, t, systems = [world, multibody_spring, root_body, damper])
@named model = System(connections, t, systems = [world, multibody_spring, root_body, damper])
model = complete(model)
ssys = structural_simplify(multibody(model))
prob = ODEProblem(ssys, defs, (0, 10))
Expand All @@ -187,7 +187,7 @@ The systems we have modeled so far have all been _planar_ mechanisms. We now ext
This pendulum, sometimes referred to as a _rotary pendulum_, has two joints, one in the "shoulder", which is typically configured to rotate around the gravitational axis, and one in the "elbow", which is typically configured to rotate around the axis of the upper arm. The upper arm is attached to the shoulder joint, and the lower arm is attached to the elbow joint. The tip of the pendulum is attached to the lower arm.

```@example pendulum
using ModelingToolkit, Multibody, JuliaSimCompiler, OrdinaryDiffEq, Plots
using ModelingToolkit, Multibody, OrdinaryDiffEq, Plots
import ModelingToolkitStandardLibrary.Mechanical.Rotational.Damper as RDamper
import Multibody.Rotations

Expand Down Expand Up @@ -426,7 +426,7 @@ lsys = named_ss(multibody(cp), inputs, outputs; op) # identical to linearize, bu
### LQR and LQG Control design
With a linear statespace object in hand, we can proceed to design an LQR or LQG controller. We will design both an LQR and an LQG controller in order to demonstrate two possible workflows.

The LQR controller is designed using the function `ControlSystemsBase.lqr`, and it takes the two cost matrices `Q1` and `Q2` penalizing state deviation and control action respectively. The LQG controller is designed using [`RobustAndOptimalControl.LQGProblem`](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/#LQG-design), and this function additionally takes the covariance matrices `r1, R2` for a Kalman filter. Before we call `LQGProblem` we partition the linearized system into an [`ExtendedStateSpace`](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/api/#RobustAndOptimalControl.ExtendedStateSpace) object, this indicates which inputs of the system are available for control and which are considered disturbances, and which outputs of the system are available for measurement. In this case, we assume that we have access to the cart position and the pendulum angle, and we control the cart position. The remaining two outputs are still important for the performance, but we cannot measure them and will rely on the Kalman filter to estimate them. When we call [`extended_controller`](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/api/#RobustAndOptimalControl.extended_controller) we get a linear system that represents the combined state estimator and state feedback controller. This linear system is then converted to an `ODESystem` by the function `LQGSystem`.
The LQR controller is designed using the function `ControlSystemsBase.lqr`, and it takes the two cost matrices `Q1` and `Q2` penalizing state deviation and control action respectively. The LQG controller is designed using [`RobustAndOptimalControl.LQGProblem`](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/#LQG-design), and this function additionally takes the covariance matrices `r1, R2` for a Kalman filter. Before we call `LQGProblem` we partition the linearized system into an [`ExtendedStateSpace`](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/api/#RobustAndOptimalControl.ExtendedStateSpace) object, this indicates which inputs of the system are available for control and which are considered disturbances, and which outputs of the system are available for measurement. In this case, we assume that we have access to the cart position and the pendulum angle, and we control the cart position. The remaining two outputs are still important for the performance, but we cannot measure them and will rely on the Kalman filter to estimate them. When we call [`extended_controller`](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/api/#RobustAndOptimalControl.extended_controller) we get a linear system that represents the combined state estimator and state feedback controller. This linear system is then converted to an `System` by the function `LQGSystem`.

Since the function `lqr` operates on the state vector, and we have access to the specified output vector, we make use of the system ``C`` matrix to reformulate the problem in terms of the outputs. This relies on the ``C`` matrix being full rank, which is the case here since our outputs include a complete state realization of the system. This is of no concern when using the `LQGProblem` structure since we penalize outputs rather than the state in this case.

Expand All @@ -449,7 +449,7 @@ z = [:x] # The output for which we want to have unit static gain
Ce, cl = extended_controller(lqg, z = RobustAndOptimalControl.names2indices(z, Pn.y))
dc_gain_compensation = inv((Pn[:x, :].C*dcgain(cl)')[]) # Multiplier that makes the static gain from references to cart position unity

LQGSystem(args...; kwargs...) = ODESystem(Ce; kwargs...)
LQGSystem(args...; kwargs...) = System(Ce; kwargs...)

@mtkmodel CartWithFeedback begin
@components begin
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/prescribed_pose.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using ModelingToolkit
using Plots
using OrdinaryDiffEq
using LinearAlgebra
using JuliaSimCompiler
# using JuliaSimCompiler
using Test

t = Multibody.t
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/quad.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using ModelingToolkit
using ModelingToolkitStandardLibrary.Blocks
using LinearAlgebra
using Plots
using JuliaSimCompiler
# using JuliaSimCompiler
using OrdinaryDiffEq
using Test
t = Multibody.t
Expand Down Expand Up @@ -183,7 +183,7 @@ function RotorCraft(; closed_loop = true, addload=true, L=nothing, outputs = not
end

end
@named model = ODESystem(connections, t; systems)
@named model = System(connections, t; systems)
complete(model)
end
model = RotorCraft(closed_loop=true, addload=true, pid=true)
Expand Down
6 changes: 3 additions & 3 deletions docs/src/examples/robot.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Multibody
using ModelingToolkit
using Plots
using JuliaSimCompiler
# using JuliaSimCompiler
using OrdinaryDiffEq
using Test

Expand Down Expand Up @@ -109,7 +109,7 @@ The coordinates of any point on the mechanism may be obtained in the world coord

```@example robot
output = collect(robot.mechanics.b6.frame_b.r_0)
fkine = JuliaSimCompiler.build_explicit_observed_function(ssys, output)
fkine = build_explicit_observed_function(ssys, output)
fkine(prob.u0, prob.p, 0)
```

Expand All @@ -124,7 +124,7 @@ prob[output]

or by building an explicit function `(state, parameters, time) -> output`
```@example robot
fkine = JuliaSimCompiler.build_explicit_observed_function(ssys, output)
fkine = build_explicit_observed_function(ssys, output)
fkine(prob.u0, prob.p, 0)
```
!!! note
Expand Down
8 changes: 4 additions & 4 deletions docs/src/examples/ropes_and_cables.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ We start by simulating a stiff rope that is attached to the world in one end and
using Multibody
using ModelingToolkit
using Plots
using JuliaSimCompiler
# using JuliaSimCompiler
using OrdinaryDiffEq
using Test
t = Multibody.t
Expand All @@ -28,7 +28,7 @@ number_of_links = 6
connections = [connect(world.frame_b, rope.frame_a)
connect(rope.frame_b, body.frame_a)]

@named stiff_rope = ODESystem(connections, t, systems = [world, body, rope])
@named stiff_rope = System(connections, t, systems = [world, body, rope])

stiff_rope = complete(stiff_rope)
ssys = structural_simplify(multibody(stiff_rope))
Expand All @@ -52,7 +52,7 @@ number_of_links = 6
connections = [connect(world.frame_b, rope.frame_a)
connect(rope.frame_b, body.frame_a)]

@named flexible_rope = ODESystem(connections, t, systems = [world, body, rope])
@named flexible_rope = System(connections, t, systems = [world, body, rope])

flexible_rope = complete(flexible_rope)
ssys = structural_simplify(multibody(flexible_rope))
Expand Down Expand Up @@ -86,7 +86,7 @@ connections = [connect(world.frame_b, fixed.frame_a, chain.frame_a)
connect(chain.frame_b, spring.frame_a)
connect(spring.frame_b, fixed.frame_b)]

@named mounted_chain = ODESystem(connections, t, systems = [systems; world])
@named mounted_chain = System(connections, t, systems = [systems; world])
mounted_chain = complete(mounted_chain)
ssys = structural_simplify(multibody(mounted_chain))
prob = ODEProblem(ssys, [
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/sensors.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The example below adds a force and a torque sensor to the pivot point of a pendu
```@example sensor
using Multibody
using ModelingToolkit
using JuliaSimCompiler
# using JuliaSimCompiler
using Plots
using OrdinaryDiffEq
using LinearAlgebra
Expand All @@ -29,7 +29,7 @@ connections = [connect(world.frame_b, joint.frame_a)
connect(torquesensor.frame_b, forcesensor.frame_a)
connect(forcesensor.frame_b, body.frame_a)]

@named model = ODESystem(connections, t,
@named model = System(connections, t,
systems = [world, joint, body, torquesensor, forcesensor])
ssys = structural_simplify(multibody(model))

Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/space.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In this example, we set ``\mu = 1``, `point_gravity = true` and let two masses o
using Multibody
using ModelingToolkit
using Plots
using JuliaSimCompiler
# using JuliaSimCompiler
using OrdinaryDiffEq

t = Multibody.t
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/spherical_pendulum.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This example models a spherical pendulum. The pivot point is modeled using a [`S
using Multibody
using ModelingToolkit
using Plots
using JuliaSimCompiler
# using JuliaSimCompiler
using OrdinaryDiffEq

t = Multibody.t
Expand All @@ -25,7 +25,7 @@ connections = [connect(world.frame_b, joint.frame_a)
connect(joint.frame_b, bar.frame_a)
connect(bar.frame_b, body.frame_a)]

@named model = ODESystem(connections, t, systems = [world; systems])
@named model = System(connections, t, systems = [world; systems])
model = complete(model)
ssys = structural_simplify(multibody(model))

Expand Down
Loading
Loading