"""Sharp GP2Y0A41SK0F distance measuring sensor unit (4 to 30 cm, analog output): a lens case with two mounting ears, a light emitter and a light detector lens on its front, and a small board with a 3-pin connector hanging below. The ears' back (the mounting face) is the XY plane and the unit looks toward +Z. The mounting holes lie on the X axis, centred on the origin, the emitter is on the -X side and the connector on the -Y side. The case, each lens, the board and the connector housing are separate solids. Dimensions from Sharp's data sheet; see the README.""" from steve import Model part_number = "GP2Y0A41SK0F" # Sharp part number # Sharp GP2Y0A41SK0F data sheet, Sheet No. OP13008EN, page 2, Outline (drawing CY13036j02A, "GP2Y0A41SK0F Outline Dimensions", # unit mm, unspecified tolerance +/-0.3, dimensions in parenthesis for reference): # mounting holes 37 apart, dia. 3.2, in ears R3.75, 1.5 thick ("2-1.5"); case 29.5 wide and 13 high, 13.5 deep overall from # the ears' back to the lens blocks' front; the front steps: 6.3 deep in all, 8.4 high, of which the last 2 are the lens # blocks, 7.2 high; lens blocks 7.5 (emitter) and 16.3 (detector) wide with 4.15 between them; emitter lens centre 4.5 from # the case's side and 3.75 from its block's outer end, detector lens centre 19.7 +/-0.1 from the emitter's; connector part # 10.1 wide, centred 14.75 from the case's side; 18.9 (+0.5/-0.3) from the case's top to the connector's and board's lower # end; board (PWB) 1.2 thick, its back (3.3) in front of the case's back. PARTS = { "GP2Y0A41SK0F": { "hole_pitch": 37.0, "hole_d": 3.2, "ear_r": 3.75, "ear_t": 1.5, "case_w": 29.5, "case_h": 13.0, "depth": 13.5, "front": 6.3, "front_h": 8.4, "block": 2.0, "block_h": 7.2, "emitter_block": 7.5, "gap": 4.15, "detector_block": 16.3, "emitter_x": 4.5, "emitter_in": 3.75, "lens_pitch": 19.7, "board_w": 10.1, "board_x": 14.75, "overall_h": 18.9, "board_t": 1.2, "board_back": 3.3, }, } # Proportions, for looks (the drawing shows these but doesn't dimension them; README): the lenses' diameters as they show in # the front view and the depth they are shown at, and the connector housing's width and depth in front of the board. PROPORTIONS = {"GP2Y0A41SK0F": {"emitter_lens": 4.9, "detector_lens": 4.5, "lens_t": 1.0, "connector_w": 7.9, "connector_d": 4.8}} if part_number not in PARTS: raise ValueError(f"no part number {part_number!r}: {', '.join(PARTS)}") D = PARTS[part_number] P = PROPORTIONS[part_number] W, H, depth = D["case_w"], D["case_h"], D["depth"] case_d = depth - D["front"] # the 13 high part of the case, from the mounting face step_d = D["front"] - D["block"] # the 8.4 high step in front of it left = -W / 2 # the case's side on the emitter's end model = Model() model.box("case", W, H, case_d, at=(0, 0, case_d / 2), op="new", body="case_body", name="Lens case") model.box("step", W, D["front_h"], step_d, at=(0, 0, case_d + step_d / 2), op="join", body="case_body", name="Front step") # The lens blocks: the emitter's starts 4.5 - 3.75 from the case's side, the detector's follows after the gap. x0 = left + D["emitter_x"] - D["emitter_in"] x1 = x0 + D["emitter_block"] + D["gap"] zb = depth - D["block"] / 2 model.box("emitter_block", D["emitter_block"], D["block_h"], D["block"], at=(x0 + D["emitter_block"] / 2, 0, zb), op="join", body="case_body", name="Emitter lens block") model.box("detector_block", D["detector_block"], D["block_h"], D["block"], at=(x1 + D["detector_block"] / 2, 0, zb), op="join", body="case_body", name="Detector lens block") # The ears: a tab as wide as the round end, out to the hole's centre, and the round end around the hole. r, t = D["ear_r"], D["ear_t"] for k, s in (("a", -1), ("b", 1)): xh = s * D["hole_pitch"] / 2 tab = abs(xh) - W / 2 model.box(f"ear_{k}_tab", tab, 2 * r, t, at=(s * (W / 2 + tab / 2), 0, t / 2), op="join", body="case_body", name="Ear") model.cylinder(f"ear_{k}_end", r, t, at=(xh, 0, 0), op="join", body="case_body", name="Ear") with model.sketch(f"hole_{k}_sketch", on="XY", name="Mounting hole") as sk: sk.circle(f"hole_{k}_circle", (xh, 0), D["hole_d"] / 2) model.extrude(f"hole_{k}", f"hole_{k}_sketch", distance=t, op="cut", body="case_body", name="Mounting hole") # The lenses, shown as discs set flush in the lens blocks' fronts at the dimensioned centres. xe = left + D["emitter_x"] lens_t = P["lens_t"] model.plane("lens_plane", on="XY", offset=depth - lens_t, name="Lens seat") for k, x, d, what in (("emitter", xe, P["emitter_lens"], "Light emitter"), ("detector", xe + D["lens_pitch"], P["detector_lens"], "Light detector")): with model.sketch(f"{k}_seat_sketch", on="lens_plane", name=f"{what} lens seat") as sk: sk.circle(f"{k}_seat_circle", (x, 0), d / 2) model.extrude(f"{k}_seat", f"{k}_seat_sketch", distance=lens_t, op="cut", body="case_body", name=f"{what} lens seat") with model.sketch(f"{k}_lens_sketch", on="lens_plane", name=f"{what} lens") as sk: sk.circle(f"{k}_lens_circle", (x, 0), d / 2) model.extrude(f"{k}_lens", f"{k}_lens_sketch", distance=lens_t, op="new", body=f"{k}_lens_body", name=f"{what} lens") # The board's part below the case, and the connector housing on its front. drop = D["overall_h"] - H xc = left + D["board_x"] yc = -H / 2 - drop / 2 zp = D["board_back"] model.box("board", D["board_w"], drop, D["board_t"], at=(xc, yc, zp + D["board_t"] / 2), op="new", body="board_body", name="Board (PWB)") model.box("connector", P["connector_w"], drop, P["connector_d"], at=(xc, yc, zp + D["board_t"] + P["connector_d"] / 2), op="new", body="connector_body", name="Connector housing") # Materials (page 2, Materials): "Lens: Acrylic acid resin (Visible light cut-off resin)" (pmma, dark), "Case: Carbonic ABS # (Conductive resin)" (abs, black), "PCB: Paper phenol" (bakelite). The sheet names the connector (JCTC 12001W90-3P-HF) but not # what it is made of: its housing is shown as pa6, natural. model.material("abs", bodies=["case_body"], color="#1c1c1e") model.material("pmma", bodies=["emitter_lens_body", "detector_lens_body"], color="#2a2a30") model.material("bakelite", bodies=["board_body"], color="#b08a4a") model.material("pa6", bodies=["connector_body"], color="#e8e4d8") result = model.result()