Skip to content

Commit 9b6e57c

Browse files
committed
-
1 parent 0baf343 commit 9b6e57c

15 files changed

Lines changed: 2322 additions & 9 deletions

coderbot.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ def __init__(self):
1616
pigpio.write(PIN_LEFT_BACKWARD, 0)
1717
pigpio.write(PIN_RIGHT_BACKWARD, 0)
1818

19+
the_bot = None
20+
21+
@classmethod
22+
def get_instance(cls):
23+
if not cls.the_bot:
24+
cls.the_bot = CoderBot()
25+
return cls.the_bot
26+
1927
def forward(self, seconds):
2028
pigpio.write(PIN_MOTOR_ENABLE, 1)
2129
pigpio.write(PIN_LEFT_FORWARD, 1)

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
from flask import Flask, render_template, request
55

6-
#signal = signal_reader.SignalReader()
7-
bot = coderbot.CoderBot()
6+
signal = signal_reader.SignalReader.get_instance()
7+
bot = coderbot.CoderBot.get_instance()
88

99
app = Flask(__name__,static_url_path="")
1010

signal_reader.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,28 @@ class SignalReader(Thread):
77

88
def __init__(self):
99
self.cam = Camera()
10-
time.sleep(2)
1110
self.streamer = JpegStreamer("0.0.0.0:8090")
12-
self.bot = coderbot.CoderBot()
11+
self.bot = coderbot.get_instance()
1312
Thread.__init__(self)
1413

1514
corners = [(160, 0), (480, 0), (460, 480), (180, 480)]
16-
15+
the_reader = None
16+
17+
@classmethod
18+
def get_instance(cls) {
19+
if not cls.the_reader:
20+
cls.the_reader = SignalReader()
21+
return cls.the_reader
22+
}
23+
1724
def start(self):
1825
self.finish = False
1926
print "SignalReader starting"
2027
Thread.start(self)
2128

2229
def stop(self):
2330
self.finish = True
31+
self.join()
2432

2533
def run(self):
2634
print "run"
@@ -57,13 +65,13 @@ def run(self):
5765
if lineAngle:
5866
if lineAngle > -30 and lineAngle < 30:
5967
print "turn right"
60-
self.bot.right(2)
68+
self.bot.right(1.8)
6169
elif lineAngle < -60 and lineAngle > -120:
6270
print "go forward"
6371
self.bot.forward(2)
6472
elif lineAngle > 150 or lineAngle < -150:
6573
print "turn left"
66-
self.bot.left(2)
74+
self.bot.left(1.8)
6775
elif lineAngle > 60 and lineAngle < 110:
6876
print "go backward"
6977
self.bot.backward(2)

static/.DS_Store

0 Bytes
Binary file not shown.
File renamed without changes.

static/css/bootstrap.min.css

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/fonts/.DS_Store

6 KB
Binary file not shown.
19.8 KB
Binary file not shown.

static/fonts/glyphicons-halflings-regular.svg

Lines changed: 229 additions & 0 deletions
Loading
40.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)