You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-29
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
-
# API for Simulating Multi-link System
1
+
API for Simulating Multi-link System
2
+
====================================
2
3
Final project of ME314 Machine Dynamics
3
4
4
5
student: Feiyu Chen
@@ -11,22 +12,30 @@ video domos:
11
12
12
13
pdf version of README: [pdf](README.pdf) (Due to some math eqs are not shown well on github.)
13
14
14
-
# Contents:
15
-
-[1. Introduction](#1.-Introduction)
16
-
-[2. Files](#2.-Files)
17
-
-[3. API Functions](#3.-API-Functions)
18
-
-[4. Example of Using My Functions](#4.-Example-of-Using-My-Functions)
19
-
-[5. Calculation of EL-eqs and Impacts](#5.-Calculation-of-EL-eqs-and-Impacts)
20
-
-[6. How is This API being Generalized](#6.-How-is-This-Api-Being-Generalized)
21
-
-[7. Problems](#7.-Problems)
15
+
**Contents:**
16
+
-[API for Simulating Multi-link System](#api-for-simulating-multi-link-system)
17
+
-[1. Introduction](#1-introduction)
18
+
-[1.1. Why I made this API](#11-why-i-made-this-api)
19
+
-[1.2. Intro](#12-intro)
20
+
-[1.3. How to run](#13-how-to-run)
21
+
-[2. Files](#2-files)
22
+
-[3. API Functions](#3-api-functions)
23
+
-[4. Example of Using My Functions](#4-example-of-using-my-functions)
24
+
-[5. Calculation of EL-eqs and Impacts](#5-calculation-of-el-eqs-and-impacts)
25
+
-[5.1. Kinetic and Potential Energy](#51-kinetic-and-potential-energy)
26
+
-[5.2. Constraint and External Force](#52-constraint-and-external-force)
27
+
-[5.3. Detecting Impacts](#53-detecting-impacts)
28
+
-[5.4. Impact Update](#54-impact-update)
29
+
-[6. How is This API being Generalized](#6-how-is-this-api-being-generalized)
30
+
-[7. Problems](#7-problems)
22
31
23
32
24
33
# 1. Introduction
25
34
26
-
## 1.1 Why I made this API
35
+
## 1.1. Why I made this API
27
36
It can be a big headache to hardcode the simulation of multi-link system in Mathematica, as it's nontrivial to type in all formulas and to deal with all kinds of weird bugs. The goal of this project is to reduce such pain by wrapping up an API (> Application Programming Interface) so users/students could build up a simulation by using simple functions.
28
37
29
-
## 1.2 Intro
38
+
## 1.2. Intro
30
39
31
40
The core of the API is a set of functions called "createLink", with Applications of creating links, triangle (polygon), vertices and wall. I made 4 scenes to demonstrate the usage of my API which are stored in "./scenes/". The videos are in current folder. The images are shown here.
32
41
@@ -35,52 +44,52 @@ The core of the API is a set of functions called "createLink", with Applications
35
44
Figure 1. Four example scenes of multi-link system.
36
45
37
46
38
-
## 1.3 How to run
47
+
## 1.3. How to run
39
48
40
49
Open this [run_this.nb](run_this.nb). Modify code and choose a scene in the second cell (you can search the keyword "Choose a scene"). And then run through the whole script.
41
50
The scenes .nb files are in "./scenes/".
42
51
43
52
# 2. Files
44
-
##2.1 run_this.nb
53
+
* 2.1. run_this.nb
45
54
This is the main file.
46
55
47
-
##2.2 scenes/
56
+
* 2.2. scenes/
48
57
The scenes are stored in "./scenes/". Inside each scene script, there is a only function called "CreateObjects[]". Inside it, the codes describe the links that form the simulation. You may change it and create your own.
49
58
50
-
##2.3 lib/
59
+
* 2.3. lib/
51
60
This stores 3 library files: [funcs_assist.nb](funcs_assist.nb), [funcs_main.nb](funcs_main.nb), and [funcs_math.nb](funcs_math.nb). They provide the necessary functions and parameters for the main script. They will be loaded when running the "run_this.nb".
52
61
53
62
# 3. API Functions
54
63
I wrote 5 functions:
55
64
56
-
### 3.1 createVertex
65
+
* createVertex
57
66
58
67
Create a vertex.
59
68
60
69
> Application: create a point obstacle, or append a link to it to make a pendulum.
61
70
62
-
### 3.2 createLink0DOFpp
71
+
* createLink0DOFpp
63
72
64
73
Create a link with 0 degrees of freedom (DOF). The "pp" at the end indicates that the inputs are two points "point1" and "point2" with format of 2-vector.
65
74
66
75
> Application: create a wall, or append it to another link to form a rigid body. See an example in Example 1 of creating polygon.
67
76
68
-
### 3.3 createLink0DOFg$\mathbf{\theta}$l
77
+
* createLink0DOFg$\mathbf{\theta}$l
69
78
70
79
This is same as above for creating a 0 DOF link, except that the inputs are:
71
80
* The starting coordinate's 4x4 matrix $\mathbf{g}$.
72
81
* Relative angle $\theta$.
73
82
* Length of this link $\mathbf{l}$.
74
83
75
-
### 3.4 createLink1DOFg$\mathbf{\theta}$l
84
+
* createLink1DOFg$\mathbf{\theta}$l
76
85
77
86
Create a 1 DOF link. The link can rotate around its starting coordinate $\mathbf{g}$.
78
87
79
88
The inputs "g$\mathbf{\theta}$l" are the same as above, which are used for specifying the starting coordinate, relative angle, and length of this link.
80
89
81
90
> Application: append this link to a pendulum. For example, turning a double-pendulum into a triple-pendulum.
82
91
83
-
### 3.5 createLink3DOFpp
92
+
* createLink3DOFpp
84
93
85
94
Create a 3 DOF link that can move in $\mathbf{x}$ and $\mathbf{y}$ direction and rotate around its center for angle $\theta$.
86
95
Its inputs are the initial positions of its two vertices.
@@ -136,14 +145,14 @@ createLink0DOF
136
145
137
146
After creating these links, you can simply run the main file and see the animation.
138
147
139
-
##5. Calculation of EL-eqs and Impacts
148
+
# 5. Calculation of EL-eqs and Impacts
140
149
141
-
###5.1 Kinetic and Potential Energy
150
+
## 5.1. Kinetic and Potential Energy
142
151
Suppose a link has length $\mathbf{l}$. Then I assume its mass to be $\mathbf{l}$ and inertia to be $\mathbf{l^2}$. The generalized 6x6 body mass M is then obtained.
143
152
144
153
For each link, I compute the 4x4 matrix representation $\mathbf{g}$ of its center frame. Then calculate the body screw velocity $\mathbf{V}$ using $\mathbf{g}$ and $\mathbf{dg/dt}$. Then the kinetic energy is $\frac{1}{2}\mathbf{V^T M V}$.
145
154
146
-
###5.2 Constraint and External Force
155
+
## 5.2. Constraint and External Force
147
156
148
157
These two elements can be easily added up to the EL-eqs.
149
158
@@ -153,7 +162,7 @@ In scene1.nb, I add a constraint to the link at right up corner. I fixed its hei
153
162
The external forces are set in this sentence:
154
163
> externalForces = ConstantArray[0, nVars];
155
164
156
-
###5.3 Detecting Impacts
165
+
## 5.3. Detecting Impacts
157
166
158
167
The impact happens when **one link's vertex** goes through **another link's edge**. The two links should also from different groups.
159
168
@@ -166,7 +175,7 @@ For determining whether a vertex is inside the edge, I wrote two different metho
166
175
167
176
(Meanwhile, whether the projection of vertex is on edge is also considered.)
168
177
169
-
###5.4 Impact Update
178
+
## 5.4. Impact Update
170
179
171
180
The logic of my code for impact detection looks like this:
172
181
@@ -195,23 +204,23 @@ Loop{
195
204
196
205
197
206
# 7. Problems
198
-
###**Not Detecting Some Impacts**
207
+
***Not Detecting Some Impacts**
199
208
At some occasions, the vertex might go through the edge. The cause is that the object's velocity is too large, or the integration step length is too large. Currently, I didn't implement any advanced techinques to go back and forth to check the exact impact time.
200
209
201
210
So you might need to reduce the integration step length, or make your scene smaller (thus less potential energy and a smaller max speed).
202
211
203
-
###**Slow Computing**
212
+
***Slow Computing**
204
213
When the total DOF<10, links<15, step_size=0.001, simulation_time=15s, it takes about 3 minutes to compute all motions. Thus, the DOF and links cannot be too many, or it will cost too much time to compute impacts and do NDSolve.
205
214
206
-
###**Be Cautions with Constraint**
215
+
***Be Cautions with Constraint**
207
216
When applying constraint to a configuration variable, we must make sure that this variable won't move perpendicular to the constraint surface. Two cases (which are not subject to the solution of EL-eqs) can cause problem of making total energy not conserved:
208
217
209
218
1. Wrong initial velocity.
210
219
2. Impacts.
211
220
212
221
The reason is that we are actually not applying constraint $\mathbf{\phi}$. Instead, we use $\mathbf{d\phi /dq}$ and $\mathbf{d^2\phi /dt^2}$ for solving EL-eqs.
213
222
214
-
###**No Varying Constraint**
223
+
***No Varying Constraint**
215
224
I didn't add varying constraint in this project. But I do make an analysis of how to do it below:
216
225
217
226
Consider a chair on the floor. Under my current scheme, the chair will keep on impacting with the floor and make the simulation slow and inaccurate.
0 commit comments