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

raspberry crashes by fast change of direction (4tronix Piconzero) #61

Open
thymjan opened this issue May 27, 2018 · 2 comments
Open

raspberry crashes by fast change of direction (4tronix Piconzero) #61

thymjan opened this issue May 27, 2018 · 2 comments

Comments

@thymjan
Copy link

thymjan commented May 27, 2018

I think this is also sort of a hardware issue, but maybe one can solve it with software:
If I draw the joystick fast forward/backward my raspberry pi zero w crashes and reboots.
If I'm driving forward, then stop and afterwards drive backward there is no problem.
So my idea is to implement a little delay (several milliseconds) when changing the direction.

Where would be the place to implement this?

@thymjan
Copy link
Author

thymjan commented May 28, 2018

I've helped myself:
sudo nano /usr/local/lib/python3.4/dist-packages/picraftzero/providers/motor/piconzero.py

I changed "def set_speed(self, speed)" to this:

    def set_speed(self, speed):
        msg = "set_speed({}, {})".format(self.motor_id, speed)
        logger.debug(msg)
        if speed == self._last_speed or speed is None:
            return
        if ((speed > 0) and (self._last_speed < 0)) or ((speed < 0) and (self._last_speed > 0)):
            msg = "change direction ************************"
            logger.debug(msg)
            speed = 0
            sleep(0.1)
            pz.stop()
            sleep(0.3)
            self._last_speed = speed
            return
        self._last_speed = speed
        logger.info(msg)
        # TODO: scale -100..100 to -128..127
        speed = constrain(speed, -128, 127)
        pz.setMotor(self.motor_id, speed)

At this moment it's a quick an dirty implementation but I think it sort of works. I have to optimize the sleep timings a bit, but I have to charge my battery first.

@thymjan
Copy link
Author

thymjan commented May 29, 2018

Did some homework:

        # TODO: scale -100..100 to -128..127
        logger.info("old speed: {}".format(speed))
        speed = int(255 * ((speed+100)/200) - 128)
        logger.info("new speed: {}".format(speed))

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

No branches or pull requests

1 participant