Radomir Dopieralski
PyCon.PL 2014
def _inverse_kinematics(self, (x, y, z)):
f = _length(x, y) - self.coxa
d = min(self.femur + self.tibia, _length(f, z))
hip = math.atan2(y, x)
knee = (
_solve_triangle(self.femur, d, self.tibia) -
math.atan2(-z, f)
)
ankle = _solve_triangle(self.femur, self.tibia, d)
return hip, knee, ankle
def creep(leg, side, delay, robot):
for i in range(delay):
yield
while True:
leg.move_to((None, None, STEP))
for i in range(4):
yield
leg.move_to((None, STRIDE, None))
for i in range(2):
yield
leg.move_to((None, None, HEIGHT))
for y in range(STRIDE, -STRIDE, -SPEED):
leg.move_to((None, y, None))
yield
def _run_animations(self, animations, fps=12):
clock = pygame.time.Clock()
while animations:
for animation in list(animations):
try:
new = next(animation)
if new is not None:
animations.remove(animation)
animations.append(itertools.chain(new, animation))
except StopIteration:
animations.remove(animation)
self.update()
clock.tick(fps)
/dev/ttyAMA0
C)