-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Intial Commit with the Base Repository
- Loading branch information
0 parents
commit 6b1b96d
Showing
8 changed files
with
376 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0"?> | ||
|
||
<data> | ||
<container id="1"> | ||
<left at="1507161600">700</left> | ||
<left at="1507248000">680</left> | ||
<left at="1507334400">660</left> | ||
<left at="1507420800">640</left> | ||
<left at="1507507200">620</left> | ||
</container> | ||
<container id="2"> | ||
<left at="1507161600">700</left> | ||
<left at="1507248000">680</left> | ||
<left at="1507334400">660</left> | ||
<left at="1507420800">640</left> | ||
<left at="1507507200">620</left> | ||
</container> | ||
<container id="3"> | ||
<left at="1507161600">700</left> | ||
<left at="1507248000">680</left> | ||
<left at="1507334400">660</left> | ||
<left at="1507420800">640</left> | ||
<left at="1507507200">620</left> | ||
</container> | ||
<container id="4"> | ||
<left at="1507161600">700</left> | ||
<left at="1507248000">680</left> | ||
<left at="1507334400">660</left> | ||
<left at="1507420800">640</left> | ||
<left at="1507507200">620</left> | ||
</container> | ||
<container id="5"> | ||
<left at="1507161600">700</left> | ||
<left at="1507248000">680</left> | ||
<left at="1507334400">660</left> | ||
<left at="1507420800">640</left> | ||
<left at="1507507200">620</left> | ||
</container> | ||
<container id="6"> | ||
<left at="1507161600">700</left> | ||
<left at="1507248000">680</left> | ||
<left at="1507334400">660</left> | ||
<left at="1507420800">640</left> | ||
<left at="1507507200">620</left> | ||
</container> | ||
</data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0"?> | ||
|
||
<data> | ||
<container id="1"> | ||
<content>Tea</content> | ||
<left>600</left> | ||
<saturated_fat>0</saturated_fat> | ||
<polyunsaturated_fat>0</polyunsaturated_fat> | ||
<monounsaturated_fat>0</monounsaturated_fat> | ||
<cholestrol>0</cholestrol> | ||
<sodium>0.042194093</sodium> | ||
<potassium>0.181434599</potassium> | ||
<carbohydrates>0.001687764</carbohydrates> | ||
<dietary_fiber>0</dietary_fiber> | ||
<sugars>0</sugars> | ||
<protein>0</protein> | ||
<vitamin_a>0</vitamin_a> | ||
<vitamin_c>0</vitamin_c> | ||
<calcium>0</calcium> | ||
<iron>0</iron> | ||
</container> | ||
<container id="2"> | ||
<content>Coffee</content> | ||
<left>600</left> | ||
<saturated_fat>0</saturated_fat> | ||
<polyunsaturated_fat>0</polyunsaturated_fat> | ||
<monounsaturated_fat>0</monounsaturated_fat> | ||
<cholestrol>0</cholestrol> | ||
<sodium>0.042194093</sodium> | ||
<potassium>0.181434599</potassium> | ||
<carbohydrates>0.001687764</carbohydrates> | ||
<dietary_fiber>0</dietary_fiber> | ||
<sugars>0</sugars> | ||
<protein>0</protein> | ||
<vitamin_a>0</vitamin_a> | ||
<vitamin_c>0</vitamin_c> | ||
<calcium>0</calcium> | ||
<iron>0</iron> | ||
</container> | ||
<container id="3"> | ||
<content>Not Set</content> | ||
</container> | ||
<container id="4"> | ||
<content>Not Set</content> | ||
</container> | ||
<container id="5"> | ||
<content>Not Set</content> | ||
</container> | ||
<container id="6"> | ||
<content>Not Set</content> | ||
</container> | ||
</data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import mraa | ||
|
||
class Hx711: | ||
def __init__(self,dout,pd_sck, gain = 128): | ||
# self.PD_SCK = pd_sck | ||
# self.DOUT = dout | ||
self.PD_SCK = mraa.Gpio(pd_sck) | ||
self.DOUT = mraa.Gpio(dout) | ||
self.PD_SCK.dir(mraa.DIR_OUT) | ||
self.DOUT.dir(mraa.DIR_IN) | ||
self.GAIN = 1 | ||
self.OFFSET = 0 | ||
self.SCALE = 1 | ||
self.set_gain(gain) | ||
def set_gain(self,gain): | ||
if gain == 128: | ||
self.GAIN = 1 | ||
elif gain == 64: | ||
self.GAIN = 3 | ||
elif gain == 32: | ||
self.GAIN = 2 | ||
self.PD_SCK.write(0) # is for low signal | ||
self.read() | ||
def read(self): | ||
while self.DOUT.read() == 1: | ||
continue | ||
|
||
value = 0 | ||
data = 0 | ||
filler = 0x00 | ||
for i in range(24): | ||
self.PD_SCK.write(1) | ||
value = value<<1 | ||
self.PD_SCK.write(0) | ||
if(self.DOUT.read()): | ||
value = value + 1 | ||
self.PD_SCK.write(1) | ||
value = value ^ 0x800000 | ||
self.PD_SCK.write(0) | ||
return value | ||
|
||
def read_average(self,times): | ||
sum0 = 0 | ||
for i in range(times): | ||
sum0 += self.read() | ||
return sum0/times; | ||
|
||
|
||
def get_value(self,times): | ||
return self.read_average(times) - self.OFFSET | ||
|
||
|
||
def get_units(self,times): | ||
return self.get_value(times) /self.SCALE | ||
|
||
|
||
def tare(self, times): | ||
sum = self.read_average(times) | ||
self.set_offset(sum) | ||
|
||
def set_scale(self,scale): | ||
self.SCALE =scale | ||
|
||
def get_scale(self): | ||
return self.SCALE | ||
|
||
def get_offset(self): | ||
return self.OFFSET | ||
|
||
|
||
|
||
def set_offset(self,offset): | ||
self.OFFSET = offset; | ||
|
||
def power_down(self): | ||
self.PD_SCK.write(0) | ||
self.PD_SCK.write(1) | ||
|
||
def power_up(self): | ||
self.PD_SCK.write(0) | ||
|
||
|
||
# def shiftIn(self): | ||
# value =0 | ||
# for i in range(24): | ||
# self.PD_SCK.write(1) | ||
# value = value<<1 | ||
# self.PD_SCK.write(0) | ||
# if(self.DOUT.read()): | ||
# value = value + 1 | ||
|
||
# return value | ||
|
||
# def is_ready(self): | ||
# if self.DOUT.read() == 0: | ||
# return True | ||
# else: | ||
# return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import serial | ||
from time import sleep | ||
from flask import Flask,jsonify | ||
import xml.etree.ElementTree as ET | ||
import json | ||
|
||
app = Flask(__name__) | ||
|
||
tree = ET.parse('containers.xml') | ||
root = tree.getroot() | ||
|
||
tree2 = ET.parse('consumption.xml') | ||
root2 = tree2.getroot() | ||
|
||
@app.route("/") | ||
def index(): | ||
with open('weights.txt','r') as r: | ||
a = r.readline() | ||
a = a.split(" ") | ||
json_data = [] | ||
for container in root.findall('container'): | ||
content = container.find('content').text | ||
iden = container.get('id') | ||
json_data.append({"content": content, "left": a[int(iden)-1]}) | ||
return jsonify(json_data) | ||
|
||
@app.route("/containers/") | ||
def containers(): | ||
json_data = [] | ||
for container in root.findall('container'): | ||
iden = container.get('id') | ||
content = container.find('content').text | ||
left = container.find('left').text | ||
json_data.append({"id": iden,"content": content, "left": left}) | ||
return jsonify(json_data) | ||
|
||
|
||
@app.route("/container/<iden>") | ||
def container(iden): | ||
json_data = [] | ||
for container in root.findall('.//container[@id="'+iden+'"]'): | ||
iden = container.get('id') | ||
content = container.find('content').text | ||
left = container.find('left').text | ||
saturated_fat = container.find('saturated_fat').text | ||
polyunsaturated_fat = container.find('polyunsaturated_fat').text | ||
monounsaturated_fat = container.find('monounsaturated_fat').text | ||
cholestrol = container.find('cholestrol').text | ||
sodium = container.find('sodium').text | ||
potassium = container.find('potassium').text | ||
carbohydrates = container.find('carbohydrates').text | ||
dietary_fiber = container.find('dietary_fiber').text | ||
sugars = container.find('sugars').text | ||
protein = container.find('protein').text | ||
vitamin_a = container.find('vitamin_a').text | ||
vitamin_c = container.find('vitamin_c').text | ||
calcium = container.find('calcium').text | ||
iron = container.find('iron').text | ||
json_data.append({"id": iden,"content": content, "left": left, "polyunsaturated_fat": polyunsaturated_fat, "monounsaturated_fat": monounsaturated_fat, "cholestrol": cholestrol, "sodium": sodium, "potassium": potassium, "carbohydrates": carbohydrates, "dietary_fiber": dietary_fiber, "sugars": sugars, "protein": protein, "vitamin_a": vitamin_a, "vitamin_c": vitamin_c, "calcium": calcium, "iron": iron}) | ||
return jsonify(json_data) | ||
|
||
@app.route("/consumption_all/") | ||
def consumption_all(): | ||
json_data = [] | ||
for container in root2.findall('.//container'): | ||
for left in container: | ||
json_data.append({"timestamp": left.get("at"), "left": left.text}) | ||
return jsonify(json_data) | ||
|
||
@app.route("/consumption/<iden>") | ||
def consumption(iden): | ||
json_data = [] | ||
for container in root2.findall('.//container[@id="'+iden+'"]'): | ||
for left in container: | ||
json_data.append({"timestamp": left.get("at"), "left": left.text}) | ||
return jsonify(json_data) | ||
|
||
app.run(host= '0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from hx711 import Hx711 | ||
from time import sleep | ||
calibration_factor = -7050.0 | ||
a1 = Hx711(36,20) | ||
a2 = Hx711(48,14) | ||
a1.set_scale(calibration_factor) | ||
a2.set_scale(calibration_factor) | ||
a1.tare(1) | ||
a2.tare(1) | ||
borders = [10,20,30,40,50,60] | ||
l1 = 5 | ||
l2 = 55 | ||
threshold_w = 1.0 | ||
threshold_x = 4 | ||
x =float() | ||
w = float() | ||
x_p = 0.0 | ||
w_p = 0.0 | ||
x_n = float() | ||
w_n = float() | ||
mark = [0.0,0.0,0.0,0.0,0.0,0.0] # places on the shelf for containers | ||
mark2 = [0,0,0,0,0,0] | ||
while 1: | ||
arr = [] | ||
arr2 = [] | ||
for i in range(10): | ||
arr.append(a1.get_units(1)) | ||
arr2.append(a2.get_units(1)) | ||
arr.sort() | ||
arr2.sort() | ||
|
||
r1 = (arr[6]+ arr[5] + arr[3] + arr[4])/4 | ||
r2 = (arr2[6] + arr2[5] + arr2[3] + arr2[4])/4 | ||
|
||
w = r1 + r2 | ||
if w > threshold_w: | ||
x = (r1*l1 + r2*l2)/w | ||
|
||
if w-w_p > threshold_w or w_p-w > threshold_w or x-x_p > threshold_x or x_p-x > threshold_x : | ||
w_n = w - w_p | ||
x_n = (w*x - w_p*x_p)/w_n | ||
|
||
for i in range(6): | ||
if x_n < borders[i]: | ||
if w_n > 0: | ||
mark[i] = w_n # replacing 1 with the weight added | ||
mark2[i] = 1 | ||
print "Container Added at : " + str(i + 1) | ||
elif w_n < 0: | ||
mark2[i] = 0 | ||
mark[i] = 0 | ||
print "Container Removed from : " + str(i+1) | ||
break | ||
|
||
else: | ||
for i in range(6): | ||
mark2[i] = 0 | ||
mark[i] = 0.0 # not sure about this slot | ||
x = 0 | ||
w_p = w | ||
x_p = x | ||
string = str() | ||
string2 = str() | ||
for i in range(6): | ||
string = string + str(mark[i]) + " " | ||
string2 = string2 + str(mark2[i]) + " " | ||
print string | ||
print string2 | ||
with open('weights.txt','w') as w: | ||
w.write(string) | ||
|
||
|
||
a1.power_down() | ||
a2.power_down() | ||
sleep(1) | ||
a1.power_up() | ||
a2.power_up() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from hx711 import Hx711 | ||
a = Hx711(36,20) | ||
abuf = [] | ||
while 1: | ||
abuf = [] | ||
for i in range(10): | ||
abuf.append(a.read()) | ||
|
||
abuf.sort() | ||
string = str() | ||
for i in range(10): | ||
string = string + str(abuf[i]) + " " | ||
|
||
aval = (abuf[4] + abuf[3] + abuf[5] + abuf[6])/4 | ||
print aval | ||
print string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from hx711 import Hx711 | ||
a = Hx711(48,14) | ||
while 1: | ||
print a.read() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0 0.0 0.0 0.0 0.0 0.0 |