Browse Source

add: do_step() - motor enabling

SG/Cellrobot 3 months ago
parent
commit
4aaad569b9
2 changed files with 7 additions and 7 deletions
  1. 2 2
      robot_control/src/api/gpio.py
  2. 5 5
      robot_control/src/robot/mag_distributor.py

+ 2 - 2
robot_control/src/api/gpio.py

@@ -127,7 +127,7 @@ class PiGPIO(GPIOInterface):
         self.set_servo_angle(pin, target_angle_deg)
         self._servo_angles[pin] = target_angle_deg
 
-    def do_step(self, dir_pin: int, step_pin: int, steps: int = 100, step_delay_us: int = 200, direction: bool = True):
+    def do_step(self, en_pin: int, dir_pin: int, step_pin: int, steps: int = 100, step_delay_us: int = 200, direction: bool = True):
         """
         Perform a step operation on a stepper motor with chunking to prevent connection reset.
         
@@ -144,7 +144,7 @@ class PiGPIO(GPIOInterface):
             direction: True for forward, False for reverse
         """
         #print(f"[CHUNKED] Moving {steps} steps, direction: {direction}, delay: {step_delay_us}us")
-        #self.set_pin(en_pin, 0)
+        self.set_pin(en_pin, 0)
 
         # Set direction once at the beginning
         self.set_pin(dir_pin, 1 if direction else 0)

+ 5 - 5
robot_control/src/robot/mag_distributor.py

@@ -15,7 +15,7 @@ class MagDistributor:
         gpio_conf = config.gpio
         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.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
@@ -86,13 +86,13 @@ class MagDistributor:
         self.logger.info("Homing linear axis...")
         max_linear_steps = int(self.linear_length_mm * self.steps_per_mm)
         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_en_pin, 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_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=50):
+    async def _home_axis(self, en_pin, dir_pin, step_pin, endstop_pin, axis='linear', max_steps = 10000, step_delay=50):
         """
         Home a single axis by moving until the endstop is triggered.
         """
@@ -104,7 +104,7 @@ class MagDistributor:
         for _ in range(max_steps):
             if not self.gpio.get_pin(endstop_pin):
                 break
-            self.gpio.do_step(dir_pin, step_pin, 1, step_delay, True)
+            self.gpio.do_step(en_pin, dir_pin, step_pin, 1, step_delay, True)
             await asyncio.sleep(0.001)
         else:
             raise RuntimeError(f"{axis} axis homing failed")
@@ -125,7 +125,7 @@ class MagDistributor:
         linear_steps = int(abs(pos_target - self.curr_pos_mm) * self.steps_per_mm)
         linear_dir = False if pos_target > self.curr_pos_mm else True
         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_en_pin, self.linear_dir_pin, self.linear_step_pin, linear_steps, step_delay, linear_dir)
             self.curr_pos_mm = pos_target