Defining a pause with a servo for a robotic arm

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
tusabez
Posts: 9
Joined: Sun Jul 25, 2021 10:00 am

Defining a pause with a servo for a robotic arm

Post by tusabez » Sat Dec 04, 2021 8:01 am

Hello everyone,

I'm attempting to control a group of servos using MicroPython and the Pico. I have this code that I found online using a PCA9685 servo controller board and would like to add a definition to pause a servo during movement but not sure how to do that. I have a robotic arm that I'm controlling and basically want to send a command to pause it anywhere in the 0-180 degree range during movement. I'd appreciate any assistance.

Code: Select all

class Servos:
    def __init__(self, i2c, address=0x40, freq=50, min_us=600, max_us=2400,
                 degrees=180):
        self.period = 1000000 / freq
        self.min_duty = self._us2duty(min_us)
        self.max_duty = self._us2duty(max_us)
        self.degrees = degrees
        self.freq = freq
        self.pca9685 = PCA9685(i2c, address)
        self.pca9685.freq(freq)

    def _us2duty(self, value):
        return int(4095 * value / self.period)

    def position(self, index, degrees=None, radians=None, us=None, duty=None):
        span = self.max_duty - self.min_duty
        if degrees is not None:
            duty = self.min_duty + span * degrees / self.degrees
        elif radians is not None:
            duty = self.min_duty + span * radians / math.radians(self.degrees)
        elif us is not None:
            duty = self._us2duty(us)
        elif duty is not None:
            pass
        else:
            return self.pca9685.duty(index)
        duty = min(self.max_duty, max(self.min_duty, int(duty)))
        self.pca9685.duty(index, duty)

    def release(self, index):
        self.pca9685.duty(index, 0)

Post Reply