Motors running at different speeds

Hi,

I've built a two wheeled robot with a Pi Zero and Zeroborg at the centre and have noticed some unusual behaviour with the speed of the motors.

I've written a simple python script to step the motors up in speed by 0.05 every second, one motor runs normally and increases speed as expected whilst the other motor doesn't start to run until the power level set is 0.65.

I initiallly thought I had a bad motor so have swapped it out for a new one with the same results.

Then I swapped the motors over and the behaviour was related to which motor port the motor was connected to, not which motor was connected.

Next I've moved from using Motor 1 and 2 to using Motor 1 and 3 to utilise a separate H bridge chip for each motor. Same behaviour.

I've posted a video of the behaviour here
Video of motor behaviour

Code Snippet

    for percent in range(10,105,5):
        motor = percent / 100.0
        print ("Motor at {}% - {}".format(percent,motor))
        ZB.SetMotor1(-motor)
        ZB.SetMotor3(motor)
        time.sleep(1)

Also perhaps of note is the power source. The Pi and the Zeroborg are both powered from a battery pack of 6 1.5v AA batteries giving a nominal voltage of 9V.

Any thoughts about why I'm experiencing this behaviour? I expected slight differences in the motors but not a large difference that depends on which port the motor is connected to.

Thanks

Scott

piborg's picture

We have seen this problem already, it is an unfortunate side-effect of how the driver chips work between positive and negative speeds.

What I would suggest is that you change motor 3 to run negative:

    for percent in range(10,105,5):
        motor = percent / 100.0
        print ("Motor at {}% - {}".format(percent,motor))
        ZB.SetMotor1(-motor)
        ZB.SetMotor3(-motor)
        time.sleep(1)

Then swap the M3+ and M3- wires on the ZeroBorg itself to change the motor direction.

This should now make both motors run at the same speeds as each other.

Ironically negative speeds behave more linearly with the motors, positive speeds seem to struggle at lower values.

Thanks for the speedy response. I'll test this out tonight and let you know.

I'm trying to build a self-balancing robot so hopefully this doesn't have too much of an effect on the robots ability to balance.

Another random question, how often can I update the motor speed? 2Hz? 50Hz? 100Hz?

piborg's picture

The limitation will be the I2C bus speed, which by default is 100 Kbit/s.

Each set motor command is 3 bytes long:

  1. I2C address
  2. Command code
  3. Power level

This means 3 bytes -> 24 bits of data per message.
At a minimum there is an additional bit to start the message and one to end the message: 26 bits.
Allowing for a bits worth of delay between bytes and messages probably a realistic length in time would be ~31 bits.

For each update you will want one command per motor, 52 bits best case, ~62 bits realistically.
This gives 100 Kbit/s ÷ 52 bits ≈ 1.9 KHz best case, 100 Kbit/s ÷ 62 bits ≈ 1.6 KHz realistically.
I would recommend 1 KHz or lower to be on the safe side.

Bear in mind any other messages on the I2C will slow this down, that includes any other calls into the ZeroBorg library code.
You may be able to improve on this by increasing the Raspberry Pi's I2C rate, but we have only tested ZeroBorg at 100 Kbit/s operation.
If you do try and go higher then the ZeroBorg is limited to 7.8125 KHz absolute maximum.

100Hz should be more than adequate. Thanks for the detailed answer.

Reversing the motor direction does help with the linearity. Now I'll need to fudge some code to try to compensate for the non-linearity in other direction!

Subscribe to Comments for "Motors running at different speeds"