-
Notifications
You must be signed in to change notification settings - Fork 1
/
motor_test.py
89 lines (79 loc) · 2.12 KB
/
motor_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
# coding: utf-8
import os
import time
import sys
import yaml
from lib.motor import Motor
def load_config():
"""
LOAD CONFIG FILE
Convert config.yml to DICT.
"""
cfg = None
if (os.path.isfile('config.yml')):
with open("config.yml", 'r') as ymlfile:
cfg = yaml.load(ymlfile)
else:
raise FileNotFoundError(("File not found: config.yml"))
return cfg
def main():
print("start")
motor = None
try:
"""
LOAD SETUP VARIABLES
"""
cfg = load_config()
motor = Motor(cfg)
"""
# NEUTRAL ANALOG RANGE: 370-393
neutral = 370
print(motor.analog_to_pulse(neutral))
neutral = 393
print(motor.analog_to_pulse(neutral))
# FORWARD MAXIMUM ANALOG VALUE: 280
analog = 280
print(motor.analog_to_pulse(analog))
# BACKWARD MAXIMUM ANALOG VALUE: 440
analog = 440
print(motor.analog_to_pulse(analog))
"""
# FORWARD: 369(START) - 280(MAX SPEED)
motor.set_speed(0)
time.sleep(2)
speed = 0
"""
for i in range(100):
speed += 1
motor.set_speed(speed)
print(motor.get_speed())
time.sleep(0.1)
for i in range(100):
speed -= 1
motor.set_speed(speed)
print(motor.get_speed())
time.sleep(0.1)
"""
# Setting the "BACKWARD" value to the value will apply the brake. (It is probably the function of ESC.)
# BACKWORD: 394(START) - 440(MAX SPEED)
speed = -30 # 30% backword throttle
delay = 5.0
for i in range(2):
speed = 30 # 30% throttle
motor.set_speed(speed, delay)
time.sleep(2.5)
speed = 0
motor.set_speed(speed, delay)
time.sleep(2.5)
motor.set_speed(0)
time.sleep(2)
except:
import traceback
traceback.print_exc()
finally:
if motor is not None:
motor.set_speed(0)
time.sleep(3)
print("end")
if __name__ == '__main__':
main()