I am struggling to get my motors to perform the same on each run. The first time I run the program, they will perform the same movement about 8/10 times. The second time I start the program, the movement does not perform the same as the last. It is significantly different.
How can I get my motors to perform the same exact movement, starting at Position A, turning 180 degrees forward to Position B, and then reversing 180 degrees back to Position A. Also, if there is a better method to implement this, please let me know. Need decent speed with high torque. This is the original way that was working for me with a singular motor.
I am using a 9V battery powering into my L298N Motor controller where I have 2 6-12V Mini DC Motors directed into. I then run the according control pins to my pi. I noticed when powering just one motor, I got much more consistent results in-between program starts. I am assuming it is because the power is not weaker, splitting into the two motors? Is the difference in power producing inconsistent results?
def init(): gpio.setmode(gpio.BCM) gpio.setup(17, gpio.OUT) gpio.setup(22, gpio.OUT) gpio.setup(23, gpio.OUT) gpio.setup(24, gpio.OUT) def forward(tf): init() gpio.output(17, True) gpio.output(22, False) gpio.output(23, True) gpio.output(24, False) time.sleep(tf) gpio.cleanup() def reverse(tf): init() gpio.output(17,False) gpio.output(22, True) gpio.output(23, False) gpio.output(24, True) time.sleep(tf) gpio.cleanup() for i in range(0,10): print ("forward") forward(.015) time.sleep(1) print ("backward") reverse(.015) time.sleep(1)