delta: Store stable positions as integers

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-15 22:05:13 -04:00
parent 94dc8167c9
commit 28fa954487
1 changed files with 13 additions and 11 deletions

View File

@ -163,17 +163,16 @@ class DeltaKinematics:
def get_stable_position(self): def get_stable_position(self):
steppers = [rail.get_steppers()[0] for rail in self.rails] steppers = [rail.get_steppers()[0] for rail in self.rails]
return [int((ep - s.get_commanded_position()) / s.get_step_dist() + .5) return [int((ep - s.get_commanded_position()) / s.get_step_dist() + .5)
* s.get_step_dist()
for ep, s in zip(self.endstops, steppers)] for ep, s in zip(self.endstops, steppers)]
def get_calibrate_params(self): def get_calibrate_params(self):
return { out = { 'radius': self.radius }
'endstop_a': self.rails[0].get_homing_info().position_endstop, for i, axis in enumerate('abc'):
'endstop_b': self.rails[1].get_homing_info().position_endstop, rail = self.rails[i]
'endstop_c': self.rails[2].get_homing_info().position_endstop, out['endstop_'+axis] = rail.get_homing_info().position_endstop
'angle_a': self.angles[0], 'angle_b': self.angles[1], out['stepdist_'+axis] = rail.get_steppers()[0].get_step_dist()
'angle_c': self.angles[2], 'radius': self.radius, out['angle_'+axis] = self.angles[i]
'arm_a': self.arm_lengths[0], 'arm_b': self.arm_lengths[1], out['arm_'+axis] = self.arm_lengths[i]
'arm_c': self.arm_lengths[2] } return out
def get_positions_from_stable(self, stable_positions, params): def get_positions_from_stable(self, stable_positions, params):
angle_names = ['angle_a', 'angle_b', 'angle_c'] angle_names = ['angle_a', 'angle_b', 'angle_c']
angles = [math.radians(params[an]) for an in angle_names] angles = [math.radians(params[an]) for an in angle_names]
@ -181,13 +180,16 @@ class DeltaKinematics:
radius2 = radius**2 radius2 = radius**2
towers = [(math.cos(a) * radius, math.sin(a) * radius) for a in angles] towers = [(math.cos(a) * radius, math.sin(a) * radius) for a in angles]
arm2 = [params[an]**2 for an in ['arm_a', 'arm_b', 'arm_c']] arm2 = [params[an]**2 for an in ['arm_a', 'arm_b', 'arm_c']]
stepdist_names = ['stepdist_a', 'stepdist_b', 'stepdist_c']
stepdists = [params[sn] for sn in stepdist_names]
endstop_names = ['endstop_a', 'endstop_b', 'endstop_c'] endstop_names = ['endstop_a', 'endstop_b', 'endstop_c']
endstops = [params[en] + math.sqrt(a2 - radius2) endstops = [params[en] + math.sqrt(a2 - radius2)
for en, a2 in zip(endstop_names, arm2)] for en, a2 in zip(endstop_names, arm2)]
out = [] out = []
for spos in stable_positions: for spos in stable_positions:
sphere_coords = [(t[0], t[1], es - sp) sphere_coords = [
for t, es, sp in zip(towers, endstops, spos)] (t[0], t[1], es - sp * sd)
for t, es, sd, sp in zip(towers, endstops, stepdists, spos) ]
out.append(mathutil.trilateration(sphere_coords, arm2)) out.append(mathutil.trilateration(sphere_coords, arm2))
return out return out