Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 114 additions & 57 deletions docs/src/gui/vismach.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,70 @@ or raw data:
possible to assemble the model in the CAD package.

Alternatively parts can be created inside the model script from a range
of *shape primitives*. Many shapes are created at the origin and need to
be moved to the required location after creation:

* `cylinder = CylinderX(x1, r1, x2, r2) +
cylinder = CylinderY(y1, r1, y2, r2) +
cylinder = CylinderZ(z1, r1, z2, r2)` +
of *shape primitives*. All primitives accept static numbers or an
optional leading HAL component (`[comp,]`) followed by HAL pin names.
Many shapes are created at the origin and need to be moved to the
required location after creation:

* `cylinder = CylinderX([comp,] x1, r1, x2, r2)` +
`cylinder = CylinderY([comp,] y1, r1, y2, r2)` +
`cylinder = CylinderZ([comp,] z1, r1, z2, r2)` +
Creates a (optionally tapered) cylinder on the given axis with the
given radii at the given points on the axis.
* `sphere = Sphere(x, y, z, r)` +
Creates a sphere of radius r at (x,y,z)
* `triangle = TriangleXY(x1, y1, x2, y2, x3, y3, z1, z2) +
triangle = TriangleXZ(x1, z1, x2, z2, x3, z3, y1, y2) +
triangle = TriangleYZ(y1, z1, y2, z2, y3, z3, x1, x2)` +
* `sphere = Sphere([comp,] x, y, z, r)` +
Creates a sphere of radius `r` at `(x, y, z)`.
* `triangle = TriangleXY([comp,] x1, y1, x2, y2, x3, y3, z1, z2)` +
`triangle = TriangleXZ([comp,] x1, z1, x2, z2, x3, z3, y1, y2)` +
`triangle = TriangleYZ([comp,] y1, z1, y2, z2, y3, z3, x1, x2)` +
Creates a triangular plate between planes defined by the last two
values parallel to the specified plane, with vertices given by the
three coordinate pairs.
* `arc = ArcX(x1, x2, r1, r2, a1, a2)` +
Create an arc shape.
* `box = Box(x1, y1, z1, x2, y2, z2)` +
* `arc = ArcX([comp,] x1, x2, r1, r2, a1, a2, steps)` +
Creates a curved arc segment along the X-axis between `x1` and `x2`,
with inner radius `r1`, outer radius `r2`, start/end angles `a1` and
`a2` (in degrees), and `steps` subdivisions.
* `box = Box([comp,] x1, y1, z1, x2, y2, z2)` +
Creates a rectangular prism with opposite corners at the specified
positions and edges parallel to the XYZ axes.
* `box = BoxCentered(xw, yw, zw)` +
Creates an xw by yw by zw box centred on the origin.
* `box = BoxCenteredXY(xw, yw, z)` +
Creates a box of width xw / yw and height z.
* `box = BoxCentered([comp,] xw, yw, zw)` +
Creates an `xw` by `yw` by `zw` box centred on the origin.
* `box = BoxCenteredXY([comp,] xw, yw, zw)` +
Creates a box of width `xw` / `yw` and height `zw`.
* `line = Line([comp,] x1, y1, z1, x2, y2, z2, stretch=1, r=5)` +
(Legacy alias: `HalLine`.) +
Creates a cylindrical line segment starting at `(x1, y1, z1)` along
vector `(x2, y2, z2)` scaled by `stretch` with radius `r`.
* `grid = Grid([comp,] s=500)` +
`grid = Grid([comp,] x, y, z, vx, vy, vz, s=500)` +
`grid = Grid([comp,] ox, oy, oz, xx, xy, xz, zx, zy, zz, s=500)` +
(Legacy aliases: `HalGrid`, `HalGridFromNormal`, `HalGridFromNormalAndDirection`.) +
Creates a reference grid of half-size `s` on the XY plane at the
origin, perpendicular to normal vector `(vx, vy, vz)` at `(x, y, z)`,
or aligned to origin `(ox, oy, oz)`, X-direction `(xx, xy, xz)`, and
Z-normal `(zx, zy, zz)`.
* `plane = Plane([comp,] s=500)` +
`plane = Plane([comp,] x, y, z, vx, vy, vz, s=500)` +
`plane = Plane([comp,] ox, oy, oz, xx, xy, xz, zx, zy, zz, s=500)` +
(Legacy alias: `HalPlaneFromNormal`.) +
Creates a solid reference plane of half-size `s` at the origin,
aligned to a normal vector, or aligned to an origin, X-direction
vector, and Z-normal vector.
* `coords = Coords([comp,] stretch=1, r=5)` +
`coords = Coords([comp,] ox, oy, oz, zx, zy, zz, stretch=1, r=5)` +
`coords = Coords([comp,] ox, oy, oz, xx, xy, xz, zx, zy, zz, stretch=1, r=5)` +
(Legacy alias: `HalCoordsFromNormalAndDirection`.) +
Creates a 3-axis RGB coordinate indicator (X=Red, Y=Green, Z=Blue) of
base length `50 * stretch` and radius `r` at the origin, aligned to a
Z-normal vector, or aligned to an origin, X-direction vector, and
Z-normal vector.

[NOTE]
====
Legacy `Hal*` aliases (such as `HalLine`, `HalGrid`,
`HalGridFromNormal`, `HalGridFromNormalAndDirection`, `HalPlaneFromNormal`,
and `HalCoordsFromNormalAndDirection`) remain supported for backwards
compatibility, though they may be deprecated in the future.
====

Composite parts may be created by *assembling* these primitives either
at creation time or subsequently using `Collection()`:
Expand All @@ -131,44 +170,62 @@ rotation axis is created at the origin (but moves with the Part):
* `part1 = Rotate([part1], theta, x, y, z)` +
Rotate the part by angle theta about an axis between the origin and
x, y, z.
* `part1 = Scale([part1], x, y, z)` +
Scale the part by factors `x`, `y`, and `z` along the respective axes.
* `part1 = RotateEuler([part1], th1, th2, th3, order=123)` +
Apply three successive Euler rotations (`th1`, `th2`, `th3` in degrees)
about the axes specified by `order` (default `123` for X-Y-Z).
* `part1 = Show([part1], const, var, scaleby_true=1, scaleby_false=0)` +
Toggle part visibility/scale between `scaleby_true` and `scaleby_false`
depending on whether `const == var`.

[NOTE]
====
Legacy `Hal*` aliases (such as `HalTranslate`, `HalVectorTranslate`,
`HalRotate`, `HalVectorRotate`, `HalScale`, `HalRotateEuler`, and
`HalShow`) remain supported for backwards compatibility, though they may
be deprecated in the future.
====

== Animating Parts

To animate the model (controlled by the values of HAL pins) there are
two functions 'HalTranslate' and 'HalRotate'. For parts to move inside
an assembly they need to have their HAL motions defined before being
assembled with the "Collection" command. The rotation axis and
translation vector move with the part as it is moved by the vismach
script during model assembly, or as it moves in response to the HAL pins
as the model is animated:

* `part = HalTranslate([part], comp, "hal_pin", xs, ys, zs)` +
The function arguments are:
** first a _collection/part_ which can be pre-created earlier in the
script, or could be created at this point if preferred eg
`part1 = HalTranslate([Box(....)], ...)`.
** The _HAL component_ is the next argument, i.e. the object returned by
the `comp = hal.component(...)` command. After that is the name of
the HAL in that will animate the motion, this needs to match an
existing HAL pin that is part of the HAL component created earlier in
the script.
** Then follow the _X, Y, Z scales_. +
For a Cartesian machine created at 1:1 scale this would typically be
1,0,0 for a motion in the positive X direction. +
However if the STL file happened to be in cm and the machine was in
inches, this could be fixed at this point by using 0.3937
(1cm /2.54in) as the scale.
* `part = HalRotate([part], comp, "hal_pin", angle_scale, x, y, z)` +
This command is similar in its operation to HalTranslate except that
it is typically necessary to move the part to the origin first to
define the axis.
** The _axis of rotation_ is from the origin point to the point defined
by (x,y,z). +
When the part is moved back away from the origin to its correct
location the axis of rotation can be considered to remain "embedded"
in the part.
** _Rotation angles_ are in degrees, so for a rotary joint with a 0-1
scaling you would need to use an angle scale of 360.
To animate the model, transform classes accept either static numbers or
a HAL component (`[comp,]`) followed by HAL pin names. All legacy `Hal*`
transform classes are kept as backwards-compatible aliases. For parts to
move inside an assembly they need to have their motions defined before
being assembled with the `Collection()` command. The rotation axis and
translation vector move with the part as it is moved by the Vismach
script during model assembly, or as it moves in response to HAL pins as
the model is animated:

* `part = Translate([part], [comp,] x, y, z)` +
`part = Translate([part], [comp,] var, x, y, z)` +
(Legacy alias: `HalTranslate`.) +
In the 3-argument form, moves `part` by `(x, y, z)`. In the 4-argument
form, moves `part` along vector `(x, y, z)` scaled by `var`.
* `part = VectorTranslate([part], [comp,] xvar, yvar, zvar, scale=1)` +
(Legacy alias: `HalVectorTranslate`.) +
Moves `part` along `(xvar, yvar, zvar)` scaled by `scale` (which may
be passed either positionally or as a keyword argument).
* `part = Rotate([part], [comp,] th, x, y, z)` +
`part = Rotate([part], [comp,] var, th, x, y, z)` +
(Legacy aliases: `HalRotate`, `HalVectorRotate`.) +
Rotates `part` around the axis `(x, y, z)` by angle `th` (in degrees),
or by `th * var` when a variable multiplier `var` is given.
* `part = RotateEuler([part], [comp,] x, y, z, order=123)` +
(Legacy alias: `HalRotateEuler`.) +
Applies sequential Euler rotations `x`, `y`, `z` (in degrees) around
axes `1` (X), `2` (Y), and `3` (Z) in the specified `order`.
* `part = Scale([part], [comp,] x, y, z)` +
`part = Scale([part], [comp,] x, y, z, var)` +
(Legacy alias: `HalScale`.) +
Scales `part` along `(x, y, z)`, or scales by `(x * var, y * var,
z * var)` when a variable multiplier `var` is given.
* `part = Show([part], [comp,] const, var, scaleby_true=1, scaleby_false=0)` +
(Legacy alias: `HalShow`.) +
Compares `var` against `const`. When `var == const`, `part` is scaled by
`scaleby_true` (default `1`, visible); otherwise it is scaled by
`scaleby_false` (default `0`, hidden).

== Assembling the model.

Expand All @@ -195,21 +252,21 @@ of drive dogs:
#Drive dogs
dogs = Box(-6,-3,94,6,3,100)
dogs = Color([1,1,1,1],[dogs])
dogs = HalRotate([dogs],c,"spindle",360,0,0,1)
dogs = Rotate([dogs],c,"spindle",360,0,0,1)
dogs = Translate([dogs],-1,49,0)

#Drawbar
draw = CylinderZ(120,3,125,3)
draw = Color([1,0,.5,1],[draw])
draw = Translate([draw],-1,49,0)
draw = HalTranslate([draw],c,"drawbar",0,0,1)
draw = Translate([draw],c,"drawbar",0,0,1)

# head/spindle
head = AsciiSTL(filename="./head.stl")
head = Color([0.3,0.3,0.3,1],[head])
head = Translate([head],0,0,4)
head = Collection([head, tool, dogs, draw])
head = HalTranslate([head],c,"Z",0,0,0.1)
head = Translate([head],c,"Z",0,0,0.1)

# base
base = AsciiSTL(filename="./base.stl")
Expand Down Expand Up @@ -295,7 +352,7 @@ tooltip = Capture()
#Build and assemble the model
part1 = Collection([Box(-6,-3,94,6,3,100)])
part1 = Color([1,1,1,1],[part1])
part1 = HalRotate([part1],comp,"pin_name",360,0,0,1)
part1 = Rotate([part1],comp,"pin_name",360,0,0,1)
part1 = Translate([dogs],-1,49,0)
...
#create a top-level model
Expand Down
Loading