Skip to content

Commit e8c15c2

Browse files
committed
merge develop
2 parents 691ecc6 + dcd62c1 commit e8c15c2

38 files changed

+1610
-309
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
name: run tests
3939
command: |
4040
. venv/bin/activate
41-
export PYTHONPATH=./stub
41+
export PYTHONPATH=./stub:test
4242
mkdir test-reports
4343
python3 -m unittest test/coderbot_test.py 2>&1 | tee test-reports/test_report.txt
4444
#python3 -m unittest test/cnn_test.py 2>&1 | tee test-reports/test_report.txt

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pip3 install -r requirements_stub.txt
3030
pip3 install -r requirements.txt
3131

3232
# Start the backend in stub mode
33-
PYTHONPATH=stub python3 init.py
33+
PYTHONPATH=stub:test python3 init.py
3434

3535
# or, run the real thing if you're on a physical RPi
3636
python3 init.py

api.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@
1313
from coderbot import CoderBot
1414
from program import ProgramEngine, Program
1515
from config import Config
16+
from coderbotTestUnit import run_test as runCoderbotTestUnit
17+
import pigpio
18+
19+
BUTTON_PIN = 16
1620

1721
bot_config = Config.get()
1822
bot = CoderBot.get_instance(
19-
servo=(bot_config.get("move_motor_mode") == "servo"),
2023
motor_trim_factor=float(bot_config.get("move_motor_trim", 1.0)),
24+
encoder=bool(bot_config.get("encoder"))
2125
)
2226

27+
query = Query()
28+
2329
def get_serial():
2430
"""
2531
Extract serial from cpuinfo file
@@ -80,13 +86,23 @@ def get_info():
8086
update_status = subprocess.check_output(["cat", "/etc/coderbot/update_status"]).decode('utf-8').replace('\n', '')
8187
except Exception:
8288
update_status = 'undefined'
89+
try:
90+
encoder = bool(Config.read().get('encoder'))
91+
if(encoder):
92+
motors = 'DC encoder motors'
93+
else:
94+
motors = 'DC motors'
95+
except Exception:
96+
motors = 'undefined'
8397

8498
serial = get_serial()
99+
85100
return {'backend_commit': backend_commit,
86101
'coderbot_version': coderbot_version,
87102
'update_status': update_status,
88103
'kernel': kernel,
89-
'serial': serial}
104+
'serial': serial,
105+
'motors': motors}
90106

91107
prog = None
92108
prog_engine = ProgramEngine.get_instance()
@@ -101,11 +117,11 @@ def stop():
101117
return 200
102118

103119
def move(data):
104-
bot.move(speed=data["speed"], elapse=data["elapse"])
120+
bot.move(speed=data["speed"], elapse=data["elapse"], distance=data["distance"])
105121
return 200
106122

107123
def turn(data):
108-
bot.turn(speed=data["speed"], elapse=data["elapse"])
124+
bot.turn(speed=data["speed"], time_elapse=data["elapse"])
109125
return 200
110126

111127
def exec(data):
@@ -116,12 +132,20 @@ def exec(data):
116132

117133
def status():
118134
sts = get_status()
135+
# getting reset log file
136+
try:
137+
with open('/home/pi/coderbot/logs/reset_trigger_service.log', 'r') as log_file:
138+
data = [x for x in log_file.read().split('\n') if x]
139+
except Exception:
140+
data = [] # if file doesn't exist, no restore as ever been performed. return empty data
141+
119142

120143
return {
121144
"status": "ok",
122145
"internetConnectivity": sts["internet_status"],
123146
"temp": sts["temp"],
124147
"uptime": sts["uptime"],
148+
"log": data
125149
}
126150

127151
def info():
@@ -132,7 +156,8 @@ def info():
132156
"backend commit build": inf["backend_commit"],
133157
"kernel" : inf["kernel"],
134158
"update status": inf["update_status"],
135-
"serial": inf["serial"]
159+
"serial": inf["serial"],
160+
"motors": inf["motors"]
136161
}
137162

138163
def restoreSettings():
@@ -204,3 +229,21 @@ def resetDefaultPrograms():
204229
with open("data/defaults/programs/" + filename) as p:
205230
q = p.read()
206231
programs.insert(json.loads(q))
232+
233+
## Reset
234+
def reset():
235+
pi = pigpio.pi('localhost')
236+
#simulating FALLING EDGE
237+
# it triggers the reset by using the service altready running on the system that detects a button press (3 sec).
238+
pi.write(BUTTON_PIN, 1)
239+
pi.write(BUTTON_PIN, 0)
240+
241+
return {
242+
"status": "ok"
243+
}
244+
245+
## Test
246+
def testCoderbot(data):
247+
# taking first JSON key value (varargin)
248+
tests_state = runCoderbotTestUnit(data[list(data.keys())[0]])
249+
return tests_state

0 commit comments

Comments
 (0)