Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smooth servo movement #21

Open
WayneKeenan opened this issue Jun 1, 2017 · 1 comment
Open

Smooth servo movement #21

WayneKeenan opened this issue Jun 1, 2017 · 1 comment

Comments

@WayneKeenan
Copy link
Owner

WayneKeenan commented Jun 1, 2017

either running average or do interpolation/fade between present pos and target

@thymjan
Copy link

thymjan commented Jun 9, 2018

This is my version for a smoother servo movement:

/usr/local/lib/python3.4/dist-packages/picraftzero/providers/servo/piconzero.py

    def set_angle(self, angle):
        msg = "Set Angle {}".format(angle)
        logger.debug(msg)
        if angle == self.last_angle or angle is None:
            return
        if self.last_angle is None:
            self.last_angle = 90

        maxanglechange = 3
        delta = angle - self.last_angle
        if abs(delta) > maxanglechange:
            logger.debug("Too fast change of angle. Throttling! angle {}, last {}".format(angle, self.last_angle))
            if delta > 0:
                angle = self.last_angle + maxanglechange
            if delta < 0:
                angle = self.last_angle - maxanglechange

        self.last_angle = angle
        logger.debug(msg)
        pz.setOutput(self.servo_id, angle)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants