mcu: Change mcu_stepper.set_position() to take a location in millimeters
Update the set_position() method to convert from millimeters to absolute step position. Also, update PrinterStepper.get_homed_offset() and mcu_stepper.get_commanded_position() to return millimeters. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
79f31238b0
commit
e4153a536f
|
@ -23,8 +23,7 @@ class CartKinematics:
|
||||||
self.steppers[2].set_max_jerk(0., self.max_z_accel)
|
self.steppers[2].set_max_jerk(0., self.max_z_accel)
|
||||||
def set_position(self, newpos):
|
def set_position(self, newpos):
|
||||||
for i in StepList:
|
for i in StepList:
|
||||||
s = self.steppers[i]
|
self.steppers[i].mcu_stepper.set_position(newpos[i])
|
||||||
s.mcu_stepper.set_position(int(newpos[i]*s.inv_step_dist + 0.5))
|
|
||||||
def home(self, homing_state):
|
def home(self, homing_state):
|
||||||
# Each axis is homed independently and in order
|
# Each axis is homed independently and in order
|
||||||
for axis in homing_state.get_axes():
|
for axis in homing_state.get_axes():
|
||||||
|
@ -55,7 +54,7 @@ class CartKinematics:
|
||||||
homing_state.home(
|
homing_state.home(
|
||||||
list(coord), homepos, [s], s.homing_speed/2.0, second_home=True)
|
list(coord), homepos, [s], s.homing_speed/2.0, second_home=True)
|
||||||
# Set final homed position
|
# Set final homed position
|
||||||
coord[axis] = s.position_endstop + s.get_homed_offset()*s.step_dist
|
coord[axis] = s.position_endstop + s.get_homed_offset()
|
||||||
homing_state.set_homed_position(coord)
|
homing_state.set_homed_position(coord)
|
||||||
def motor_off(self, move_time):
|
def motor_off(self, move_time):
|
||||||
self.limits = [(1.0, -1.0)] * 3
|
self.limits = [(1.0, -1.0)] * 3
|
||||||
|
|
|
@ -26,12 +26,7 @@ class CoreXYKinematics:
|
||||||
def set_position(self, newpos):
|
def set_position(self, newpos):
|
||||||
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2])
|
pos = (newpos[0] + newpos[1], newpos[0] - newpos[1], newpos[2])
|
||||||
for i in StepList:
|
for i in StepList:
|
||||||
s = self.steppers[i]
|
self.steppers[i].mcu_stepper.set_position(pos[i])
|
||||||
if pos[i] >= 0.:
|
|
||||||
steppos = int(pos[i]*s.inv_step_dist + 0.5)
|
|
||||||
else:
|
|
||||||
steppos = int(pos[i]*s.inv_step_dist - 0.5)
|
|
||||||
s.mcu_stepper.set_position(steppos)
|
|
||||||
def home(self, homing_state):
|
def home(self, homing_state):
|
||||||
# Each axis is homed independently and in order
|
# Each axis is homed independently and in order
|
||||||
for axis in homing_state.get_axes():
|
for axis in homing_state.get_axes():
|
||||||
|
@ -63,8 +58,7 @@ class CoreXYKinematics:
|
||||||
list(coord), homepos, [s], s.homing_speed/2.0, second_home=True)
|
list(coord), homepos, [s], s.homing_speed/2.0, second_home=True)
|
||||||
if axis == 2:
|
if axis == 2:
|
||||||
# Support endstop phase detection on Z axis
|
# Support endstop phase detection on Z axis
|
||||||
coord[axis] = (s.position_endstop
|
coord[axis] = s.position_endstop + s.get_homed_offset()
|
||||||
+ s.get_homed_offset()*s.step_dist)
|
|
||||||
homing_state.set_homed_position(coord)
|
homing_state.set_homed_position(coord)
|
||||||
def motor_off(self, move_time):
|
def motor_off(self, move_time):
|
||||||
self.limits = [(1.0, -1.0)] * 3
|
self.limits = [(1.0, -1.0)] * 3
|
||||||
|
|
|
@ -59,10 +59,9 @@ class DeltaKinematics:
|
||||||
for stepper in self.steppers:
|
for stepper in self.steppers:
|
||||||
stepper.set_max_jerk(max_xy_halt_velocity, max_accel)
|
stepper.set_max_jerk(max_xy_halt_velocity, max_accel)
|
||||||
def _cartesian_to_actuator(self, coord):
|
def _cartesian_to_actuator(self, coord):
|
||||||
return [int((math.sqrt(self.arm_length2
|
return [math.sqrt(self.arm_length2
|
||||||
- (self.towers[i][0] - coord[0])**2
|
- (self.towers[i][0] - coord[0])**2
|
||||||
- (self.towers[i][1] - coord[1])**2) + coord[2])
|
- (self.towers[i][1] - coord[1])**2) + coord[2]
|
||||||
* self.steppers[i].inv_step_dist + 0.5)
|
|
||||||
for i in StepList]
|
for i in StepList]
|
||||||
def _actuator_to_cartesian(self, pos):
|
def _actuator_to_cartesian(self, pos):
|
||||||
# Based on code from Smoothieware
|
# Based on code from Smoothieware
|
||||||
|
@ -118,8 +117,7 @@ class DeltaKinematics:
|
||||||
homing_state.home(list(coord), homepos, self.steppers
|
homing_state.home(list(coord), homepos, self.steppers
|
||||||
, s.homing_speed/2.0, second_home=True)
|
, s.homing_speed/2.0, second_home=True)
|
||||||
# Set final homed position
|
# Set final homed position
|
||||||
coord = [(s.mcu_stepper.get_commanded_position() + s.get_homed_offset())
|
coord = [s.mcu_stepper.get_commanded_position() + s.get_homed_offset()
|
||||||
* s.step_dist
|
|
||||||
for s in self.steppers]
|
for s in self.steppers]
|
||||||
homing_state.set_homed_position(self._actuator_to_cartesian(coord))
|
homing_state.set_homed_position(self._actuator_to_cartesian(coord))
|
||||||
def motor_off(self, move_time):
|
def motor_off(self, move_time):
|
||||||
|
|
|
@ -69,10 +69,14 @@ class MCU_stepper:
|
||||||
def get_oid(self):
|
def get_oid(self):
|
||||||
return self._oid
|
return self._oid
|
||||||
def set_position(self, pos):
|
def set_position(self, pos):
|
||||||
self._mcu_position_offset += self._commanded_pos - pos
|
if pos >= 0.:
|
||||||
self._commanded_pos = pos
|
steppos = int(pos * self._inv_step_dist + 0.5)
|
||||||
|
else:
|
||||||
|
steppos = int(pos * self._inv_step_dist - 0.5)
|
||||||
|
self._mcu_position_offset += self._commanded_pos - steppos
|
||||||
|
self._commanded_pos = steppos
|
||||||
def get_commanded_position(self):
|
def get_commanded_position(self):
|
||||||
return self._commanded_pos
|
return self._commanded_pos * self._step_dist
|
||||||
def get_mcu_position(self):
|
def get_mcu_position(self):
|
||||||
return self._commanded_pos + self._mcu_position_offset
|
return self._commanded_pos + self._mcu_position_offset
|
||||||
def note_homing_start(self, homing_clock):
|
def note_homing_start(self, homing_clock):
|
||||||
|
|
|
@ -99,4 +99,4 @@ class PrinterStepper:
|
||||||
raise homing.EndstopError(
|
raise homing.EndstopError(
|
||||||
"Endstop %s incorrect phase (got %d vs %d)" % (
|
"Endstop %s incorrect phase (got %d vs %d)" % (
|
||||||
self.name, pos, self.homing_endstop_phase))
|
self.name, pos, self.homing_endstop_phase))
|
||||||
return delta
|
return delta * self.step_dist
|
||||||
|
|
Loading…
Reference in New Issue