pylever-dyn 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pylever_dyn-0.0.1/.flake8 +2 -0
- pylever_dyn-0.0.1/.gitignore +9 -0
- pylever_dyn-0.0.1/.python-version +1 -0
- pylever_dyn-0.0.1/LICENSE +21 -0
- pylever_dyn-0.0.1/PKG-INFO +366 -0
- pylever_dyn-0.0.1/README.md +338 -0
- pylever_dyn-0.0.1/code/main.py +7 -0
- pylever_dyn-0.0.1/docs/palanca_paper.tex +503 -0
- pylever_dyn-0.0.1/examples/customer_curve.csv +14 -0
- pylever_dyn-0.0.1/examples/direct_calculation.py +43 -0
- pylever_dyn-0.0.1/examples/inverse_design.py +39 -0
- pylever_dyn-0.0.1/examples/pedal_2021_geometry.json +7 -0
- pylever_dyn-0.0.1/examples/report.py +49 -0
- pylever_dyn-0.0.1/makefile +24 -0
- pylever_dyn-0.0.1/pyproject.toml +47 -0
- pylever_dyn-0.0.1/resources/Pedals Dynamic study 20210317.xls +0 -0
- pylever_dyn-0.0.1/src/pylever/__init__.py +0 -0
- pylever_dyn-0.0.1/src/pylever/analysis/__init__.py +0 -0
- pylever_dyn-0.0.1/src/pylever/components/__init__.py +20 -0
- pylever_dyn-0.0.1/src/pylever/components/dampers.py +119 -0
- pylever_dyn-0.0.1/src/pylever/components/force_law.py +211 -0
- pylever_dyn-0.0.1/src/pylever/components/slider_crank.py +165 -0
- pylever_dyn-0.0.1/src/pylever/components/springs.py +266 -0
- pylever_dyn-0.0.1/src/pylever/geometry/__init__.py +4 -0
- pylever_dyn-0.0.1/src/pylever/geometry/geometry.py +150 -0
- pylever_dyn-0.0.1/src/pylever/geometry/point.py +77 -0
- pylever_dyn-0.0.1/src/pylever/io/__init__.py +0 -0
- pylever_dyn-0.0.1/src/pylever/mechanism/__init__.py +15 -0
- pylever_dyn-0.0.1/src/pylever/mechanism/dynamics.py +156 -0
- pylever_dyn-0.0.1/src/pylever/mechanism/lever_system.py +212 -0
- pylever_dyn-0.0.1/src/pylever/mechanism/spring_fit.py +365 -0
- pylever_dyn-0.0.1/src/pylever/report/__init__.py +25 -0
- pylever_dyn-0.0.1/src/pylever/report/lever_report.py +494 -0
- pylever_dyn-0.0.1/src/pylever/report/spring_export.py +332 -0
- pylever_dyn-0.0.1/srcold/examples/pedal_freno.py +83 -0
- pylever_dyn-0.0.1/srcold/main.py +18 -0
- pylever_dyn-0.0.1/srcold/palanca/__init__.py +45 -0
- pylever_dyn-0.0.1/srcold/palanca/analysis.py +175 -0
- pylever_dyn-0.0.1/srcold/palanca/curves.py +110 -0
- pylever_dyn-0.0.1/srcold/palanca/dynamics.py +89 -0
- pylever_dyn-0.0.1/srcold/palanca/elements.py +341 -0
- pylever_dyn-0.0.1/srcold/palanca/excel.py +158 -0
- pylever_dyn-0.0.1/srcold/palanca/geometry.py +107 -0
- pylever_dyn-0.0.1/srcold/palanca/lever.py +115 -0
- pylever_dyn-0.0.1/srcold/palanca/plotting.py +119 -0
- pylever_dyn-0.0.1/srcold/tests/test_excel_validation.py +108 -0
- pylever_dyn-0.0.1/srcold/tests/test_physics.py +126 -0
- pylever_dyn-0.0.1/tests/__init__.py +0 -0
- pylever_dyn-0.0.1/tests/conftest.py +40 -0
- pylever_dyn-0.0.1/tests/data/excel_2021_booster_back.csv +23 -0
- pylever_dyn-0.0.1/tests/data/excel_2021_booster_in.csv +23 -0
- pylever_dyn-0.0.1/tests/data/excel_2021_sweep.csv +45 -0
- pylever_dyn-0.0.1/tests/data/excel_2021_target.csv +35 -0
- pylever_dyn-0.0.1/tests/test_dampers.py +63 -0
- pylever_dyn-0.0.1/tests/test_dynamics.py +72 -0
- pylever_dyn-0.0.1/tests/test_force_law.py +107 -0
- pylever_dyn-0.0.1/tests/test_geometry.py +84 -0
- pylever_dyn-0.0.1/tests/test_lever_system.py +107 -0
- pylever_dyn-0.0.1/tests/test_report.py +171 -0
- pylever_dyn-0.0.1/tests/test_slider_crank.py +126 -0
- pylever_dyn-0.0.1/tests/test_spring_fit.py +107 -0
- pylever_dyn-0.0.1/tests/test_springs.py +132 -0
- pylever_dyn-0.0.1/uv.lock +2035 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ernesto Avedillo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pylever-dyn
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Kinematic and dynamic analysis of planar levers, oriented to the design of brake pedals
|
|
5
|
+
Author: Ernesto Avedillo
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.13
|
|
9
|
+
Requires-Dist: matplotlib>=3.8
|
|
10
|
+
Requires-Dist: numpy>=2.0
|
|
11
|
+
Requires-Dist: pypdf>=5
|
|
12
|
+
Requires-Dist: reportlab>=4
|
|
13
|
+
Requires-Dist: scipy>=1.18.1
|
|
14
|
+
Requires-Dist: springcalc>=0.1.27
|
|
15
|
+
Provides-Extra: all
|
|
16
|
+
Requires-Dist: matplotlib>=3.8; extra == 'all'
|
|
17
|
+
Requires-Dist: pandas>=2.2; extra == 'all'
|
|
18
|
+
Requires-Dist: xlrd>=2.0; extra == 'all'
|
|
19
|
+
Provides-Extra: excel
|
|
20
|
+
Requires-Dist: xlrd>=2.0; extra == 'excel'
|
|
21
|
+
Provides-Extra: pandas
|
|
22
|
+
Requires-Dist: pandas>=2.2; extra == 'pandas'
|
|
23
|
+
Provides-Extra: plot
|
|
24
|
+
Requires-Dist: matplotlib>=3.8; extra == 'plot'
|
|
25
|
+
Provides-Extra: step
|
|
26
|
+
Requires-Dist: cadquery>=2.8.0; extra == 'step'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# pylever
|
|
30
|
+
|
|
31
|
+
Kinematics, statics, and dynamics of planar levers, focused on the design of **pedals**
|
|
32
|
+
(brake, clutch, and accelerator): compression, extension, and torsion springs, slider-crank
|
|
33
|
+
(booster / CMC), weight, friction, and dampers.
|
|
34
|
+
|
|
35
|
+
Two ways to work:
|
|
36
|
+
|
|
37
|
+
- **Forward calculation**: given the lever and its components, calculate the force-travel curve
|
|
38
|
+
(press and release) and **free return** (velocity and energy) from any percentage of travel.
|
|
39
|
+
- **Inverse calculation**: given a customer curve (CSV), find the anchor positions and springs
|
|
40
|
+
that reproduce it, and design real springs with [springcalc](https://pypi.org/project/springcalc/).
|
|
41
|
+
|
|
42
|
+
The full mathematical explanation is in [docs/palanca_paper.tex](docs/palanca_paper.tex).
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
uv sync # development environment
|
|
48
|
+
uv sync --extra step # + cadquery, to export springs to STEP
|
|
49
|
+
uv run pytest # tests
|
|
50
|
+
uv run python examples/direct_calculation.py
|
|
51
|
+
uv run python examples/inverse_design.py
|
|
52
|
+
uv run python examples/report.py
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Dependencies: `numpy`, `scipy`, `springcalc`, `matplotlib`, `reportlab`, and `pypdf`. STEP export
|
|
56
|
+
also requires `cadquery` (the optional `step` extra), which is a large dependency.
|
|
57
|
+
|
|
58
|
+
## Conventions
|
|
59
|
+
|
|
60
|
+
| Quantity | Unit / convention |
|
|
61
|
+
|---|---|
|
|
62
|
+
| Lengths | mm |
|
|
63
|
+
| Forces | N |
|
|
64
|
+
| Moments | N·mm. **Positive when opposing pedal application** |
|
|
65
|
+
| Mass / inertia | kg / kg·m² |
|
|
66
|
+
| Axes | X to the right, Y upward (gravity in −Y) |
|
|
67
|
+
| Polar angles | degrees, **clockwise** from +X (as in the old Excel file) |
|
|
68
|
+
| Lever rotation θ | degrees, positive clockwise (= pressing). θ = 0 is the rest position |
|
|
69
|
+
| Travel | **Chord** of the force application point: straight-line distance from the rest position, `2·L·sin(θ/2)` |
|
|
70
|
+
| User force | At the force application point, perpendicular to the lever: `F = M_total / L` |
|
|
71
|
+
|
|
72
|
+
All points are given in absolute coordinates with the lever at rest.
|
|
73
|
+
|
|
74
|
+
## Structure
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
src/pylever/
|
|
78
|
+
├── geometry/ Lever (pivot, force application point, center of mass), Point
|
|
79
|
+
├── components/ Force laws, springs, slider-crank, dampers
|
|
80
|
+
├── mechanism/ LeverSystem, spring fitting (spring_fit), dynamics (dynamics)
|
|
81
|
+
└── report/ PDF report (LeverReport), JSON/STEP export for each spring
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Components
|
|
85
|
+
|
|
86
|
+
### Geometry: `Lever`
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from pylever.geometry import Lever
|
|
90
|
+
|
|
91
|
+
lever = Lever.from_xy(force=(0, -200), com=(0, -90), pivot=(0, 0))
|
|
92
|
+
lever = Lever.from_json("examples/pedal_2021_geometry.json") # x/y or r/angle from the pivot
|
|
93
|
+
lever.length, lever.com_distance, lever.angle
|
|
94
|
+
lever.rotated(10) # lever rotated 10° (pressed)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Force laws `F(x)`
|
|
98
|
+
|
|
99
|
+
`x` is always the compression / stroke of the component (mm).
|
|
100
|
+
|
|
101
|
+
| Class | Use |
|
|
102
|
+
|---|---|
|
|
103
|
+
| `SpringcalcLaw(spring)` | springcalc compression spring (`CompressionSpringGeneral`: variable diameter and pitch). The curve, including coil contact, is simulated once and interpolated. Raises an error if it reaches solid height |
|
|
104
|
+
| `SpringcalcLaw.from_json(path)` | Spring saved with `springcalc.save_model` |
|
|
105
|
+
| `TableLaw(x, F)` / `TableLaw.from_csv(path)` | Measured curve. CSV with or without a header, `,`, `;`, or tab delimiter; decimal commas are accepted |
|
|
106
|
+
| `FunctionLaw(f)` | Any function `f(x) -> F` |
|
|
107
|
+
|
|
108
|
+
### Lever springs
|
|
109
|
+
|
|
110
|
+
All springs are mounted between a fixed anchor `G` and an anchor on the lever `A`, and are
|
|
111
|
+
created from a springcalc spring.
|
|
112
|
+
|
|
113
|
+
| Class | springcalc spring | Force |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `CompressionSpring(G, A, spring, length_offset=0)` | `CompressionSpringGeneral` | Pushes along G–A. Spring length = `\|A−G\| + length_offset` (seats) |
|
|
116
|
+
| `ExtensionSpring(G, A, spring, length_offset=0)` | `ExtensionSpring` | Pulls along G–A: `F₀ + k·ΔL` if ΔL > 0 |
|
|
117
|
+
| `TorsionSpring(G, A, spring)` | `TorsionSpring` | Floating coil with legs articulated at G and A. Torque `k·(α_free − α)`. Force **along G–A** (solid loaded at two points) |
|
|
118
|
+
|
|
119
|
+
Names match those in springcalc: if importing both, use an alias
|
|
120
|
+
(`from pylever.components import ExtensionSpring as LeverExtensionSpring`).
|
|
121
|
+
|
|
122
|
+
### Slider-crank: `SliderCrank`
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from pylever.components import SliderCrank, TableLaw
|
|
126
|
+
|
|
127
|
+
booster = SliderCrank.from_xy(
|
|
128
|
+
rod_anchor=(0, -40), # on the lever
|
|
129
|
+
cylinder_start=(-120, -40), # piston at rest (end closest to the pivot)
|
|
130
|
+
cylinder_end=(-160, -40), # cylinder axis and maximum stroke
|
|
131
|
+
force=TableLaw.from_csv("booster.csv"), # or SpringcalcLaw(...) or FunctionLaw(...)
|
|
132
|
+
installed_length=None, # only if force is a spring: installed length (preload)
|
|
133
|
+
)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Exact stroke from circle-line intersection; moment `M = F·ds/dθ`.
|
|
137
|
+
|
|
138
|
+
### Dampers
|
|
139
|
+
|
|
140
|
+
Only active during dynamics (ω ≠ 0). Viscous coefficient `c` or force law `F(|v|)` (e.g. a catalog CSV).
|
|
141
|
+
|
|
142
|
+
| Class | Parameters |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `LinearDamper(G, A, c=None, law=None, active="both")` | `c` in N·s/mm, `v` in mm/s. `active`: `"both"`, `"extension"`, `"compression"` |
|
|
145
|
+
| `RotaryDamper(c=None, law=None, active="both")` | At the pivot. `c` in N·mm·s/rad. `active`: `"both"`, `"press"`, `"release"` |
|
|
146
|
+
|
|
147
|
+
### System: `LeverSystem`
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from pylever.mechanism import LeverSystem
|
|
151
|
+
|
|
152
|
+
system = LeverSystem(
|
|
153
|
+
lever=lever, travel_deg=15,
|
|
154
|
+
mass=0.5, # kg, weight at the center of mass
|
|
155
|
+
friction=3.0, # N at the force application point: + on press, − on release
|
|
156
|
+
inertia=0.004, # kg·m² about the pivot (None: point mass at the center of mass)
|
|
157
|
+
compression_springs=[...], extension_springs=[...], torsion_springs=[...],
|
|
158
|
+
slider_crank=booster, dampers=[...],
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
On creation, it validates component types, unique names, and the geometry of each component relative to the pivot.
|
|
163
|
+
|
|
164
|
+
## Forward calculation
|
|
165
|
+
|
|
166
|
+
Complete example: [examples/direct_calculation.py](examples/direct_calculation.py).
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from springcalc import CompressionSpringGeneral, ExtensionSpring, Material, ureg
|
|
170
|
+
from pylever.components import CompressionSpring, LinearDamper, SliderCrank, TableLaw
|
|
171
|
+
from pylever.components import ExtensionSpring as LeverExtensionSpring
|
|
172
|
+
from pylever.geometry import Lever
|
|
173
|
+
from pylever.mechanism import LeverSystem, return_report
|
|
174
|
+
|
|
175
|
+
material = Material(material_name="SH")
|
|
176
|
+
ocs = CompressionSpringGeneral(material=material, wire_diameter=2.0)
|
|
177
|
+
ocs.set_geometry(f_mean_diameter=lambda h: 20 * ureg.mm, f_pitch=lambda h: 6 * ureg.mm,
|
|
178
|
+
free_length=60 * ureg.mm)
|
|
179
|
+
ocs.calculate_spring_properties()
|
|
180
|
+
|
|
181
|
+
ret = ExtensionSpring(material=material, wire_diameter=1.5, initial_force=5)
|
|
182
|
+
ret.set_diameter(outer_diameter=15)
|
|
183
|
+
ret.calculate_spring_properties(nr_coils=10, free_length=40)
|
|
184
|
+
|
|
185
|
+
system = LeverSystem(
|
|
186
|
+
lever=Lever.from_xy(force=(0, -200), com=(0, -90)), travel_deg=15,
|
|
187
|
+
mass=0.5, friction=3.0, inertia=0.004,
|
|
188
|
+
compression_springs=[CompressionSpring((-50, 30), (0, -30), ocs, length_offset=-25, name="ocs")],
|
|
189
|
+
extension_springs=[LeverExtensionSpring((60, 0), (0, -30), ret, name="return")],
|
|
190
|
+
slider_crank=SliderCrank.from_xy(rod_anchor=(0, -40), cylinder_start=(-120, -40),
|
|
191
|
+
cylinder_end=(-160, -40),
|
|
192
|
+
force=TableLaw([0, 5, 10, 20], [0, 20, 60, 200])),
|
|
193
|
+
dampers=[LinearDamper((60, -10), (0, -50), c=0.05, name="damper")],
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
curve = system.curve(n=41)
|
|
197
|
+
curve.travel # chord of the force application point, mm
|
|
198
|
+
curve.force # force without friction, N
|
|
199
|
+
curve.apply # press (+ friction)
|
|
200
|
+
curve.release # release (− friction)
|
|
201
|
+
curve.moments # moment of each component, including "weight", N·mm
|
|
202
|
+
|
|
203
|
+
system.user_force(10, direction=+1) # force at 10° while pressing
|
|
204
|
+
system.moments(10) # {"weight": ..., "ocs": ..., "return": ..., "slider_crank": ...}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Example output:
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
travel [mm] apply [N] release [N]
|
|
211
|
+
0.00 13.48 7.48
|
|
212
|
+
8.73 15.39 9.39
|
|
213
|
+
17.45 17.27 11.27
|
|
214
|
+
26.16 19.29 13.29
|
|
215
|
+
34.86 22.45 16.45
|
|
216
|
+
43.55 25.51 19.51
|
|
217
|
+
52.21 28.85 22.85
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Free return (velocity and energy)
|
|
221
|
+
|
|
222
|
+
The user releases the lever at a percentage of its travel, and it returns on its own. The equation
|
|
223
|
+
`I·θ̈ = −(M_el + M_damper − M_friction)` is integrated until it reaches the rest stop or comes to a halt.
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
results = system.free_return([25, 50, 75, 100])
|
|
227
|
+
print(return_report(results))
|
|
228
|
+
|
|
229
|
+
r = results[-1]
|
|
230
|
+
r.returned, r.stuck # reaches the stop / does not start moving (held by friction)
|
|
231
|
+
r.time # time to the stop, s
|
|
232
|
+
r.impact_speed, r.impact_omega # speed at the force application point, m/s; rad/s
|
|
233
|
+
r.kinetic_energy # kinetic energy at impact, J
|
|
234
|
+
r.elastic_energy # energy released by springs + weight + slider-crank, J
|
|
235
|
+
r.friction_energy, r.damping_energy # energy dissipated, J
|
|
236
|
+
r.balance_error # check: Eel − Ekin − Wfr − Wdam ≈ 0
|
|
237
|
+
r.t, r.theta_deg, r.speed, r.kinetic # curves over time
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
% θ0 [°] status t [ms] v [m/s] ω [rad/s] Ekin [mJ] Eel [mJ] Wfr [mJ] Wdam [mJ]
|
|
242
|
+
25 3.75 stop 17.3 1.342 6.712 90.10 155.93 39.27 26.56
|
|
243
|
+
50 7.50 stop 22.4 1.958 9.790 191.69 348.88 78.54 78.66
|
|
244
|
+
75 11.25 stop 24.4 2.531 12.657 320.42 593.16 117.81 154.93
|
|
245
|
+
100 15.00 stop 25.4 3.116 15.580 485.50 897.81 157.08 255.23
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Inverse calculation: finding springs
|
|
249
|
+
|
|
250
|
+
Complete example: [examples/inverse_design.py](examples/inverse_design.py).
|
|
251
|
+
|
|
252
|
+
**Inputs**: the customer curve in CSV (travel as the chord of the force application point in mm, force in N,
|
|
253
|
+
**without friction**), the number of springs of each type, and whether to use the slider-crank (which remains fixed).
|
|
254
|
+
|
|
255
|
+
```csv
|
|
256
|
+
travel,force
|
|
257
|
+
0,30
|
|
258
|
+
5,34.6
|
|
259
|
+
...
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Stage 1: anchors and ideal springs
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from pylever.mechanism import FitBounds
|
|
266
|
+
|
|
267
|
+
base = LeverSystem(lever, travel_deg=15, mass=0.5, friction=3.0, slider_crank=booster)
|
|
268
|
+
|
|
269
|
+
fit = base.fit_springs(
|
|
270
|
+
"customer_curve.csv",
|
|
271
|
+
compression=1, extension=1, torsion=0,
|
|
272
|
+
use_slider_crank=True,
|
|
273
|
+
bounds=FitBounds(ground_region=(-120, 120, -80, 60), # allowed region for fixed anchors
|
|
274
|
+
lever_region=(-25, 25, -150, 0)), # allowed region on the lever
|
|
275
|
+
seed=1, maxiter=150,
|
|
276
|
+
)
|
|
277
|
+
print(fit.report())
|
|
278
|
+
fit.system # LeverSystem with ideal springs
|
|
279
|
+
fit.springs # per spring: type, anchors, parameters, and working range
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
- Variables: anchors `G` and `A` for each spring and its ideal parameters
|
|
283
|
+
(compression: k, L0; extension: k, L0, F0; torsion: k, free angle, legs).
|
|
284
|
+
- Global optimizer `scipy.optimize.differential_evolution` minimizes the RMS error against the curve.
|
|
285
|
+
- Constraints: each spring is loaded throughout the entire travel (`require_active`) and compression
|
|
286
|
+
deflection ≤ 60% of L0 (`max_deflection_ratio`). Limits can be adjusted in `FitBounds`.
|
|
287
|
+
- Mass, friction, inertia, the slider-crank, and dampers are taken from the base system;
|
|
288
|
+
its springs are ignored.
|
|
289
|
+
|
|
290
|
+
### Stage 2: real compression springs with springcalc
|
|
291
|
+
|
|
292
|
+
```python
|
|
293
|
+
real = fit.realize_compression(material="SH", safety_factor=1.2, designer="conical", seed=1)
|
|
294
|
+
print(real.report())
|
|
295
|
+
real.system # LeverSystem with real springs
|
|
296
|
+
real.designs # springcalc design objects (wire, diameters, pitch, coils, safety factor...)
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
For each spring, its working force-deflection curve is generated and passed to the springcalc
|
|
300
|
+
inverse designer (`"conical"`: seconds; `"general"`: minutes or hours). Since the real free length
|
|
301
|
+
differs from the ideal one, `length_offset` (seats) is adjusted to maintain the deflection at each
|
|
302
|
+
position without moving the anchors. Extension and torsion springs currently retain their ideal
|
|
303
|
+
parameters (springcalc does not yet support their inverse design).
|
|
304
|
+
|
|
305
|
+
Example output:
|
|
306
|
+
|
|
307
|
+
```
|
|
308
|
+
Stage 1 (ideal springs)
|
|
309
|
+
RMS = 0.185 N, max error = 0.537 N (29893 evaluations)
|
|
310
|
+
compression_1 [compression] G=(101.13, -78.46) A=(14.51, -20.54): k=12.58, free_length=136.1
|
|
311
|
+
range: length=(104.2, 107.5), force=(359.5, 400.9)
|
|
312
|
+
extension_1 [extension] G=(19.19, -70.84) A=(-2.71, -119.71): k=9.98, free_length=33.66, initial_force=20.59
|
|
313
|
+
range: length=(53.55, 68.78), force=(219.1, 371.1)
|
|
314
|
+
|
|
315
|
+
Stage 2 (springcalc)
|
|
316
|
+
RMS = 0.185 N, max error = 0.537 N
|
|
317
|
+
compression_1: d=4.25 mm, Dm=37.07 mm→44.66 mm, p=33.96 mm→17.72 mm, L0=93.07 mm, n=3.73, Lc=15.84 mm, FS=1.20, length_offset=-43.00 mm
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
The solution is not unique: constrain the anchor regions to the available physical space and set
|
|
321
|
+
`seed` for reproducible results.
|
|
322
|
+
|
|
323
|
+
## PDF report and spring export
|
|
324
|
+
|
|
325
|
+
`LeverReport` generates a PDF containing:
|
|
326
|
+
|
|
327
|
+
1. A system summary and the coordinates of all points.
|
|
328
|
+
2. A drawing of the mechanism at rest (solid line) and at full travel (dashed line).
|
|
329
|
+
3. A plot of each spring's load and a plot of pedal force: each component's contribution, the total
|
|
330
|
+
without friction, press/release with friction, and, if provided, the customer curve.
|
|
331
|
+
4. A curve table and each spring's working points (rest and full travel).
|
|
332
|
+
5. The springcalc report for each spring (data, 3D view, curves, Goodman diagram), with the
|
|
333
|
+
mechanism's working points used as load positions. Ideal (not yet designed) springs are shown
|
|
334
|
+
as a parameter table.
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
from pylever.report import LeverReport
|
|
338
|
+
|
|
339
|
+
report = LeverReport(system, title="Pedal 2021", target="customer_curve.csv") # target is optional
|
|
340
|
+
report.build("pedal.pdf") # PDF only
|
|
341
|
+
report.export_springs("pedal_springs") # <spring>.json and <spring>.step
|
|
342
|
+
report.export("pedal_out") # everything: report.pdf + JSON + STEP
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
For each spring:
|
|
346
|
+
|
|
347
|
+
- **JSON**: `springcalc.save_model` format (can be read again with `springcalc.load_model`), with
|
|
348
|
+
working points as positions and a `"pylever"` section containing the mounting information (anchors,
|
|
349
|
+
`length_offset`) and working points. The original spring is not modified; a copy is used.
|
|
350
|
+
- **STEP** (requires `uv sync --extra step`): spring wire in its free state, along the Z axis, in
|
|
351
|
+
the spring's local coordinates. Compression: springcalc exporter (any diameter and pitch profile).
|
|
352
|
+
Extension: body with `nr_coils` turns and one complete eye at each end, adjusted so the inner
|
|
353
|
+
distance between the eyes equals the free length. Torsion: body with tangent legs whose tips are
|
|
354
|
+
`fixed_leg_radius`/`mobile_leg_radius` from the axis and form `free_angle` (the body angle is
|
|
355
|
+
adjusted by less than half a turn). This is reference geometry for assembly and interference
|
|
356
|
+
checks, not a manufacturing drawing for hooks or legs.
|
|
357
|
+
|
|
358
|
+
The slider-crank is treated as a spring when its force is a `SpringcalcLaw`.
|
|
359
|
+
|
|
360
|
+
## Limitations
|
|
361
|
+
|
|
362
|
+
- Quasi-static except for `free_return`: the mass of springs, rod, and piston is not considered.
|
|
363
|
+
- Torsion spring: the angle between the legs is constrained to (0°, 180°); the legs cannot pass through alignment.
|
|
364
|
+
- Global Coulomb friction is constant at the force application point.
|
|
365
|
+
- Stage 2 supports compression springs only.
|
|
366
|
+
- `springcalc` has no 3D view for extension springs; its report indicates this in that section.
|