1+ using DyadBotComponents
2+ using WGLMakie
3+ using ModelingToolkit
4+ using OrdinaryDiffEq
5+
6+ f = Figure (size = (600 , 600 ); aspect= DataAspect ())
7+
8+ ax = Axis (f[1 , 1 ])
9+
10+ # TODO : connect to the bot parameters
11+ y1 = 1.0
12+ r = 1.0
13+
14+ y2 = 3.0
15+ w = 2
16+
17+
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)
23+
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)
27+
28+ poly! (ax, Rect (- 2.5 , 0 , 5 , 5 ); color= :transparent )
29+
30+ rotate! (spoke_transform, π* 0.1 )
31+ rotate! (spoke_transform, π* 0.2 )
32+ rotate! (spoke_transform, π* 0.3 )
33+
34+ translate! (base_transform, 0.5 )
35+
36+ rotate! (body_transform, - π* 0.1 )
37+
38+
39+
40+ @mtkcompile bot = DyadBotComponents. CascadeControlledFlatDyadBot ()
41+ prob = ODEProblem (bot, [bot. x_ref => 0.75 ], (0 ,200 ))
42+ sol = solve (prob)
43+
44+ plot (sol; idxs= bot. plant. x)
45+ plot (sol; idxs= bot. plant. theta)
46+ plot (sol; idxs= bot. ref. output. u)
47+
48+ nframes = 200
49+ framerate = 30
50+ times = range (0 , 200 , length= nframes)
51+
52+ translate! (base_transform, 0.0 )
53+ rotate! (body_transform, 0.0 )
54+ rotate! (spoke_transform, 0.0 )
55+
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)
60+
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