-
Notifications
You must be signed in to change notification settings - Fork 10
/
mode_ESC.py
82 lines (65 loc) · 2.74 KB
/
mode_ESC.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
############################################################################
#
# QuadcopeRPI- SW for controlling a quadcopter by RPI
#
# Copyright (C) 2014 Oscar Ferrato (solenero tech)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Contact me at:
# solenero.tech@gmail.com
# solenerotech.wordpress.com
##############################################################################
#2014.10.23
from time import time, sleep
import logging
import sys
def mode_ESC(myQ):
logger = logging.getLogger('myQ.mode_ESC')
cycleTime = 0.010 # [s]
try:
#wait ack from user to start motors
while myQ.rc.command != 9 and myQ.rc.command != -1 and myQ.rc.cycling:
pass
if myQ.rc.command != -1:
myQ.rc.throttle = 0
usedMotor = -1
initTime = time()
previousTime = initTime
currentTime = initTime
#displayCommand()
while myQ.rc.cycling is True and myQ.rc.command != -1 and myQ.netscan.connectionUp is True:
#manage cycletime
while currentTime <= previousTime + cycleTime:
currentTime = time()
sleep(0.001)
previousTime = currentTime
# user commands:
if myQ.rc.command == 0 and usedMotor != 0:
usedMotor = 0
elif myQ.rc.command == 1 and usedMotor != 1:
usedMotor = 1
elif myQ.rc.command == 2 and usedMotor != 2:
usedMotor = 2
elif myQ.rc.command == 3 and usedMotor != 3:
usedMotor = 3
if usedMotor > -1 and usedMotor < 4:
#wait ack to set max Throttle
while myQ.rc.command != 5 and myQ.rc.command != -1 and myQ.rc.cycling:
pass
myQ.motor[usedMotor].setW(100)
sleep(5)
#wait ack to reset Throttle
while myQ.rc.command != 6 and myQ.rc.command != -1 and myQ.rc.cycling:
pass
myQ.motor[usedMotor].setW(0)
myQ.rc.command = -1
except:
logger.critical('Unexpected error:', sys.exc_info()[0])