|
@@ -16,10 +16,13 @@ class MagDistributor:
|
|
|
self.linear_dir_pin = gpio_conf.mag_dist_pos_dir_pin
|
|
self.linear_dir_pin = gpio_conf.mag_dist_pos_dir_pin
|
|
|
self.linear_step_pin = gpio_conf.mag_dist_pos_step_pin
|
|
self.linear_step_pin = gpio_conf.mag_dist_pos_step_pin
|
|
|
# self.linear_en_pin = gpio_conf.mag_dist_pos_en_pin
|
|
# self.linear_en_pin = gpio_conf.mag_dist_pos_en_pin
|
|
|
- self.rot_pin = gpio_conf.mag_dist_rot_pin
|
|
|
|
|
|
|
+ self.rot_dir_pin = gpio_conf.mag_dist_rot_dir_pin
|
|
|
|
|
+ self.rot_step_pin = gpio_conf.mag_dist_rot_step_pin
|
|
|
|
|
+ # self.rot_en_pin = gpio_conf.mag_dist_rot_en_pin
|
|
|
|
|
|
|
|
# Endstop pins
|
|
# Endstop pins
|
|
|
self.linear_limit_pin = gpio_conf.mag_dist_pos_limit_pin
|
|
self.linear_limit_pin = gpio_conf.mag_dist_pos_limit_pin
|
|
|
|
|
+ self.rot_limit_pin = gpio_conf.mag_dist_rot_limit_pin
|
|
|
|
|
|
|
|
# Cell pick sensor pin
|
|
# Cell pick sensor pin
|
|
|
self.mag_dist_sensor_pin = gpio_conf.mag_dist_sensor_pin # <-- Add this to your config
|
|
self.mag_dist_sensor_pin = gpio_conf.mag_dist_sensor_pin # <-- Add this to your config
|
|
@@ -63,7 +66,9 @@ class MagDistributor:
|
|
|
max_linear_steps = int(self.linear_length_mm * self.steps_per_mm)
|
|
max_linear_steps = int(self.linear_length_mm * self.steps_per_mm)
|
|
|
home_step_delay = self._speed_to_step_delay(self.home_speed_mmmin)
|
|
home_step_delay = self._speed_to_step_delay(self.home_speed_mmmin)
|
|
|
await self._home_axis(self.linear_dir_pin, self.linear_step_pin, self.linear_limit_pin, axis='linear', max_steps=max_linear_steps, step_delay=home_step_delay)
|
|
await self._home_axis(self.linear_dir_pin, self.linear_step_pin, self.linear_limit_pin, axis='linear', max_steps=max_linear_steps, step_delay=home_step_delay)
|
|
|
|
|
+ await self._home_axis(self.rot_dir_pin, self.rot_step_pin, self.rot_limit_pin, axis='rotational', max_steps=self.full_rot_steps, step_delay=home_step_delay)
|
|
|
self.curr_pos_mm = 0
|
|
self.curr_pos_mm = 0
|
|
|
|
|
+ self.curr_rot_deg = 0
|
|
|
self.logger.info("Mag distributor homed successfully.")
|
|
self.logger.info("Mag distributor homed successfully.")
|
|
|
|
|
|
|
|
async def _home_axis(self, dir_pin, step_pin, endstop_pin, axis='linear', max_steps = 10000, step_delay=200):
|
|
async def _home_axis(self, dir_pin, step_pin, endstop_pin, axis='linear', max_steps = 10000, step_delay=200):
|
|
@@ -89,16 +94,22 @@ class MagDistributor:
|
|
|
if self.debug:
|
|
if self.debug:
|
|
|
return
|
|
return
|
|
|
self.logger.info(f"Moving mag distributor to linear: {pos_target} mm, rot: {rot_target} deg")
|
|
self.logger.info(f"Moving mag distributor to linear: {pos_target} mm, rot: {rot_target} deg")
|
|
|
- linear_steps = int(abs(pos_target - self.curr_pos_mm) * self.steps_per_mm)
|
|
|
|
|
- linear_dir = True if pos_target > self.curr_pos_mm else False
|
|
|
|
|
|
|
+
|
|
|
# Use max speed for normal moves if not specified
|
|
# Use max speed for normal moves if not specified
|
|
|
if step_delay is None:
|
|
if step_delay is None:
|
|
|
step_delay = self._speed_to_step_delay(self.max_speed_mmmin)
|
|
step_delay = self._speed_to_step_delay(self.max_speed_mmmin)
|
|
|
|
|
+
|
|
|
|
|
+ linear_steps = int(abs(pos_target - self.curr_pos_mm) * self.steps_per_mm)
|
|
|
|
|
+ linear_dir = True if pos_target > self.curr_pos_mm else False
|
|
|
if linear_steps > 0:
|
|
if linear_steps > 0:
|
|
|
self.gpio.do_step(self.linear_dir_pin, self.linear_step_pin, linear_steps, step_delay, linear_dir)
|
|
self.gpio.do_step(self.linear_dir_pin, self.linear_step_pin, linear_steps, step_delay, linear_dir)
|
|
|
self.curr_pos_mm = pos_target
|
|
self.curr_pos_mm = pos_target
|
|
|
|
|
|
|
|
- self.gpio.set_servo_angle_smooth(self.rot_pin, rot_target, self.max_speed_mmmin * 0.03183) # Convert mm/min to deg/s with 3cm radius
|
|
|
|
|
|
|
+ rot_steps = int(abs(rot_target - self.curr_rot_deg) * self.full_rot_steps / 360)
|
|
|
|
|
+ rot_dir = True if rot_target > self.curr_rot_deg else False
|
|
|
|
|
+ if rot_steps > 0:
|
|
|
|
|
+ self.gpio.do_step(self.rot_dir_pin, self.rot_step_pin, rot_steps, step_delay, rot_dir)
|
|
|
|
|
+ self.curr_rot_deg = rot_target
|
|
|
|
|
|
|
|
def reset_feeder_magazines(self):
|
|
def reset_feeder_magazines(self):
|
|
|
"""
|
|
"""
|