|
|
@@ -1,5 +1,6 @@
|
|
|
import logging
|
|
|
import asyncio
|
|
|
+import time
|
|
|
from robot_control.src.utils.config import RobotConfig, DefeederMagazineConfig
|
|
|
from robot_control.src.api.gpio import GPIOInterface
|
|
|
from typing import Optional
|
|
|
@@ -15,13 +16,10 @@ class MagDistributor:
|
|
|
self.linear_dir_pin = gpio_conf.mag_dist_pos_dir_pin
|
|
|
self.linear_step_pin = gpio_conf.mag_dist_pos_step_pin
|
|
|
# self.linear_en_pin = gpio_conf.mag_dist_pos_en_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
|
|
|
+ self.rot_pin = gpio_conf.mag_dist_rot_pin
|
|
|
|
|
|
# Endstop pins
|
|
|
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
|
|
|
self.mag_dist_sensor_pin = gpio_conf.mag_dist_sensor_pin # <-- Add this to your config
|
|
|
@@ -66,9 +64,6 @@ class MagDistributor:
|
|
|
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)
|
|
|
self.curr_pos_mm = 0
|
|
|
- self.logger.info("Homing rotational axis...")
|
|
|
- await self._home_axis(self.rot_dir_pin, self.rot_step_pin, self.rot_limit_pin, axis='rot', max_steps=self.full_rot_steps, step_delay=home_step_delay)
|
|
|
- self.curr_rot_deg = 0
|
|
|
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):
|
|
|
@@ -95,18 +90,15 @@ class MagDistributor:
|
|
|
return
|
|
|
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)
|
|
|
- rot_steps = int(abs(rot_target - self.curr_rot_deg) / 360 * self.full_rot_steps)
|
|
|
linear_dir = True if pos_target > self.curr_pos_mm else False
|
|
|
- rot_dir = True if rot_target > self.curr_rot_deg else False
|
|
|
# Use max speed for normal moves if not specified
|
|
|
if step_delay is None:
|
|
|
step_delay = self._speed_to_step_delay(self.max_speed_mmmin)
|
|
|
if linear_steps > 0:
|
|
|
self.gpio.do_step(self.linear_dir_pin, self.linear_step_pin, linear_steps, step_delay, linear_dir)
|
|
|
self.curr_pos_mm = pos_target
|
|
|
- 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
|
|
|
+
|
|
|
+ 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
|
|
|
|
|
|
def reset_feeder_magazines(self):
|
|
|
"""
|
|
|
@@ -137,11 +129,17 @@ class MagDistributor:
|
|
|
# Check if cell can be picked from magazines, if not add to empty magazines and continue
|
|
|
for mag_id in mags_to_try:
|
|
|
pos = magazines[mag_id].mag_pos
|
|
|
+ self.move_mag_distributor_at_pos(pos.pos_mm, 0)
|
|
|
self.move_mag_distributor_at_pos(pos.pos_mm, pos.rot_deg)
|
|
|
+ time.sleep(1)
|
|
|
# Check cell pick sensor
|
|
|
if self.mag_dist_sensor_pin and self.gpio.get_pin(self.mag_dist_sensor_pin):
|
|
|
+ self.move_mag_distributor_at_pos(pos.pos_mm, 0)
|
|
|
pos = self.config.feeder.mag_pos
|
|
|
+ self.move_mag_distributor_at_pos(pos.pos_mm, 0)
|
|
|
self.move_mag_distributor_at_pos(pos.pos_mm, pos.rot_deg)
|
|
|
+ time.sleep(1)
|
|
|
+ self.move_mag_distributor_at_pos(pos.pos_mm, 0)
|
|
|
self.logger.info(f"Cell successfully picked from magazine {mag_id} and deposited to feeder.")
|
|
|
self.current_magazine = mag_id # update current
|
|
|
return
|
|
|
@@ -164,7 +162,11 @@ class MagDistributor:
|
|
|
|
|
|
# Move to defeeder position
|
|
|
pos = self.config.defeeder.mag_pos
|
|
|
+ self.move_mag_distributor_at_pos(pos.pos_mm, 0)
|
|
|
self.move_mag_distributor_at_pos(pos.pos_mm, pos.rot_deg)
|
|
|
+ time.sleep(1)
|
|
|
+ self.move_mag_distributor_at_pos(pos.pos_mm, 0)
|
|
|
+
|
|
|
|
|
|
# Optionally check for cell presence at defeeder (if sensor available)
|
|
|
if self.mag_dist_sensor_pin and not self.gpio.get_pin(self.mag_dist_sensor_pin):
|
|
|
@@ -172,7 +174,10 @@ class MagDistributor:
|
|
|
return
|
|
|
|
|
|
# Move to target magazine position
|
|
|
+ self.move_mag_distributor_at_pos(magazine.mag_pos.pos_mm, 0)
|
|
|
self.move_mag_distributor_at_pos(magazine.mag_pos.pos_mm, magazine.mag_pos.rot_deg)
|
|
|
+ time.sleep(1)
|
|
|
+ self.move_mag_distributor_at_pos(magazine.mag_pos.pos_mm, 0)
|
|
|
|
|
|
# Optionally check for successful placement (if sensor logic applies)
|
|
|
self.logger.info(f"Cell collected from defeeder and moved to magazine {magazine.name}.")
|