Tips and tricks when controlling motors Pro Preview

There are glitches and strange behavior that you can avoid when you follow these rules.

To access the full video please subscribe to FLLCasts.com

Subscribe

  • #841
  • 20 Apr 2018

Avoid giving motor start commands in loop

Do not give several start commands one after the other. Do not put forward.start() in a loop without forward.stop(). The motor is not going to keep moving, but rather is going to change its speed randomly.

 

Start with a stop command

Another glitch that we found is that the first start command to a motor is not going to be executed well. The second start command moves the motor in full speed. So we added explicit stop right after the initialization of the GPIO ports:

#Define PWM functions
forward = GPIO.PWM(forwardPin, frequency)
backward = GPIO.PWM(backwardPin, frequency)
left = GPIO.PWM(leftPin, frequency)
right = GPIO.PWM(rightPin, frequency)
# initialize in stopped position. Helps to avoid problems
forward.stop()
backward.stop()
left.stop()
right.stop()

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

Image for Perfect STEM course. Module 1 - Smart Car with Raspberry PI
  • 118
  • 42:47
  • 136