Skip to content

Commit 8dd5e6a

Browse files
committed
merge feature/atmega
2 parents 87095c5 + 427f1c9 commit 8dd5e6a

17 files changed

+235
-35
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ Thumbs.db
7070
# Swap files
7171
*.swp
7272

73-
7473
# Python3 Virtual Environment folders
7574

7675
bin/
@@ -94,3 +93,7 @@ photos/metadata.json
9493

9594
# Uploaded updates folder
9695
updatePackages/
96+
97+
# firmware
98+
firmware/
99+

atmega328p.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# RPi PINOUTS
2+
# MOSI -> GPIO10
3+
# MISO -> GPIO9
4+
# SCK -> GPIO11
5+
# CE1 -> GPIO7
6+
# CE1 -> GPIO8
7+
8+
# get the GPIO Library and SPI Library
9+
import spidev
10+
import time
11+
12+
BAUDRATE_MAX = 250000
13+
BAUDRATE = 10000
14+
15+
START = 0xff
16+
CMD_RESET = 0x00
17+
CMD_SET_DATA = 0x01
18+
CMD_GET_DATA = 0x02
19+
20+
ADDR_AI_FIRST = 0x00
21+
ADDR_AI_LAST = 0x01
22+
ADDR_DI_FIRST = 0x02
23+
ADDR_DI_LAST = 0x05
24+
ADDR_DO_FIRST = 0x00
25+
ADDR_DO_LAST = 0x0a
26+
27+
class ATMega328():
28+
29+
_instance = None
30+
31+
@classmethod
32+
def get_instance(cls):
33+
if cls._instance is None:
34+
cls._instance = ATMega328()
35+
return cls._instance
36+
37+
def __init__(self):
38+
#Initialze the SPI
39+
self.spi = spidev.SpiDev()
40+
self.spi.open(0,0)
41+
self.spi.max_speed_hz = BAUDRATE_MAX
42+
43+
def close(self):
44+
self.spi.close()
45+
46+
def digitalWrite(self, addr, value):
47+
resp = self.spi.xfer([START, CMD_SET_DATA, addr, value, 0], BAUDRATE)
48+
49+
def digitalRead(self, addr):
50+
resp = self.spi.xfer([START, CMD_GET_DATA, addr, 0, 0], BAUDRATE)
51+
return resp[3]
52+
53+
def analogRead(self, addr):
54+
resp = self.spi.xfer([START, CMD_GET_DATA, addr, 0, 0], BAUDRATE)
55+
return resp[3]
56+
57+
def get_input(self, addr):
58+
if addr >= ADDR_AI_FIRST and addr <= ADDR_AI_LAST:
59+
return self.analogRead(addr)
60+
elif addr >= ADDR_DI_FIRST and addr <= ADDR_DI_LAST:
61+
return self.digitalRead(addr)
62+
63+
def set_output(self, addr, value):
64+
if addr >= ADDR_DO_FIRST and addr <= ADDR_DO_LAST:
65+
self.digitalWrite(addr, value)

audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self):
6767
#self._google_speech_client = speech.SpeechClient()
6868

6969
def exit(self):
70-
pass
70+
pass
7171
# cleanup stuff.
7272
#self.stream_in.close()
7373
#self.pyaudio.terminate()

cnn_classifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def detect_objects(self,
128128
ymax = int(min(imH,(boxes[i][2] * imH)))
129129
xmax = int(min(imW,(boxes[i][3] * imW)))
130130

131-
object_name = self._labels[int(classes[i])]
131+
object_name = self._labels[int(classes[i])+1]
132132
pairs.append((object_name, int(100*scores[i]), (xmin, ymin, xmax, ymax)))
133133

134134
pairs = sorted(pairs, key=lambda x: x[1], reverse=True)[:top_results]

cnn_models/models.json

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
{
2-
"base_high_slow": {
3-
"output_layer": "final_result",
4-
"image_width": 224,
5-
"status": 1,
6-
"image_height": 224
7-
},
8-
"base_low_fast": {
9-
"output_layer": "final_result",
10-
"image_width": 224,
11-
"status": 100,
12-
"image_height": 224
13-
},
14-
"object_detect": {
15-
"output_layer": "final_result",
16-
"image_width": 224,
17-
"status": 1,
18-
"image_height": 224
19-
},
20-
"object_detect_mobile": {
21-
"output_layer": "final_result",
22-
"image_width": 224,
23-
"status": 1,
24-
"image_height": 224
25-
}
26-
}
2+
"generic_fast_low": {
3+
"status": 1.0,
4+
"image_height": "224",
5+
"image_width": "224",
6+
"output_layer": ""
7+
},
8+
"generic_slow_high": {
9+
"status": 1.0,
10+
"image_height": "224",
11+
"image_width": "224",
12+
"output_layer": ""
13+
},
14+
"generic_object_detect": {
15+
"status": 1.0,
16+
"image_height": "224",
17+
"image_width": "224",
18+
"output_layer": ""
19+
}
20+
}

coderbot.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ def _servo_control(self, pin, angle):
215215
self.pi.set_PWM_frequency(pin, 50)
216216
self.pi.set_PWM_dutycycle(pin, duty)
217217

218+
def _dc_enc_motor(self, speed_left=100, speed_right=100, time_elapse=0, target_distance=0):
219+
self._twin_motors_enc.control(power_left=speed_left,
220+
power_right=speed_right,
221+
time_elapse=time_elapse,
222+
target_distance=target_distance)
223+
218224
def stop(self):
219225
self._twin_motors_enc.stop()
220226

@@ -262,8 +268,3 @@ def restart(self):
262268
def reboot(self):
263269
os.system('sudo reboot')
264270

265-
def _dc_enc_motor(self, speed_left=100, speed_right=100, time_elapse=0, target_distance=0):
266-
self._twin_motors_enc.control(power_left=speed_left,
267-
power_right=speed_right,
268-
time_elapse=time_elapse,
269-
target_distance=target_distance)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "test_io_ext", "dom_code": "<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable id=\"L_e%=^0/~b[gZI1*^ZSd\">Analog_Input_1</variable></variables><block type=\"controls_whileUntil\" id=\"Dl?:_j0SBuhadu{w@UF.\" x=\"228\" y=\"37\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"pJCxtUhR_b%x:dTqn9md\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"variables_set\" id=\"+v#-(`(Qm]QpW/]^kj=k\"><field name=\"VAR\" id=\"L_e%=^0/~b[gZI1*^ZSd\">Analog_Input_1</field><value name=\"VALUE\"><block type=\"coderbot_atmega_get_input\" id=\"ai)*,59_NZc9svsP|JM:\"><field name=\"INPUT\">0</field></block></value><next><block type=\"text_print\" id=\"QtWQNQO[-l[BZ~e`Qmh$\"><value name=\"TEXT\"><block type=\"text_join\" id=\"1Ukw}Lu=x]S?%jKwDJJV\"><mutation items=\"2\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"Y9wE(=ZJTe,Y=7yA$1+2\"><field name=\"TEXT\">Analog Input 1: </field></block></value><value name=\"ADD1\"><block type=\"variables_get\" id=\"4QrPsC2-~_VL]6GoH_*O\"><field name=\"VAR\" id=\"L_e%=^0/~b[gZI1*^ZSd\">Analog_Input_1</field></block></value></block></value><next><block type=\"controls_if\" id=\"le3Rmn/8;oI#ps$J,7la\"><mutation else=\"1\"></mutation><value name=\"IF0\"><block type=\"logic_compare\" id=\"pm_-a@W30t?pU$DT9!sX\"><field name=\"OP\">GT</field><value name=\"A\"><block type=\"variables_get\" id=\"IrfeoxR,w1!`9%NW+elg\"><field name=\"VAR\" id=\"L_e%=^0/~b[gZI1*^ZSd\">Analog_Input_1</field></block></value><value name=\"B\"><block type=\"math_number\" id=\"R4b=e-`S!g*H6T7B1nel\"><field name=\"NUM\">100</field></block></value></block></value><statement name=\"DO0\"><block type=\"coderbot_atmega_set_output\" id=\"yvJ,i1lZv!^Q~}#Co+-i\"><field name=\"OUTPUT\">0</field><value name=\"VALUE\"><block type=\"logic_boolean\" id=\"Peb+]}4!:tv}p4J_B9]z\"><field name=\"BOOL\">TRUE</field></block></value></block></statement><statement name=\"ELSE\"><block type=\"coderbot_atmega_set_output\" id=\"z/@VGWnrW3D(x,d1SZ^y\"><field name=\"OUTPUT\">0</field><value name=\"VALUE\"><block type=\"logic_boolean\" id=\"$yU!z^ZFMBh!(m7s,9*:\"><field name=\"BOOL\">FALSE</field></block></value></block></statement></block></next></block></next></block></statement></block></xml>", "code": "Analog_Input_1 = None\n\n\nwhile True:\n get_prog_eng().check_end()\n Analog_Input_1 = get_atmega().get_input(0)\n get_cam().set_text('Analog Input 1: ' + str(Analog_Input_1))\n if Analog_Input_1 > 100:\n get_atmega().set_output(0, True)\n else:\n get_atmega().set_output(0, False)\n", "default": false}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "test_input", "dom_code": "<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_whileUntil\" id=\"Eg+_}I*|KDj2r:7;lzVu\" x=\"16\" y=\"109\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"vjj7Y31uCw@dAO#:o!z=\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"text_print\" id=\"|Oml,Wc+N7-.yv1S4tti\"><value name=\"TEXT\"><block type=\"text_join\" id=\"_:R_VIq+*$|i?`gYssJ/\"><mutation items=\"6\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"]Ohyg]}FmQVhZ6z;]H59\"><field name=\"TEXT\">analog 1: </field></block></value><value name=\"ADD1\"><block type=\"coderbot_atmega_get_input\" id=\"c-@JnZzRduznZ!.oS2C4\"><field name=\"INPUT\">0</field></block></value><value name=\"ADD2\"><block type=\"text\" id=\"vJK8H/$_C*KFm)w=^mc!\"><field name=\"TEXT\"> analog 2: </field></block></value><value name=\"ADD3\"><block type=\"coderbot_atmega_get_input\" id=\"!y:zHIM%S^5yuAl@{d*x\"><field name=\"INPUT\">1</field></block></value><value name=\"ADD4\"><block type=\"text\" id=\"qB~`8GzOl^}ynUI1ycwT\"><field name=\"TEXT\"> digital 1: </field></block></value><value name=\"ADD5\"><block type=\"coderbot_atmega_get_input\" id=\"tVz][Ed:A#XFy]shvSRk\"><field name=\"INPUT\">2</field></block></value></block></value></block></statement></block></xml>", "code": "while True:\n get_prog_eng().check_end()\n get_cam().set_text(''.join([str(x) for x in ['analog 1: ', get_atmega().get_input(0), ' analog 2: ', get_atmega().get_input(1), ' digital 1: ', get_atmega().get_input(2)]]))\n", "default": false}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "test_output", "dom_code": "<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_whileUntil\" id=\"Eg+_}I*|KDj2r:7;lzVu\" x=\"16\" y=\"109\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"vjj7Y31uCw@dAO#:o!z=\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"coderbot_atmega_set_output\" id=\"FWQt#G1gxXgvCXg_pJSD\"><field name=\"OUTPUT\">0</field><value name=\"VALUE\"><block type=\"logic_boolean\" id=\"OX}R-$-yxOonk~1)~V@8\"><field name=\"BOOL\">TRUE</field></block></value><next><block type=\"coderbot_sleep\" id=\"hn*rWB|=?5VdK=9d#~Q,\"><value name=\"ELAPSE\"><block type=\"math_number\" id=\"X4z;@`hR!z6Wr,]?mr!8\"><field name=\"NUM\">0.1</field></block></value><next><block type=\"coderbot_atmega_set_output\" id=\"%gGkLCH-,tpv8-Cvh@m9\"><field name=\"OUTPUT\">1</field><value name=\"VALUE\"><block type=\"logic_boolean\" id=\"$WPv~h)tka4-4ac)B;d-\"><field name=\"BOOL\">TRUE</field></block></value><next><block type=\"coderbot_sleep\" id=\";V5!M5]]T8qq|j`Bdl|h\"><value name=\"ELAPSE\"><block type=\"math_number\" id=\"Z-fZi_u%ISNl3D/?Cy_Q\"><field name=\"NUM\">0.1</field></block></value><next><block type=\"coderbot_atmega_set_output\" id=\"]S_7t8;yoT6_vto%_^]#\"><field name=\"OUTPUT\">2</field><value name=\"VALUE\"><block type=\"logic_boolean\" id=\"6a*oNkOM`1fbClSoMAu)\"><field name=\"BOOL\">TRUE</field></block></value><next><block type=\"coderbot_sleep\" id=\"!ki0*0*T,b5Gr9ZweOAH\"><value name=\"ELAPSE\"><block type=\"math_number\" id=\"jcQPERvz]3Ax}+(PFIJ~\"><field name=\"NUM\">0.1</field></block></value><next><block type=\"coderbot_atmega_set_output\" id=\"9Tmmbu4g;%4U%NN}6^*~\"><field name=\"OUTPUT\">0</field><value name=\"VALUE\"><block type=\"logic_boolean\" id=\"l8J8y%;Lq(j-2c7|]-Dx\"><field name=\"BOOL\">FALSE</field></block></value><next><block type=\"coderbot_sleep\" id=\"]sK==U]48RmtmtEQeYo.\"><value name=\"ELAPSE\"><block type=\"math_number\" id=\"QLzo=Bik,6*oygOtmi(;\"><field name=\"NUM\">0.1</field></block></value><next><block type=\"coderbot_atmega_set_output\" id=\"XF@xS7zgaWl(,^hup`qP\"><field name=\"OUTPUT\">1</field><value name=\"VALUE\"><block type=\"logic_boolean\" id=\"x5axsrx_%hM(@MP1O??0\"><field name=\"BOOL\">FALSE</field></block></value><next><block type=\"coderbot_sleep\" id=\"3_fx6eK)|8mP1ubjFfZq\"><value name=\"ELAPSE\"><block type=\"math_number\" id=\"HQ4:!?6-V41HAQaJCxtr\"><field name=\"NUM\">0.1</field></block></value><next><block type=\"coderbot_atmega_set_output\" id=\"CURTVoSTK_`uN%{,/cVc\"><field name=\"OUTPUT\">2</field><value name=\"VALUE\"><block type=\"logic_boolean\" id=\"`qobZ6#VrlWZlrz:I_yn\"><field name=\"BOOL\">FALSE</field></block></value><next><block type=\"coderbot_sleep\" id=\"V[cnM=e?S(c{9U1;d$hB\"><value name=\"ELAPSE\"><block type=\"math_number\" id=\"BU7nnRfsY/UXGOT4%Cdy\"><field name=\"NUM\">0.1</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>", "code": "while True:\n get_prog_eng().check_end()\n get_atmega().set_output(0, True)\n get_bot().sleep(0.1)\n get_atmega().set_output(1, True)\n get_bot().sleep(0.1)\n get_atmega().set_output(2, True)\n get_bot().sleep(0.1)\n get_atmega().set_output(0, False)\n get_bot().sleep(0.1)\n get_atmega().set_output(1, False)\n get_bot().sleep(0.1)\n get_atmega().set_output(2, False)\n get_bot().sleep(0.1)\n", "default": false}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "test_sonars", "dom_code": "<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_whileUntil\" id=\"0Mx[mSKoV~Gk1qbv5Wrn\" x=\"68\" y=\"148\"><field name=\"MODE\">WHILE</field><value name=\"BOOL\"><block type=\"logic_boolean\" id=\"q8(wB97}Y)d71cgy$yo#\"><field name=\"BOOL\">TRUE</field></block></value><statement name=\"DO\"><block type=\"text_print\" id=\"0fGi]QOF@I*b$5x^?f#A\"><value name=\"TEXT\"><block type=\"text_join\" id=\"HA#?-0mP[+$WL+So^l5J\"><mutation items=\"6\"></mutation><value name=\"ADD0\"><block type=\"text\" id=\"E%5LX*8^Gl-$lv$UIWBv\"><field name=\"TEXT\">Front: </field></block></value><value name=\"ADD1\"><block type=\"coderbot_sonar_get_distance\" id=\"9Mw8Ob~`;a.l/tw}fui`\"><field name=\"SONAR\">0</field></block></value><value name=\"ADD2\"><block type=\"text\" id=\"{xub0XYN;{o:+?BqYjz:\"><field name=\"TEXT\"> Right: </field></block></value><value name=\"ADD3\"><block type=\"coderbot_sonar_get_distance\" id=\"c~T`mQ}cq/AzVk|=_;k#\"><field name=\"SONAR\">1</field></block></value><value name=\"ADD4\"><block type=\"text\" id=\"{oo.?}O~rUC7|]Q9Wu0[\"><field name=\"TEXT\"> Left: </field></block></value><value name=\"ADD5\"><block type=\"coderbot_sonar_get_distance\" id=\"}`5RPkPB/|v%D;^Gc1WM\"><field name=\"SONAR\">2</field></block></value></block></value></block></statement></block></xml>", "code": "while True:\n get_prog_eng().check_end()\n get_cam().set_text(''.join([str(x) for x in ['Front: ', get_bot().get_sonar_distance(0), ' Right: ', get_bot().get_sonar_distance(1), ' Left: ', get_bot().get_sonar_distance(2)]]))\n", "default": false}

0 commit comments

Comments
 (0)