def motordrive(motpin1, motpin2, optopin, DC, q): try: Motor = rpi_dc_lib.DRV8833NmDc(motpin1, motpin2, 50) #print("driving motor") speedlist = [] Motor.forward(100 - DC) # if fwd==1: # Motor.forward(100-DC) # elif #print("motor two with feedback started\n") avgspeed = measurespeed(optopin) now = time.time() while (time.time() - now) < spintime: avgspeed = measurespeed(optopin) speedlist = speedlist + [avgspeed] #print("M2 speed = " + str(avgspeed)) if fb == True and abs(avgspeed - setspeed) > 1 and DC + k * ( setspeed - avgspeed) < 99: DC = DC + k * (setspeed - avgspeed) Motor.forward(100 - DC) #input("press key to stop") #print("motor stop\n") Motor.stop(0) #time.sleep(spintime) #print("M2 speed = " + str(avgspeed)) except KeyboardInterrupt: print("CTRL-C: Terminating program.") except Exception as error: print(error) print("Unexpected error:") finally: Motor.cleanup(True) q.put(speedlist)
def motortwo(): print(" TEST: testing motor ") # Motorssetup MotorTwo = rpi_dc_lib.DRV8833NmDc(13 ,21 ,50 ,True, "motor_two") # ================ Motors two test section 1============= try: print("1. motor forward") MotorTwo.forward(15) input("press key to stop") MotorTwo.stop(0) print("motor stop\n") time.sleep(3) print("2. motor forward speed up") for i in range(15,30): MotorTwo.forward(i) time.sleep(1) MotorTwo.stop(0) print("motor stop\n") time.sleep(3) print("3. motor backward") MotorTwo.backward(15) input("press key to stop") MotorTwo.stop(0) print("motor stop\n") time.sleep(3) print("4. motor backward speed up") for i in range(15,30): MotorTwo.backward(i) time.sleep(1) MotorTwo.stop(0) print("motor stop\n") time.sleep(3) print("5 brake check") MotorTwo.forward(50) time.sleep(3) MotorTwo.brake(100) print("motor brake\n") except KeyboardInterrupt: print("CTRL-C: Terminating program.") except Exception as error: print(error) print("Unexpected error:") finally: MotorTwo.cleanup(True)
def motortwodrive(DC2): try: MotorTwo = rpi_dc_lib.DRV8833NmDc(13 ,21 ,50 ,False, "motor_two") #print("driving motor") MotorTwo.forward(100-DC2) avgspeed = measurespeed(optopin2) #input("press key to stop") #print("motor stop\n") #MotorOne.stop(0) time.sleep(spintime) #print(avgspeed) except KeyboardInterrupt: print("CTRL-C: Terminating program.") except Exception as error: print(error) print("Unexpected error:") finally: MotorTwo.cleanup(False)
def stopfunc(): print("stop") MotorOne = rpi_dc_lib.DRV8833NmDc(26, 19, 50, False, "motor_one") MotorOne.stop(0) MotorTwo = rpi_dc_lib.DRV8833NmDc(13, 21, 50, False, "motor_two") MotorTwo.stop(0)