@@ -3,65 +3,76 @@ using WGLMakie
33using ModelingToolkit
44using OrdinaryDiffEq
55
6- f = Figure (size = (600 , 600 ); aspect= DataAspect ())
6+ t_end = 100
7+ @mtkcompile bot = DyadBotComponents. CascadeControlledFlatDyadBot ()
8+ prob = ODEProblem (bot, [bot. x_ref => 0.75 ], (0 ,t_end))
9+ sol = solve (prob)
710
8- ax = Axis (f[1 , 1 ])
11+ plot (sol; idxs= [bot. ref. output. u, bot. plant. x])
12+ plot (sol; idxs= bot. plant. theta)
913
10- # TODO : connect to the bot parameters
11- y1 = 1.0
12- r = 1.0
1314
14- y2 = 3.0
15- w = 2
15+ function get_figure ()
1616
17+ defs = ModelingToolkit. defaults (bot)
1718
18- base_transform = Transformation (origin = Vec3d (0.0 , y1, 0 ))
19- spoke_transform = Transformation (base_transform; origin = Vec3d (0.0 , y1, 0 ))
20- linesegments! (ax, [- r,+ r], [y1,y1]; transformation= spoke_transform, color= :blue )
21- linesegments! (ax, [0.0 ,0.0 ], [y1- r,y1+ r]; transformation= spoke_transform, color= :blue )
22- poly! (ax, Circle (Point2f (0.0 ,y1), r); color= :transparent , strokecolor= :blue , strokewidth= 2 , transformation= spoke_transform)
19+ r = defs[bot. plant. R] # wheel radius
20+ y1 = r
2321
24- body_transform = Transformation (base_transform; origin = Vec3d (0.0 , y1, 0 ))
25- poly! (ax, Rect (0.0 - 0.25 / 2 , y1, 0.25 , y2- y1); color= :transparent , strokecolor= :red , strokewidth= 2 , transformation= body_transform)
26- poly! (ax, Rect (0.0 - w/ 2 , y2, w, w); color= :transparent , strokecolor= :green , strokewidth= 2 , transformation= body_transform)
22+ L = defs[bot. plant. L] # body length
23+ y2 = y1 + L
2724
28- poly! (ax, Rect (- 2.5 , 0 , 5 , 5 ); color= :transparent )
25+ w1 = r* 0.5
26+ w2 = r* 2
2927
30- rotate! (spoke_transform, π* 0.1 )
31- rotate! (spoke_transform, π* 0.2 )
32- rotate! (spoke_transform, π* 0.3 )
3328
34- translate! (base_transform, 0.5 )
29+ f = Figure (size = (600 , 600 ); aspect= DataAspect ())
30+ ax = Axis (f[1 , 1 ])
31+
3532
36- rotate! (body_transform, - π* 0.1 )
33+ # wheel
34+ base_transform = Transformation (origin = Vec3d (0.0 , y1, 0 ))
35+ spoke_transform = Transformation (base_transform; origin = Vec3d (0.0 , y1, 0 ))
36+ linesegments! (ax, [- r,+ r], [y1,y1]; transformation= spoke_transform, color= :blue )
37+ linesegments! (ax, [0.0 ,0.0 ], [y1- r,y1+ r]; transformation= spoke_transform, color= :blue )
38+ poly! (ax, Circle (Point2f (0.0 ,y1), r); color= :transparent , strokecolor= :blue , strokewidth= 2 , transformation= spoke_transform)
3739
40+ # body
41+ body_transform = Transformation (base_transform; origin = Vec3d (0.0 , y1, 0 ))
42+ poly! (ax, Rect (0.0 - w1/ 2 , y1, w1, y2- y1); color= :transparent , strokecolor= :red , strokewidth= 2 , transformation= body_transform)
43+ poly! (ax, Rect (0.0 - w2/ 2 , y2, w2, w2); color= :transparent , strokecolor= :green , strokewidth= 2 , transformation= body_transform)
3844
45+ # frame
46+ poly! (ax, Rect (- 3 / 2 , 0 , 3 , 3 ); color= :transparent )
3947
40- @mtkcompile bot = DyadBotComponents. CascadeControlledFlatDyadBot ()
41- prob = ODEProblem (bot, [bot. x_ref => 0.75 ], (0 ,200 ))
42- sol = solve (prob)
48+ return f, base_transform, spoke_transform, body_transform
49+ end
4350
44- plot (sol; idxs= bot. plant. x)
45- plot (sol; idxs= bot. plant. theta)
46- plot (sol; idxs= bot. ref. output. u)
51+ f, base_transform, spoke_transform, body_transform = get_figure ()
4752
48- nframes = 200
49- framerate = 30
50- times = range (0 , 200 , length= nframes)
53+ function animate (;framerate = 30 , filename= " dyadbot.mp4" )
5154
52- translate! (base_transform, 0.0 )
53- rotate! (body_transform, 0.0 )
54- rotate! (spoke_transform, 0.0 )
55+ nframes = 500
56+ times = range (0 , t_end, length= nframes)
5557
56- record (f, " dyadbot.mp4" , times;
57- framerate = 10 ) do t
58- x = sol (t; idxs= bot. plant. x)
59- theta = sol (t; idxs= bot. plant. theta)
58+ translate! (base_transform, 0.0 )
59+ rotate! (body_transform, 0.0 )
60+ rotate! (spoke_transform, 0.0 )
61+
62+ record (f, filename, times;
63+ framerate) do t
64+ x = sol (t; idxs= bot. plant. x)
65+ theta = sol (t; idxs= bot. plant. theta)
66+
67+ # x = wheel*r*π
68+
69+ translate! (base_transform, x)
70+ rotate! (body_transform, - theta + π)
71+ rotate! (spoke_transform, - x/ (r* π))
72+ end
73+
74+ end
75+
76+ animate (; framerate= 5 , filename = " dyadbot_slow.mp4" )
77+ animate (; framerate= 30 , filename = " dyadbot_fast.mp4" )
6078
61- # x = wheel*r*π
62-
63- translate! (base_transform, x)
64- rotate! (body_transform, - theta + π)
65- rotate! (spoke_transform, - x/ (r* π))
66-
67- end
0 commit comments