-
Notifications
You must be signed in to change notification settings - Fork 1
/
Test.py
executable file
·127 lines (116 loc) · 4.93 KB
/
Test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# This program will let you test your ESC and brushless motor.
# Make sure your battery is not connected if you are going to calibrate it at first.
# Since you are testing your motor, I hope you don't have your propeller attached to it otherwise you are in trouble my friend...?
# This program is made by AGT @instructable.com. DO NOT REPUBLISH THIS PROGRAM... actually the program itself is harmful pssst Its not, its safe.
import os #importing os library so as to communicate with the system
import time #importing time library to make Rpi wait because its too impatient
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=18 #Connect the ESC in this GPIO pin
ESC2=24 #Connect the ESC of second motor to this GPIO pin
pi = pigpio.pi();
pi.set_servo_pulsewidth(ESC, 0)
pi.set_servo_pulsewidth(ESC2, 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")
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")
while True:
inp = input()
if inp == "stop":
stop()
break
elif inp == "control":
control()
break
elif inp == "arm":
arm()
break
else:
pi.set_servo_pulsewidth(ESC,inp)
def calibrate(): #This is the auto calibration procedure of a normal ESC
pi.set_servo_pulsewidth(ESC, 0)
print("Disconnect the battery and press Enter")
inp = input()
if inp == '':
pi.set_servo_pulsewidth(ESC, max_value)
print("Connect the battery NOW.. you will here two beeps, then wait for a gradual falling tone then press Enter")
inp = input()
if inp == '':
pi.set_servo_pulsewidth(ESC, min_value)
print ("Weird eh! Special tone")
time.sleep(7)
print ("Wait for it ....")
time.sleep (5)
print ("Im working on it, DONT WORRY JUST WAIT.....")
pi.set_servo_pulsewidth(ESC, 0)
time.sleep(2)
print ("Arming ESC now...")
pi.set_servo_pulsewidth(ESC, min_value)
time.sleep(1)
print ("See.... uhhhhh")
control() # You can change this to any other function you want
def control():
time.sleep(1)
speed = 1500 # note from harry, said "handshake" which wasnt a variable so im going with the min it recommended
# 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")
while True:
pi.set_servo_pulsewidth(ESC, speed)
pi.set_servo_pulsewidth(ESC2, speed)
inp = input()
if inp == "q":
speed -= 100 # decrementing the speed like hell
print("speed = {}".format(speed))
elif inp == "e":
speed += 100 # incrementing the speed like hell
print("speed = {}".format(speed))
elif inp == "d":
speed += 10 # incrementing the speed
print("speed = {}".format(speed))
elif inp == "a":
speed -= 10 # decrementing the speed
print("speed = {}".format(speed))
elif inp == "stop":
stop() #going for the stop function
break
elif inp == "manual":
manual_drive()
break
elif inp == "arm":
arm()
break
else:
print("Press a,q,d or e")
def arm(): #This is the arming procedure of an ESC
print ("Connect the battery and press Enter")
inp = input()
if inp == '':
pi.set_servo_pulsewidth(ESC, 0)
time.sleep(1)
pi.set_servo_pulsewidth(ESC, max_value)
time.sleep(1)
pi.set_servo_pulsewidth(ESC, min_value)
time.sleep(1)
control()
def stop(): #This will stop every action your Pi is performing for ESC ofcourse.
pi.set_servo_pulsewidth(ESC, 0)
pi.stop()
#This is the start of the program actually, to start the function it needs to be initialized before calling... stupid python.
inp = input()
if inp == "manual":
manual_drive()
elif inp == "calibrate":
calibrate()
elif inp == "arm":
arm()
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!!")