Commit 32d363ca by mehtank

ESPCore

1 parent b9accd9f
from svggen.api.component import Component
from svggen.api.Function import Function
c = Component()
c.addParameter("length")
c.addParameter("width")
c.addParameter("height")
c.addParameter("controller")
c.addParameter("driveservo")
c.addSubcomponent("brain", "ESPBrains")
c.addSubcomponent("right", "ServoMount", invert=True)
c.addSubcomponent("left", "ServoMount", invert=True)
# Constant thickness of main body
def depthfn(params = None, fnmod = None):
if params is None: params = []
if fnmod is None: fnmod = "%s"
return ["controller", "driveservo"] + params, \
fnmod % "max(x[0].getDimension('height'), x[1].getParameter('motorwidth'))"
# Set microcontroller
c.addConstraint(("brain","depth"), *depthfn())
c.addConstraint(("brain","length"), "width")
c.addConstraint(("brain", "brain"), "controller")
for servo in ("right", "left"):
c.addConstraint((servo,"depth"), *depthfn())
c.addConstraint((servo, "length"),
("length", "controller"),
"x[0] - x[1].getDimension('width')")
c.addConstConstraint((servo, "center"), False)
c.addConstraint((servo, "servo"), "driveservo")
c.addConstConstraint(("left","phase"), 2)
# connections
c.addConnection(("brain", "topedge0"),
("right", "topedge2"),
angle=-90)
c.addConnection(("brain", "botedge0"),
("left", "topedge0"),
angle=-90)
# Sheath
c.addParameter("battery")
c.addSubcomponent("sheath", "RectBeam")
c.addConstConstraint(("sheath","phase"), 1)
c.addConstraint(("sheath","length"), "length")
c.addConstraint(("sheath","width"), "width")
c.addConstraint(("sheath","depth"), *depthfn(["battery"], "%s + x[2]"))
c.addSubcomponent("sheathsplit", "SplitEdge")
c.addConstraint(("sheathsplit","toplength"), "width", "(x,)")
c.addConstraint(("sheathsplit","botlength"), ("driveservo", "width"),
"(x[0].getParameter('motorheight'), \
x[1] - 2*x[0].getParameter('motorheight'), \
x[0].getParameter('motorheight'))")
c.addConnection(("left", "botedge1"),
("sheathsplit", "botedge2"),
angle=180)
c.addConnection(("sheathsplit", "topedge0"),
("sheath", "topedge1"))
# USB charging port for battery
c.addSubcomponent("usb", "Cutout")
c.addConstConstraint(("usb", "dy"), 9)
c.addConstConstraint(("usb", "dx"), 4)
c.addConnection(("sheath", "face1"),
("usb", "hole"),
mode="hole",
offset=Function(*depthfn(["length", "battery"], "(4-(%s+x[3])/2, 0.5 * x[2] - 15)")))
c.toYaml("library/ESPCore.yaml")
from svggen.api.component import Component
from svggen.utils.dimensions import fs90r
from svggen.library.Arduino import ESP8266
from svggen.utils.utils import copyDecorations
class ESPCore(Component):
_test_params = {
"driveservo" : fs90r,
"controller": ESP8266(),
"height" : 50,
"length" : 90,
"width" : 65,
"battery": 7,
}
def __init__(self):
# XXX Check for yaml definition by default?
Component.__init__(self, "ESPCore.yaml")
def assemble(self):
copyDecorations(self, ("rightservoface", ("right", "face2", 1, 2)),
("rightservosheath", ("sheath", "face3", -1, 0)))
copyDecorations(self, ("leftservoface", ("left", "face2", 2, 1)),
("leftservosheath", ("sheath", "face1", 0, -1)))
copyDecorations(self, ("brainface", ("brain", "face1", 0, 1)),
("brainsheath", ("sheath", "face2", 1, 2)))
if __name__ == "__main__":
f = ESPCore()
f._make_test()
connections:
connection0:
- [brain, topedge0]
- [right, topedge2]
- {angle: -90}
connection1:
- [brain, botedge0]
- [left, topedge0]
- {angle: -90}
connection2:
- [left, botedge1]
- [sheathsplit, botedge2]
- {angle: 180}
connection3:
- [sheathsplit, topedge0]
- [sheath, topedge1]
- {}
connection4:
- [sheath, face1]
- [usb, hole]
- mode: hole
offset:
function: (4-(max(x[0].getDimension('height'), x[1].getParameter('motorwidth'))+x[3])/2,
0.5 * x[2] - 15)
parameter: [controller, driveservo, length, battery]
interfaces: {}
metadata:
battery: {default: null}
controller: {default: null}
driveservo: {default: null}
height: {default: null}
length: {default: null}
width: {default: null}
parameters: {battery: null, controller: null, driveservo: null, height: null, length: null,
width: null}
subcomponents:
brain:
classname: ESPBrains
kwargs: {}
parameters:
brain: {parameter: controller}
depth:
function: max(x[0].getDimension('height'), x[1].getParameter('motorwidth'))
parameter: [controller, driveservo]
length: {parameter: width}
left:
classname: ServoMount
kwargs: {invert: true}
parameters:
center: false
depth:
function: max(x[0].getDimension('height'), x[1].getParameter('motorwidth'))
parameter: [controller, driveservo]
length:
function: x[0] - x[1].getDimension('width')
parameter: &id001 [length, controller]
phase: 2
servo: {parameter: driveservo}
right:
classname: ServoMount
kwargs: {invert: true}
parameters:
center: false
depth:
function: max(x[0].getDimension('height'), x[1].getParameter('motorwidth'))
parameter: [controller, driveservo]
length:
function: x[0] - x[1].getDimension('width')
parameter: *id001
servo: {parameter: driveservo}
sheath:
classname: RectBeam
kwargs: {}
parameters:
depth:
function: max(x[0].getDimension('height'), x[1].getParameter('motorwidth'))
+ x[2]
parameter: [controller, driveservo, battery]
length: {parameter: length}
phase: 1
width: {parameter: width}
sheathsplit:
classname: SplitEdge
kwargs: {}
parameters:
botlength:
function: (x[0].getParameter('motorheight'), x[1] - 2*x[0].getParameter('motorheight'), x[0].getParameter('motorheight'))
parameter: [driveservo, width]
toplength: {function: '(x,)', parameter: width}
usb:
classname: Cutout
kwargs: {}
parameters: {dx: 4, dy: 9}
from svggen.library import getComponent
from svggen.library.Arduino import ESP8266
from svggen.utils.dimensions import fs90r
def test_make_seg(display=False):
f = getComponent("ESPCore", length=82, width=60, height=25)
f.setParameter("driveservo", fs90r)
f.setParameter('controller', ESP8266())
f.setParameter('battery', 5)
f.makeOutput("output/espcore", tree=True, display=display)
if __name__ == '__main__':
test_make_seg(display=True)
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!