-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rover.py
62 lines (54 loc) · 1.27 KB
/
Rover.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
# Importing the packages and the libraries
from flask import Flask
import RPi.GPIO as gpio
import time
gpio.setwarnings(False)
app = Flask(__name__)
# Function to initialise the gpio channels
def init():
gpio.setmode(gpio.BCM)
gpio.setup(17,gpio.OUT)
gpio.setup(26,gpio.OUT)
gpio.setup(22,gpio.OUT)
gpio.setup(21,gpio.OUT)
# Pivot rover to the forward
@app.route('/forward')
def forward():
init()
gpio.output(17, True)
gpio.output(26, False)
gpio.output(22, False)
gpio.output(21, True)
return 'moved forward'
# Pivot rover to the right
@app.route('/pivot_right')
def pivot_right():
init()
gpio.output(17,True)
gpio.output(26,False)
gpio.output(22,False)
gpio.output(21,True)
return 'pivoted right'
# Pivot rover to the left
@app.route('/pivot_left')
def pivot_left():
init()
gpio.output(17,True)
gpio.output(26,True)
gpio.output(22,False)
gpio.output(21,True)
return 'pivoted left'
# Stop rover
@app.route('/stop_rover')
def stop_rover():
init()
gpio.output(17, False)
gpio.output(26, False)
gpio.output(22, False)
gpio.output(21, False)
return 'Rover stopped'
@app.route('/')
def index():
return 'Control Rover'
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0')