def test_basic(self): mate1 = Mate(Box()) mate2 = Mate(Box()) c = Coincident(mate1, mate2) # assert composition self.assertEqual(id(mate1), id(c.mate)) self.assertEqual(id(mate2), id(c.to_mate))
def make_constraints(self): board = self.components["board"] constr = [ Fixed( board.mate_origin, CoordSystem(origin=(0, 0, self.standoff + board.thickness / 2)), ) ] for i, j in enumerate(board.mount_verts()): m = Mate( self, CoordSystem( origin=(j.X, j.Y, self.standoff + board.thickness), xDir=(1, 0, 0), normal=(0, 0, 1), ), ) constr.append( Coincident(self.components[self.screw_name(i)].mate_origin, m)), constr.append( Coincident( self.components[self.standoff_name(i)].mate_top(), Mate( self, CoordSystem( origin=(j.X, j.Y, self.standoff), xDir=(1, 0, 0), normal=(0, 0, 1), ), ), )) return constr
def test_mate(self): mate = Mate(Box()) cs1 = CoordSystem(origin=(1, 1, 1)) box = Box() box.world_coords = cs1 cs2 = CoordSystem(origin=(2, 3, 4)) coords = Mate(box, cs2) c = Fixed(mate, coords) # given world_coords is from a mate self.assertEqual(cs1 + cs2, c.world_coords)
def make_constraints(self): return [ Fixed(self.components['chassis'].mate_origin), Coincident( self.components['front_axle'].mate_origin, Mate(self.components['chassis'], CoordSystem((self.wheelbase/2,0,0))), ), Coincident( self.components['rear_axle'].mate_origin, Mate(self.components['chassis'], CoordSystem((-self.wheelbase/2,0,0))), ), ]
def make_constraints(self): constr = [ Fixed(self.components["mount"].mate_origin), Coincident( self.components["stepper"].mate_origin, self.components["mount"].mate_motor(), ), ] # if driven is defined if self.driven is not None: shaft_length = self.stepper().shaft_length constr.append( Coincident( self.components["driven"].mate_wheel(), self.components["mount"].mate_motor(offset=shaft_length), )) # if the mount is defined add the mnt = self.find("mount") if self.target is not None: for i, j in enumerate(self.components["mount"].mount_points()): m = Mate( self, CoordSystem( origin=(j.X, j.Y, -mnt.thickness), xDir=(1, 0, 0), normal=(0, 0, -1), ), ) constr.append( Coincident(self.components[self.mount_name(i)].mate_origin, m)) # screws for stepper to mount for i, j in enumerate(self.components["stepper"].mount_points()): m = Mate( self, CoordSystem( origin=( j.X, -mnt.length / 2, j.Y + mnt.height / 2 + mnt.clearance / 2 + mnt.thickness, ), xDir=(1, 0, 0), normal=(0, -1, 0), ), ) constr.append( Coincident(self.components[self.screw_name(i)].mate_origin, m)) return constr
def mate_end(self, offset=0): return Mate( self, CoordSystem(origin=(-self.length / 2, 0, 0), xDir=(0, 0, 1), normal=(1, 0, 0)), )
def mate_top(self): " top of the stator" return Mate( self, CoordSystem(origin=(0, 0, self.length / 2), xDir=(0, 1, 0), normal=(0, 0, 1)))
def test_translation(self): box = Box() # +'ve translation c = Fixed(Mate(box, CoordSystem()), CoordSystem(origin=(1, 2, 3))) (part, coords) = list(solver([c]))[0] self.assertEqual(coords.origin, cadquery.Vector(1, 2, 3)) self.assertEqual(coords.xDir, cadquery.Vector(1, 0, 0)) self.assertEqual(coords.zDir, cadquery.Vector(0, 0, 1)) # -'ve translation c = Fixed(Mate(box, CoordSystem(origin=(1, 2, 3))), CoordSystem()) (part, coords) = list(solver([c]))[0] self.assertEqual(coords.origin, cadquery.Vector(-1, -2, -3)) self.assertEqual(coords.xDir, cadquery.Vector(1, 0, 0)) self.assertEqual(coords.zDir, cadquery.Vector(0, 0, 1))
def mate_right(self): return Mate( self, CoordSystem(origin=(0, self.length / 2, 0), xDir=(1, 0, 0), normal=(0, 1, 0)), )
def mate_tip(self, offset=0): return Mate( self, CoordSystem(origin=(0, 0, self.length), xDir=(1, 0, 0), normal=(0, 0, 1)), )
def mate_holder(self): return Mate( self, CoordSystem(origin=(0, 0, 0), # xDir=(1, 0, 0), normal=(0, 0, 1), ), )
def mate_gear(self): """This is at the centre and end of the drive shaft""" return Mate( self, CoordSystem(origin=(8.5, 0, 26.75), xDir=(1, 0, 1), normal=(0, 0, -1)))
def pulley_B_mate(self, offset=0): return Mate( self, CoordSystem(origin=(-offset, -self.spacing, 0), xDir=(0, 1, 0), normal=(1, 0, 0)), )
def mate_output(self, offset=0): return Mate( self, CoordSystem(origin=(0, 0, self.gap / 2), xDir=(1, 0, 0), normal=(0, 0, 1)), )
def mate_bottom(self, explode=0): return Mate( self, CoordSystem(origin=(0, 0, -2 * explode), xDir=(1, 0, 0), normal=(0, 0, -1)), )
def mate_two(self): return Mate( self, CoordSystem(origin=(0, -11, 0), # xDir=(1, 0, 0), normal=(0, -1, 0), ), )
def mate_holder(self): return Mate( self, CoordSystem(origin=(-90, 17.5, 128), xDir=(1, 0, 0), normal=(0, -1, 0)), )
def mate_beam2(self): return Mate( self, CoordSystem(origin=(10, 17.5, 128), xDir=(0, -1, 0), normal=(-1, 0, 0)), )
def test_world_coords(self): cs1 = CoordSystem(origin=(1, 2, 3)) cs2 = CoordSystem(origin=(1, 1, 1)) box = Box() box.world_coords = cs2 m = Mate(box, cs1) self.assertEqual(m.world_coords, cs1 + cs2)
def mate_top(self): return Mate( self, CoordSystem(origin=(0, 0, self.height), xDir=(1, 0, 0), normal=(0, 0, -1)), )
def mate_top(self): " connect to the end of the top cap" return Mate( self, CoordSystem(origin=(0, 0, -self.length / 2), xDir=(0, 1, 0), normal=(0, 0, -1)))
def mate_centre(self): """Assumes rotating around Z axis""" return Mate( self, CoordSystem(origin=(0, 0, +self.width / 2), # xDir=(1, 0, 0), normal=(0, -1, 0), ))
def mate_tip(self): return Mate( self, CoordSystem(origin=(0, 0, self.shaft_length), xDir=(1, 0, 0), normal=(0, 0, 1)), )
def test_rotation(self): box = Box() # +'ve rotation c = Fixed(Mate(box, CoordSystem()), CoordSystem(xDir=(1, 0.1, 0))) (part, coords) = list(solver([c]))[0] self.assertEqual(coords.origin, cadquery.Vector()) self.assertEqual(coords.xDir, cadquery.Vector(1, 0.1, 0).normalized()) self.assertEqual(coords.zDir, cadquery.Vector(0, 0, 1)) # -'ve rotation c = Fixed(Mate(box, CoordSystem(xDir=(1, 0.1, 0))), CoordSystem()) (part, coords) = list(solver([c]))[0] self.assertEqual(coords.origin, cadquery.Vector()) self.assertEqual(coords.xDir, cadquery.Vector(1, -0.1, 0).normalized()) self.assertEqual(coords.zDir, cadquery.Vector(0, 0, 1))
def mate_motor(self): return Mate( self, CoordSystem(origin=(self.motor_offset, 0, 0), xDir=(0, 0, 1), normal=(-1, 0, 0)), )
def mate_top(self): return Mate( self, CoordSystem(origin=(0, 0, self.thickness), xDir=(1, 0, 0), normal=(0, 0, 1)), )
def mate_left(self): return Mate( self, CoordSystem(origin=(0, self.seperation / 2, 0), xDir=(1, 0, 0), normal=(0, -1, 0)), )
def mate_end(self): # center of +x face return Mate(self, CoordSystem( origin=(self.length / 2, 0, 0), xDir=(0, 0, -1), normal=(-1, 0, 0), ))
def mate_top(self): # Mate point at the top of the cylinder, twist applied return Mate( self, CoordSystem.from_plane( self.local_obj.faces(">Z").workplane().plane.rotated( (0, 0, self.twist))))
def mate_bottom(self): " bottom of the stator" return Mate( self, CoordSystem(origin=(0, 0, -self.length / 2), xDir=(1, 0, 0), normal=(0, 0, -1)))