@@ -2,6 +2,7 @@ using QuanserInterface
2
2
using HardwareAbstractions
3
3
using ControlSystemsBase
4
4
using QuanserInterface: energy
5
+ using Test
5
6
6
7
7
8
rr = Ref ([0 , pi , 0 , 0 ])
@@ -44,7 +45,7 @@ function swingup(process; Tf = 10, verbose=true, stab=true, umax=5.0)
44
45
end
45
46
y = QuanserInterface. measure (process)
46
47
if verbose && ! simulation
47
- @info " Starting $(simulation ? " simulation" : " experiment" ) from y: $y , waiting for your input..."
48
+ verbose && @info " Starting $(simulation ? " simulation" : " experiment" ) from y: $y , waiting for your input..."
48
49
# readline()
49
50
end
50
51
yo = zeros (2 )
@@ -68,17 +69,17 @@ function swingup(process; Tf = 10, verbose=true, stab=true, umax=5.0)
68
69
r = rr[]
69
70
if ! (- deg2rad (110 ) <= y[1 ] <= deg2rad (110 ))
70
71
u = [- 0.5 * y[1 ]]
71
- @warn " Correcting"
72
+ verbose && @warn " Correcting"
72
73
control (process, u)
73
74
oob += 20
74
75
if oob > 600
75
- @error " Out of bounds"
76
+ verbose && @error " Out of bounds"
76
77
break
77
78
end
78
79
else
79
80
oob = max (0 , oob- 1 )
80
81
if stab && abs (normalize_angles (y[2 ]) - pi ) < 0.50
81
- @info " stabilizing"
82
+ verbose && @info " stabilizing"
82
83
u = clamp .(L* (r - xhn), - 10 , 10 )
83
84
else
84
85
# xhn = (process.x) # Try with correct state if in simulation
@@ -109,7 +110,7 @@ function swingup(process; Tf = 10, verbose=true, stab=true, umax=5.0)
109
110
end
110
111
111
112
process = QuanserInterface. QubeServoPendulumSimulator (; Ts, p = QuanserInterface. pendulum_parameters (true ))
112
- function runplot (process; kwargs... )
113
+ function runplot (process; verbose = isinteractive (), kwargs... )
113
114
rr[][1 ] = deg2rad (0 )
114
115
rr[][2 ] = pi
115
116
y = QuanserInterface. measure (process)
@@ -118,7 +119,7 @@ function runplot(process; kwargs...)
118
119
autohome! (process)
119
120
end
120
121
global D
121
- D = swingup (process; kwargs... )
122
+ D = swingup (process; verbose, kwargs... )
122
123
isinteractive () && plotD (D)
123
124
end
124
125
0 commit comments