Commit 8c9b11cb authored by Torbjørn Ludvigsen's avatar Torbjørn Ludvigsen 👷

Makes README.md and simulation.py easier to understand

parent 1df0762e
......@@ -19,7 +19,84 @@ python setup.py build
sudo python setup.py install
```
Once dependencies are in place, the simulation runs with
Once dependencies and data are in place, the simulation runs with
```bash
python ./simulation.py
```
If it works, then your output looks similar to
```python
cost: 0.254896
Output Anchors:
[[ 0. -1164.30732212 -143.53179478]
[ 998.78058643 585.33185503 -114.97805252]
[ -977.11333826 518.87558222 -105.60105899]
[ 0. 0. 2874.86861506]]
Errors:
[[ 0.00000000e+00 -5.23073221e+01 -2.85317948e+01]
[ 2.87805864e+01 3.53318550e+01 2.19474805e-02]
[ -7.11333826e+00 -3.11244178e+01 9.39894101e+00]
[ 0.00000000e+00 0.00000000e+00 9.86861506e+00]]
```
Note that these values are only test data and does not correspond to your Hangprinter setup (yet).
## How to Collect Data Points?
Data collection depends on Mechaduinos and well calibrated line buildup compensation.
As of Jan 31, 2018, this is the procedure (using HangprinterMarlin, not stock Marlin yet).
- Go into torque mode on all motors: `G95 A35 B35 C35 D35`.
Adjust torque magnitude as you prefer.
- Drag mover to the origin and zero counters: `G92 X0 Y0 Z0`
- Mark reference point for all encoders: `G96 A B C D`
- Repeat 10 - 20 times:
- Drag mover to position of data point collection.
- Collect data point: `G97 A B C D`
## How to Insert Data Points?
Before you run the simulation, open `simulation.py` and modify the main function.
Replace `?` with your approximated values (not mandatory but useful).
Replace `??` with data points collected with your Hangprinter.
At least 10 data points at a mean distance ~1m from the origin are recommended.
```python
if __name__ == "__main__":
# Rough approximations from manual measuring.
# Does not affect optimization result. Only used for manual sanity check.
az = ?
bz = ?
cz = ?
anchors = np.array([[ 0.0, ?, az],
[ ?, ?, bz],
[ ?, ?, cz],
[ 0.0, 0.0, ?]])
# Replace this with your collected data
samp = np.array([
[??, ??, ??, ??],
[??, ??, ??, ??]
])
```
When values are inserted, run again with
```bash
python ./simulation.py
```
## Output Explanation
```python
cost: 0.254896
Output Anchors:
[[ 0. -1164.30732212 -143.53179478]
[ 998.78058643 585.33185503 -114.97805252]
[ -977.11333826 518.87558222 -105.60105899]
[ 0. 0. 2874.86861506]]
Errors:
[[ 0.00000000e+00 -5.23073221e+01 -2.85317948e+01]
[ 2.87805864e+01 3.53318550e+01 2.19474805e-02]
[ -7.11333826e+00 -3.11244178e+01 9.39894101e+00]
[ 0.00000000e+00 0.00000000e+00 9.86861506e+00]]
```
Ideal data points collected on an ideal machine would give `cost: 0.0`.
In real life this does not happen.
The cost value is there to let you compare your different data sets of equal size.
The `Output Anchors`-set with the lowest cost is generally your best one.
The `Errors` is your manual sanity check.
`Errors` are calculated by differentiating with your approximations denoted `?` above.
......@@ -276,7 +276,8 @@ def solve(samp, _cost = cost_sq):
return solver0.bestSolution
if __name__ == "__main__":
# Gotten from manual measuring
# Rough approximations from manual measuring.
# Does not affect optimization result. Only used for manual sanity check.
az = -115.
bz = -115.
cz = -115.
......@@ -285,70 +286,8 @@ if __name__ == "__main__":
[-970.0, 550.0, cz],
[ 0.0, 0.0, 2865.0]])
# data 1
# samp = np.array([
#[126.31 , 5.02 , -0.21 , -213.52],
#[295.03 , -257.68 , 218.73 , -244.16],
#[511.65 , 94.13 , 116.17 , -585.52],
#[373.57 , 615.00 , -132.03 , -570.93],
#[285.95 , 468.10 , -475.99 , -112.57],
#[411.75 , -471.95 , 279.45 , -61.84],
#[646.11 , 257.49 , 289.34 , -845.42],
#[43.83 , 384.27 , 262.25 , -618.82],
#[-416.94 , 392.71 , 305.03 , -178.76],
#[-355.53 , 308.31 , 408.93 , -267.15],
#[191.34 , 555.78 , 209.78 , -741.28],
#[537.90 , 574.98 , 470.11 , -1102.07],
#[636.51 , 380.17 , 709.07 , -1118.74],
#[897.10 , 913.95 , 702.54 , -1473.05]
#])
# data 2
# samp = np.array([
#[400.53 , 175.53 , 166.10 , -656.90],
#[229.27 , 511.14 , -48.41 , -554.31],
#[-41.69 , -62.87 , 306.76 , -225.31],
#[272.97 , 176.65 , 381.13 , -717.81],
#[338.07 , 633.70 , 309.27 , -911.22],
#[504.47 , 658.88 , 48.60 , -794.42],
#[504.47 , 658.88 , 48.60 , -794.42],
#[103.50 , 569.98 , 633.68 , -860.25],
#[229.37 , 7.32 , 411.98 , -575.81],
#[428.73 , -413.46 , 250.38 , -133.93],
#[-506.97 , 343.33 , 327.68 , -4.40]
# ])
# data 3
# samp = np.array([
#[571.85 , -773.44 , 578.54 , 59.12],
#[647.64 , 654.08 , -858.11 , 90.96],
#[-860.99 , 675.57 , 630.82 , 94.65],
#[318.70 , 741.68 , 209.66 , -824.57],
#[754.92 , 466.22 , 418.71 , -1066.04],
#[450.51 , 403.77 , 699.62 , -1046.80],
#[1234.76 , 1174.05 , 1183.26 , -1913.14],
#[283.26 , 162.84 , 182.21 , -603.33],
#[663.00 , -139.32 , 603.13 , -648.02],
#[661.00 , 625.20 , -73.58 , -713.35],
#[-33.50 , 643.97 , 658.06 , -754.40]
# ])
# data 1 & 2 & 3
# Replace this with your collected data
samp = np.array([
[126.31 , 5.02 , -0.21 , -213.52],
[295.03 , -257.68 , 218.73 , -244.16],
[511.65 , 94.13 , 116.17 , -585.52],
[373.57 , 615.00 , -132.03 , -570.93],
[285.95 , 468.10 , -475.99 , -112.57],
[411.75 , -471.95 , 279.45 , -61.84],
[646.11 , 257.49 , 289.34 , -845.42],
[43.83 , 384.27 , 262.25 , -618.82],
[-416.94 , 392.71 , 305.03 , -178.76],
[-355.53 , 308.31 , 408.93 , -267.15],
[191.34 , 555.78 , 209.78 , -741.28],
[537.90 , 574.98 , 470.11 , -1102.07],
[636.51 , 380.17 , 709.07 , -1118.74],
[897.10 , 913.95 , 702.54 , -1473.05],
[400.53 , 175.53 , 166.10 , -656.90],
[229.27 , 511.14 , -48.41 , -554.31],
[-41.69 , -62.87 , 306.76 , -225.31],
......@@ -359,18 +298,7 @@ if __name__ == "__main__":
[103.50 , 569.98 , 633.68 , -860.25],
[229.37 , 7.32 , 411.98 , -575.81],
[428.73 , -413.46 , 250.38 , -133.93],
[-506.97 , 343.33 , 327.68 , -4.40],
[571.85 , -773.44 , 578.54 , 59.12],
[647.64 , 654.08 , -858.11 , 90.96],
[-860.99 , 675.57 , 630.82 , 94.65],
[318.70 , 741.68 , 209.66 , -824.57],
[754.92 , 466.22 , 418.71 , -1066.04],
[450.51 , 403.77 , 699.62 , -1046.80],
[1234.76 , 1174.05 , 1183.26 , -1913.14],
[283.26 , 162.84 , 182.21 , -603.33],
[663.00 , -139.32 , 603.13 , -648.02],
[661.00 , 625.20 , -73.58 , -713.35],
[-33.50 , 643.97 , 658.06 , -754.40]
[-506.97 , 343.33 , 327.68 , -4.40]
])
u = np.shape(samp)[0]
......@@ -380,7 +308,6 @@ if __name__ == "__main__":
sol_anch = anchorsvec2matrix(solution[0:params_anch])
the_cost = cost_sq(anchorsvec2matrix(solution[0:params_anch]), np.reshape(solution[params_anch:], (u,3)), samp)
print("cost: %f" % the_cost)
print("cost per sample: %f" % (the_cost/u))
print("Output Anchors: ")
print(sol_anch)
print("Errors: ")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment