I'm in the process of trying to put together a small "robot" that can be controlled over the internet. I'm trying to get the code for the drive motor controls down now, and I've hit an odd issue.
This is the intended order of operations:
- Run tankcontrol.py, which serves tankcontrol.html, and also utilizes this PiMotor.py library that came with this motor HAT
- Navigate to http://raspberrypi/
- The python app receives these values and converts them into forward/reverse 0 through 100 values.
- The python app sends those commands out to the motors, using the PiMotor library above.
This all seems to work except for the last item. Even if I push my joystick all the way forward, and see leftMotor.forward(100) firing over and over again on the pi's console, the motor will change speed seemingly at random. Almost like it's having a little motor seizure. This also happens if I try to keep the motor at a lower speed, but I can tell that the apparent average speed is lower than at full speed.
Here's a video of this problem in action, with just one motor as a test. The sound of the motor really helps show what it's doing, so make sure your sound is on.
I'm also doing this on a Pi Zero W, running Raspian 9, if that helps.
Other things of mention:
- Running "python" from the CLI and just trying to run forward(100) on the motor in question works perfectly fine.
- Running a script that just utilizes that PiMotor library with a bunch of sleep functions to simulate the rapid websocket updates also works fine.
- The CPU on the Pi sits at around 50% while this is running.
- Changing the reportInterval value on tankcontrol.html (to change the rate at which changes are sent) to a lower value has no effect.
What's wrong with my code that would cause this to happen?