Update ESC to python3

This commit is contained in:
Michael Pivato
2019-04-24 10:56:19 +09:30
parent 493647cadd
commit 87b21944c8

View File

@@ -9,30 +9,30 @@ os.system ("sudo pigpiod") #Launching GPIO library
time.sleep(1) # As i said it is too impatient and so if this delay is removed you will get an error
import pigpio #importing GPIO library
ESC=4 #Connect the ESC in this GPIO pin
ESC=19 #Connect the ESC in this GPIO pin
pi = pigpio.pi();
pi.set_servo_pulsewidth(ESC, 0)
max_value = 2000 #change this if your ESC's max value is different or leave it be
min_value = 1000 #change this if your ESC's min value is different or leave it be
print "For first time launch, select calibrate"
print "Type the exact word for the function you want"
print "calibrate OR manual OR control OR arm OR stop"
print("For first time launch, select calibrate")
print("Type the exact word for the function you want")
print("calibrate OR manual OR control OR arm OR stop")
def manual_drive(): #You will use this function to program your ESC if required
print "You have selected manual option so give a value between 0 and you max value"
print("You have selected manual option so give a value between 0 and you max value")
while True:
inp = raw_input()
if inp == "stop":
stop()
break
elif inp == "control":
control()
break
elif inp == "arm":
arm()
break
elif inp == "control":
control()
break
elif inp == "arm":
arm()
break
else:
pi.set_servo_pulsewidth(ESC,inp)
@@ -46,54 +46,54 @@ def calibrate(): #This is the auto calibration procedure of a normal ESC
inp = raw_input()
if inp == '':
pi.set_servo_pulsewidth(ESC, min_value)
print "Wierd eh! Special tone"
print("Wierd eh! Special tone")
time.sleep(7)
print "Wait for it ...."
print("Wait for it ....")
time.sleep (5)
print "Im working on it, DONT WORRY JUST WAIT....."
print("Im working on it, DONT WORRY JUST WAIT.....")
pi.set_servo_pulsewidth(ESC, 0)
time.sleep(2)
print "Arming ESC now..."
print("Arming ESC now...")
pi.set_servo_pulsewidth(ESC, min_value)
time.sleep(1)
print "See.... uhhhhh"
print("See.... uhhhhh")
control() # You can change this to any other function you want
def control():
print "I'm Starting the motor, I hope its calibrated and armed, if not restart by giving 'x'"
print("I'm Starting the motor, I hope its calibrated and armed, if not restart by giving 'x'")
time.sleep(1)
speed = 1500 # change your speed if you want to.... it should be between 700 - 2000
print "Controls - a to decrease speed & d to increase speed OR q to decrease a lot of speed & e to increase a lot of speed"
print("Controls - a to decrease speed & d to increase speed OR q to decrease a lot of speed & e to increase a lot of speed")
while True:
pi.set_servo_pulsewidth(ESC, speed)
inp = raw_input()
if inp == "q":
speed -= 100 # decrementing the speed like hell
print "speed = %d" % speed
print("speed = %d" % speed)
elif inp == "e":
speed += 100 # incrementing the speed like hell
print "speed = %d" % speed
print("speed = %d" % speed)
elif inp == "d":
speed += 10 # incrementing the speed
print "speed = %d" % speed
print("speed = %d" % speed)
elif inp == "a":
speed -= 10 # decrementing the speed
print "speed = %d" % speed
print("speed = %d" % speed)
elif inp == "stop":
stop() #going for the stop function
break
elif inp == "manual":
manual_drive()
break
elif inp == "arm":
arm()
break
elif inp == "arm":
arm()
break
else:
print "WHAT DID I SAID!! Press a,q,d or e"
print("WHAT DID I SAID!! Press a,q,d or e")
def arm(): #This is the arming procedure of an ESC
print "Connect the battery and press Enter"
print("Connect the battery and press Enter")
inp = raw_input()
if inp == '':
pi.set_servo_pulsewidth(ESC, 0)
@@ -120,5 +120,5 @@ elif inp == "control":
control()
elif inp == "stop":
stop()
else :
print "Thank You for not following the things I'm saying... now you gotta restart the program STUPID!!"
else:
print("Thank You for not following the things I'm saying... now you gotta restart the program STUPID!!")