0

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 Javascript on tankcontrol.html connects to a websocket on the python app The Javascript looks out for a joystick (currently configured just to use mine), a grabs the axis values for that joystick.
  • The Javascript does some math to work out differential steering values for the motors, values between -100 and 100 per motor.
  • 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?

  • Welcome to Raspberry Pi :-) But your question is too broad. This site isn't made for brainstorming and discuss general issues. It is made to do one specific question that can be answered detailed. Please take the short Tour and visit the Help Center to get an idea how things work here. – Ingo Mar 3 at 13:00
  • @Ingo Thanks, I've updated my question to be more direct. – Crackerjam Mar 3 at 15:28
  • Sorry, but I don't think it's possible to debug code over the Internet. Without debugging it's really hard to say what's going on. Perhaps a timing issue somewhere. – Dmitry Grigoryev Mar 6 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.