-
Notifications
You must be signed in to change notification settings - Fork 0
/
Forwardcontrol.py
92 lines (71 loc) · 2.85 KB
/
Forwardcontrol.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
# Simple demo of of the PCA9685 PWM servo/LED controller library.
from __future__ import division
from flask import Flask, render_template, request
import time
# Import the PCA9685 module.
import Adafruit_PCA9685
app = Flask(__name__, static_url_path='')
@app.route("/")
def root():
message = "Hey World"
return render_template('index.html',message=message)
@app.route("/servos",methods=['GET','POST'])
def servos():
clicked=None
if request.method == "POST":
# Uncomment to enable debug output.
#import logging
#logging.basicConfig(level=logging.DEBUG)
# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()
# Alternatively specify a different address and/or bus:
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
# Configure min and max servo pulse lengths
servo_min = 150 # Min pulse length out of 4096
servo_max = 600 # Max pulse length out of 4096
# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)
print('Moving servo on channels 0-3, press Ctrl-C to quit...')
while True:
# Move servo on channel O between extremes.
#360=clockwise, 0=counterclockwise
pwm.set_pwm(0, 0, servo_max) #Left Front Drive
time.sleep(1)
pwm.set_pwm(1, 360, servo_max) #Right Front Drive
time.sleep(1)
pwm.set_pwm(2, 0, servo_max) #Left Rear Drive
time.sleep(1)
pwm.set_pwm(3, 360, servo_max) #Right Rear Drive
time.sleep(1)
return render_template('index.html')
@app.route("/stop",methods=['GET','POST'])
def servos():
clicked=None
if request.method == "POST":
# Uncomment to enable debug output.
#import logging
#logging.basicConfig(level=logging.DEBUG)
# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()
# Alternatively specify a different address and/or bus:
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)
# Configure min and max servo pulse lengths
servo_min = 0 # Min pulse length out of 4096
servo_max = 600 # Max pulse length out of 4096
# Set frequency to 60hz, good for servos.
pwm.set_pwm_freq(60)
print('Stop servos on channels 0-3, press Ctrl-C to quit...')
while True:
# Move servo on channel O between extremes.
#360=clockwise, 0=counterclockwise
pwm.set_pwm(0, 0, servo_min) #Left Front Drive
time.sleep(1)
pwm.set_pwm(1, 360, servo_min) #Right Front Drive
time.sleep(1)
pwm.set_pwm(2, 0, servo_min) #Left Rear Drive
time.sleep(1)
pwm.set_pwm(3, 360, servo_min) #Right Rear Drive
time.sleep(1)
return render_template('index.html')
if __name__ == "__main__":
app.run(host='0.0.0.0')