Skip to content

Commit c485650

Browse files
committed
fixing Dzhanibekov
1 parent 9952d32 commit c485650

File tree

8 files changed

+74
-47
lines changed

8 files changed

+74
-47
lines changed

docs/src/assets/dzhanibekov_nasa.gif

1.99 MB
Loading

docs/src/assets/quadruped_min.gif

-802 KB
Binary file not shown.

docs/src/define_simulation.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
1-
# Defining a Simulation
1+
# Defining a Simulation
2+
Here, we explain how to simulate a dynamical system i.e. a [`mechanism`](@ref) forward in time.
3+
The example that we are trying to replicate the Dzhanibekov effect shown below.
4+
5+
![dzhanibekov](./assets/dzhanibekov_nasa.gif)
6+
7+
8+
Load the `Dojo` package.
9+
```julia
10+
using Dojo
11+
```
12+
13+
Define the simulation timestep, and other parameters like the gravity.
14+
```julia
15+
timestep=0.01
16+
gravity=0.0
17+
```
18+
19+
We want to simulate the
20+
```julia
21+
mech = get_mechanism(:dzhanibekov,
22+
timestep=timestep,
23+
gravity=gravity);
24+
25+
# ## Simulate
26+
initialize_dzhanibekov!(mech,
27+
angular_velocity=[15.0; 0.01; 0.0])
28+
storage = simulate!(mech, 4.65,
29+
record=true,
30+
verbose=false)
31+
32+
# ## Visualizers
33+
vis=visualizer()
34+
render(vis)
35+
visualize(mech, storage,
36+
vis=vis)
37+
```
38+
39+
And voila! You should see something like this;
40+
41+
![dzhanibekov](./../../examples/animations/dzhanibekov.gif)

docs/src/impact.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@ where $\circ$ is an element-wise product operator, enforces zero force if the bo
2121

2222

2323
### Constructor
24-
```@docs
25-
ImpactContact
26-
```
24+
[`ImpactContact`](@ref)

docs/src/linearized_friction.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ $$[v^T -v^T]^T + \psi \mathbf{1} - \eta = 0, \\
2929
where $\psi \in \mathbf{R}$ and $\eta \in \mathbf{R}^{4}$ are the dual variables associated with the friction cone and positivity constraints, respectively, and $\textbf{1}$ is a vector of ones.
3030

3131
### Constructor
32-
```@docs
33-
LinearContact
34-
```
32+
[`LinearContact`](@ref)

docs/src/nonlinear_friction.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,4 @@ v^{(i)}(z, z_{+}) - \eta_{(2:3)}^{(i)} = 0, \quad i = 1, \dots, P, \\
4545
where $u \in \mathbf{R}^m$ is the control input at the current time step, $\lambda = (\beta^{(1)}_{(2:3)}, \gamma^{(1)}, \dots, \beta^{(P)}_{(2:3)}, \gamma^{(P)}) \in \mathbf{\Lambda}$ is the concatenation of impact and friction impulses, $B : \mathbf{Z} \rightarrow \mathbf{R}^{6N \times m}$ is the input Jacobian mapping control inputs into maximal coordinates, $C : \mathbf{Z} \rightarrow \mathbf{R}^{\text{dim}(\mathbf{\Lambda}) \times 6N}$ is a contact Jacobian mapping between maximal coordinates and contact surfaces, $s \in \mathbf{R}^P$ is a slack variable introduced for convenience, and $v^{(i)} : \mathbf{Z} \times \mathbf{Z} \rightarrow \mathbf{R}^2$ is the tangential velocity at contact point $i$. Joint limits and internal friction are readily incorporated into this problem formulation.
4646

4747
### Constructor
48-
```@docs
49-
NonlinearContact
50-
```
48+
[`NonlinearContact`](@ref)
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
function get_dzhanibekov(;
2-
timestep=0.01,
3-
gravity=-9.81,
1+
function get_dzhanibekov(;
2+
timestep=0.01,
3+
gravity=-9.81,
44
color=magenta) where T
55

66
radius = 0.1
77
body_length = 1.0
88
body_mass = 1.0
99
origin = Origin{Float64}()
10-
main_body = Capsule(radius, body_length, body_mass,
11-
color=color)
12-
side_body = Capsule(0.5 * radius, 0.35 * body_length, 0.1 * body_mass,
13-
axis_offset=UnitQuaternion(RotY(0.5 * π)),
14-
color=color)
10+
main_body = Capsule(radius, body_length, body_mass,
11+
color=color, name=:main)
12+
side_body = Capsule(0.5 * radius, 0.35 * body_length, 0.5 * body_mass,
13+
axis_offset=UnitQuaternion(RotY(0.5 * π)),
14+
color=color, name=:side)
1515
links = [main_body, side_body]
1616

1717
# Joint Constraints
18-
joint_float = JointConstraint(Floating(origin, links[1]))
19-
joint_attach = JointConstraint(Fixed(links[1], links[2];
20-
parent_vertex=szeros(3),
21-
child_vertex=[-0.25 * body_length; 0.0; 0.0]))
22-
joints = [joint_float, joint_attach]
18+
joint_float = JointConstraint(Floating(origin, links[1]), name=:floating)
19+
joint_fixed = JointConstraint(Fixed(links[1], links[2];
20+
parent_vertex=szeros(3),
21+
child_vertex=[-0.25 * body_length; 0.0; 0.0]), name=:fixed)
22+
joints = [joint_float, joint_fixed]
2323

24+
links[1].inertia = Diagonal([3e-2, 1e-3, 1e-1])
2425
# Mechanism
25-
return Mechanism(origin, links, joints,
26-
gravity=gravity,
26+
return Mechanism(origin, links, joints,
27+
gravity=gravity,
2728
timestep=timestep)
2829
end
2930

30-
function initialize_dzhanibekov!(mech::Mechanism{T,Nn,Ne,Nb};
31-
linear_velocity=zeros(3),
31+
function initialize_dzhanibekov!(mechanism::Mechanism{T,Nn,Ne,Nb};
32+
linear_velocity=zeros(3),
3233
angular_velocity=zeros(3)) where {T,Nn,Ne,Nb}
3334

34-
set_maximal_configurations!(mech.origin, mech.bodies[3])
35-
set_maximal_velocities!(mech.bodies[3],
36-
v=linear_velocity,
37-
ω=angular_velocity)
38-
39-
set_maximal_configurations!(mech.bodies[3], mech.bodies[4],
40-
Δx=[0.25; 0.0; 0.0])
41-
set_maximal_velocities!(mech.bodies[4],
42-
v=zeros(3),
43-
ω=zeros(3))
44-
end
35+
zero_velocity!(mechanism)
36+
set_minimal_coordinates_velocities!(mechanism, get_joint(mechanism, :floating);
37+
xmin=[szeros(6); linear_velocity; angular_velocity])
38+
set_minimal_coordinates_velocities!(mechanism, get_joint(mechanism, :fixed))
39+
end

examples/simulation/dzhanibekov.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ using Dojo
99
timestep=0.01
1010
gravity=0.0
1111
mech = get_mechanism(:dzhanibekov,
12-
timestep=timestep,
12+
timestep=timestep,
1313
gravity=gravity);
1414

1515
# ## Simulate
16-
initialize_dzhanibekov!(mech,
16+
initialize_dzhanibekov!(mech,
1717
angular_velocity=[15.0; 0.01; 0.0])
18-
storage = simulate!(mech, 4.65,
19-
record=true,
18+
storage = simulate!(mech, 4.00,
19+
record=true,
2020
verbose=false)
2121

2222
# ## Visualizers
23-
vis=visualizer()
24-
render(vis)
25-
visualize(mech, storage,
26-
vis=vis)
27-
23+
vis = Visualizer()
24+
open(vis)
25+
visualize(mech, storage, vis=vis)

0 commit comments

Comments
 (0)