relocate(leg)

# Assemble the parts
alpha = 0
joints = linkage(alpha, x, y, links)

for name in link_list:
    v, a = link_loc(name, joints, links)
    abs_loc = cq.Location(
        cq.Workplane("YZ").plane.rotated((0, 0, a)),
        cq.Vector(*v))  # calculate the absolute location ...
    loc = abs_loc * leg.mates[
        name].mate.loc.inverse  # ... and center the mate of the link first
    leg.assemble(name, loc)

cv = show(leg)

alphas = {name: [] for name in link_list}
positions = {name: [] for name in link_list}

for alpha in range(0, -375, -15):
    for name in link_list:
        p, a = link_loc(name, linkage(alpha, x, y, links), links)
        alphas[name].append(a)
        positions[name].append(p)

time = np.linspace(0, 4, 25)

animation = Animation(cv)

for name in link_list:
Пример #2
0
    leg = MAssembly(cq.Workplane("YZ").polyline([(0, 0), (x, 0), (x, y)]), name="base", color=C("Gray"))
    for i, name in enumerate(link_list):
        leg.add(parts[name], name=name, color=C(links[name]["col"]), loc=L(0, 0, i * 10 - 50))
    return leg


leg = create_leg(x, y)

# Mates

for name in link_list:
    leg.mate(f"{name}?mate", name=name, origin=True)


check_mates = True
if check_mates:
    show(leg)
else:
    # Assemble the parts
    alpha = 0
    joints = linkage(alpha, x, y, links)

    for name in link_list:
        v, a = link_loc(name, joints, links)
        abs_loc = cq.Location(
            cq.Workplane("YZ").plane.rotated((0, 0, a)), cq.Vector(*v)
        )  # calculate the absolute location ...
        loc = abs_loc * leg.mates[name].mate.loc.inverse  # ... and center the mate of the link first
        leg.assemble(name, loc)

    show(leg)
Пример #3
0
    return assy


bearing = create_bearing()

# Mates

from collections import OrderedDict as odict

bearing.mate("outer@faces@<Z", name="outer", origin=True)
bearing.mate("inner@faces@<Z", name="inner", origin=True)

for i in range(number_balls):
    bearing.mate(balls[i], Mate(), name=balls[i],
                 origin=True)  # the default Mate is sufficient
    bearing.mate("inner@faces@<Z",
                 name="inner_%d" % i,
                 transforms=odict(rz=i * 60, tx=r5, tz=-ball_diam / 2))

check_mates = False
if check_mates:
    # Assemble the parts
    show(bearing)
else:
    bearing.assemble("inner", "outer")
    for i in range(number_balls):
        bearing.assemble(balls[i], "inner_%d" % i)

    show(bearing)
Пример #4
0
                                                  name="back_stand",
                                                  color=C(0.5, 0.8, 0.9),
                                                  loc=L(-40, 100, 0)))

    for i, name in enumerate(leg_names):
        hexapod.add(leg, name=name, loc=L(100, -55 * (i - 1.7), 0))

    return hexapod


# Mates

from collections import OrderedDict as odict

hexapod = create_hexapod()
show(hexapod)

hexapod.mate("bottom?top", name="bottom", origin=True)
hexapod.mate("top?bottom",
             name="top",
             origin=True,
             transforms=odict(rx=180, tz=-(height + 2 * tol)))

for name in stand_names:
    hexapod.mate(f"bottom?{name}",
                 name=f"{name}_bottom",
                 transforms=odict(rz=-90 if "f" in name else 90))
    hexapod.mate(f"{name}@faces@<X",
                 name=name,
                 origin=True,
                 transforms=odict(rx=180))
Пример #5
0
# add mates to the connectors
for c in ["con_tl", "con_tr", "con_br", "con_bl"]:
    door.mate(f"{c}?X", name=f"{c}_0", transforms=odict(rx=180))
    door.mate(f"{c}?Z", name=f"{c}_1", transforms=odict(rx=180))

# add mates to bottom vslot and panel
door.mate("panel@faces@<Z", name="panel_0", transforms=odict(rx=180, rz=90))
door.mate("bottom@faces@>X[-4]", name="panel_1")

# add mates to handle and one hole
door.mate("handle?mate1", name="handle_0", transforms=odict(rx=180))
door.mate("panel?hole1", name="handle_1")


check_mates = True
if check_mates:
    show(door)
else:
    # Assemble the parts
    door.assemble("bottom_0", "con_bl_0")  # add bottom vslot to bottom-left connector
    door.assemble("con_br_1", "bottom_1")  # add bottom-right connector to bottom vslot
    door.assemble("left_1", "con_bl_1")  # add left vslot to bottom-left connector
    door.assemble("right_0", "con_br_0")  # add right vslot to bottom-right connector
    door.assemble("panel_0", "panel_1")  # add panel
    door.assemble("con_tl_0", "left_0")  # add top-left connector to left vslot
    door.assemble("con_tr_1", "right_1")  # add top-right connector to right vslot
    door.assemble("top_1", "con_tl_1")  # add top vslot to top-left connector
    door.assemble("handle_0", "handle_1")  # add handle

    show(door)
Пример #6
0
disk_arm.mate("base?mate",
              name="disk_pivot",
              origin=True,
              transforms=odict(rz=180))
disk_arm.mate("base@faces@>Z", name="arm_pivot")
disk_arm.mate("disk@faces@>Z[-2]", name="disk", origin=True)
disk_arm.mate("arm?mate", name="arm", origin=True)

relocate(disk_arm)

# show(disk_arm)

disk_arm.assemble("arm", "arm_pivot")
disk_arm.assemble("disk", "disk_pivot")

show(disk_arm, reset_camera=True)

r_disk = 100
dist_pivot = 200


def angle_arm(angle_disk):
    ra = np.deg2rad(angle_disk)
    v = np.array((dist_pivot, 0)) - r_disk * np.array((cos(ra), sin(ra)))
    return np.rad2deg(np.arctan2(*v[::-1]))


animation = Animation()

times = np.linspace(0, 5, 181)
disk_angles = np.linspace(0, 360, 181)
Пример #7
0
disk_arm.mate("base?mate",
              name="disk_pivot",
              origin=True,
              transforms=odict(rz=180))
disk_arm.mate("base@faces@>Z", name="arm_pivot")
disk_arm.mate("disk@faces@>Z[-2]", name="disk", origin=True)
disk_arm.mate("arm?mate", name="arm", origin=True)

relocate(disk_arm)

# show(disk_arm)

disk_arm.assemble("arm", "arm_pivot")
disk_arm.assemble("disk", "disk_pivot")

show(disk_arm, reset_camera=False, zoom=3.5)

r_disk = 100
dist_pivot = 200


def angle_arm(angle_disk):
    ra = np.deg2rad(angle_disk)
    v = np.array((dist_pivot, 0)) - r_disk * np.array((cos(ra), sin(ra)))
    return np.rad2deg(np.arctan2(*v[::-1]))


animation = Animation(viewer=True)

times = np.linspace(0, 5, 181)
disk_angles = np.linspace(0, 360, 181)
Пример #8
0
    hexapod.mate(f"{name}/lower?{lower}", name=f"leg_{name}_lower_hole", origin=True)

# show(hexapod, reset_camera=False)
relocate(hexapod)

# Assemble the parts
for leg in leg_names:
    hexapod.assemble(f"leg_{leg}_lower_hole", f"leg_{leg}_hole")
    hexapod.assemble(f"leg_{leg}_hinge", f"{leg}_hole")

hexapod.assemble("top", "bottom")

for stand_name in stand_names:
    hexapod.assemble(f"{stand_name}", f"{stand_name}_bottom")

show(hexapod, render_mates=True, mate_scale=5)

# Animation

horizontal_angle = 25


def intervals(count):
    r = [min(180, (90 + i * (360 // count)) % 360) for i in range(count)]
    return r


def times(end, count):
    return np.linspace(0, end, count + 1)

Пример #9
0
    ("box0", "box0"),
    ("c/box1", "box1"),
    ("c/b/box2", "box2"),
    ("c/b/a/box3", "box3"),
    ("c", "cyl1"),
    ("c/b", "cyl2"),
    ("c/b/a", "cyl3"),
):
    assy.mate(
        f"{obj}?{name}_m0",
        name=f"{name}_m0",
        transforms=odict(rx=180 if "c" in name else 0),
        origin=True,
    )
    assy.mate(f"{obj}?{name}_m1", name=f"{name}_m1", transforms=odict(rx=0 if "b" in name else 180))


check_mates = True
if check_mates:
    show(assy)
else:
    # Assemble the parts
    assy.assemble("cyl1_m0", "box0_m0")
    assy.assemble("box1_m1", "cyl1_m1")
    assy.assemble("cyl2_m0", "box1_m0")
    assy.assemble("box2_m1", "cyl2_m1")
    assy.assemble("cyl3_m0", "box2_m0")
    assy.assemble("box3_m1", "cyl3_m1")

    show(assy)
        f"{obj}?{name}_m0",
        name=f"{name}_m0",
        transforms=odict(rx=180 if "c" in name else 0),
        origin=True,
    )
    assy.mate(
        f"{obj}?{name}_m1",
        name=f"{name}_m1",
        transforms=odict(rx=0 if "b" in name else 180),
    )

relocate(assy)

check_mates = False
if check_mates:
    show(assy, render_mates=True)
else:
    # Assemble the parts
    assy.assemble("cyl1_m0", "box0_m0")
    assy.assemble("box1_m1", "cyl1_m1")
    assy.assemble("cyl2_m0", "box1_m0")
    assy.assemble("box2_m1", "cyl2_m1")
    assy.assemble("cyl3_m0", "box2_m0")
    assy.assemble("box3_m1", "cyl3_m1")

    show(assy)

import numpy as np
from jupyter_cadquery.cad_animation import Animation

animation = Animation()