8000 prepare 5.0-rc4 by previ · Pull Request #172 · CoderBotOrg/backend · GitHub
[go: up one dir, main page]

Skip to content
8000

prepare 5.0-rc4 #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 59 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ba975a5
tf 2.7
previ Jan 21, 2022
e437748
revert tf 2.1
previ Jan 22, 2022
9d5fdf4
bump numpy ver
previ Jan 23, 2022
7c7ee87
bump requirements_stub
previ Jan 24, 2022
ba9729e
bump requirements_stub
previ Jan 24, 2022
80c3b6f
led ws2812b
previ Jan 25, 2022
e14de56
led ws2812b
previ Jan 25, 2022
bcbba45
led ws2812b
previ Jan 25, 2022
f2c224a
led ws2812b
previ Jan 26, 2022
140285d
add listMusicPackages api
previ Jan 29, 2022
d88b342
fix musicPackage export
previ Jan 30, 2022
cfab93b
remove coderbot-copy.py
previ Jan 30, 2022
c90ccf8
fix music package removal
previ Feb 1, 2022
db7bfde
Merge branch 'develop' of https://github.com/CoderBotOrg/backend into…
previ Feb 1, 2022
1c69018
v1 feature parity
previ Feb 1, 2022
0cefff7
fix #155
previ Feb 6, 2022
a6eec09
fix program status and log with v2
previ Feb 7, 2022
d1d3882
update ci
previ Feb 8, 2022
55023d5
add default activity init
previ Mar 6, 2022
5763bc8
add default activity init
previ Mar 7, 2022
a3f291b
add default activity
previ Mar 9, 2022
ca1b990
activity default parameters
previ Mar 12, 2022
c096602
bullseye wip
previ May 28, 2022
fa63bb4
bullseye wip
previ May 29, 2022
5d50a5e
Update audioControls.py
previ May 29, 2022
0f3e5f6
bullseye wip
previ May 29, 2022
1266d83
Update audio.py
previ Jun 8, 2022
e032049
update stock activities
previ Jun 8, 2022
d58a6d8
Update program.py
previ Jun 11, 2022
94e2c76
Update activity_default.json
previ Jun 12, 2022
a1ec6ac
Update coderbot.py
previ Jun 18, 2022
ea027ed
no longer init_activities
previ Jun 28, 2022
c71cfc7
move init_activities on frontend for i18n
previ Jun 28, 2022
795fd4c
fix v4.1 bugs
previ Jul 3, 2022
06ad987
fix 4.1 bugs
previ Jul 3, 2022
a5699ba
fix 4.1 bugs
previ Jul 3, 2022
e6b0ffb
fix 4.1 bugs
previ Jul 3, 2022
0cadf12
fix 4.1 bugs
previ Jul 3, 2022
6dc5198
fix v4.1 bugs
previ Jul 3, 2022
94985a5
fix 4.1 bugs
previ Jul 4, 2022
76b850a
fix 4.1 bugs
previ Jul 4, 2022
216b1f8
fix 4.1 bugs
previ Jul 4, 2022
3dc0eb3
fix 4.1 bugs
previ Jul 5, 2022
02d3601
fix 4.1 bugs
previ Jul 6, 2022
5de8c00
Update wifi.py
previ Jul 7, 2022
86bcc8d
Update wifi.py
previ Jul 8, 2022
9ab32b3
add CONTRIBUTING.md (#162)
avivace Jul 8, 2022
66441fa
merge master
previ Jul 8, 2022
5454eaa
fix event
previ Aug 13, 2022
cc4792a
Refactor API (#166)
previ Oct 23, 2022
f378bd4
Refactor api v3 (#167)
previ Oct 25, 2022
0920d25
wip #164
previ Oct 26, 2022
e78c71f
wip #164
previ Oct 26, 2022
6a32faa
wip #164
previ Oct 26, 2022
a82fe38
wip #164
previ Oct 27, 2022
5f84450
wip #164
previ Oct 27, 2022
53537b3
wip #164
previ Oct 27, 2022
4b106cb
merge master into develop
previ Oct 27, 2022
2f64fe2
parent 4b106cba48d5a8efb0a29c9d81566edaf563f651
previ Oct 30, 2022
File filter

Filter by extension

Filter by ext 8000 ension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor api v3 (#167)
* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* merge remove_old_ui

* merge remove_old_ui

* fix merge

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* WIP #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wop #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #184

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

* wip #164

Co-authored-by: Roberto Previtera <roberto@MacBook-Air.station>
  • Loading branch information
previ and Roberto Previtera authored Oct 25, 2022
commit f378bd4e39803bfc246e66927c6d6f9c1f7aafae
11 changes: 8 additions & 3 deletions .github/workflows/build_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ jobs:
#python3 -m unittest test/cnn_test.py 2>&1 | tee test-reports/test_report.txt
echo "test complete"
- run: |
export PYTHONPATH=./coderbot:./stub:./test
export PYTHONPATH=./stub:./coderbot:./test
python3 coderbot/main.py > coderbot.log &
sleep 30
apt-get install -y python3-venv
mkdir -p schemathesis
python3 -m venv schemathesis
. schemathesis/bin/activate
pip install schemathesis
st run --endpoint '^(?!(\/api\/v1\/video\/stream|\/api\/v1\/control\/move|\/api\/v1\/video\/rec|\/api\/v1\/video\/stop)$).*$' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
st run --endpoint 'activities' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
st run --endpoint 'media' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
st run --endpoint 'control/speak' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
st run --endpoint 'control/stop' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
st run --endpoint 'music' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
st run --endpoint 'programs' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
echo "openapi test complete"

release-backend:
#needs: [test]
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Docker meta
Expand Down
16 changes: 6 additions & 10 deletions coderbot/activity.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from tinydb import TinyDB, Query
from tinydb.operations import delete
import json

# Programs and Activities databases
class Activities():
_instance = None

@classmethod
def get_instance(cls):
if cls._instance == None:
if cls._instance is None:
cls._instance = Activities()
return cls._instance

Expand All @@ -22,15 +20,14 @@ def load(self, name, default):
if len(activities) > 0:
return activities[0]
elif default is not None:
default_Activities = self.activities.search(self.query.default == True)
if len(self.activities.search(self.query.default == True)) > 0:
return self.activities.search(self.query.default == True)[0]
else:
return None
return None
return None

def save(self, name, activity):
# if saved activity is "default", reset existing default activity to "non-default"
if activity.get("default", False) == True:
if activity.get("default", False) is True:
self.activities.update({'default': False})
if self.activities.search(self.query.name == name) == []:
self.activities.insert(activity)
Expand All @@ -41,10 +38,9 @@ def delete(self, name):
activities = self.activities.search(self.query.name == name)
if len(activities) > 0:
activity = activities[0]
if activity.get("default", False) == True:
if activity.get("default", False) is True:
self.activities.update({'default': True}, self.query.stock == True)
self.activities.remove(self.query.name == activity["name"])

def list(self):
return self.activities.all()

50 changes: 27 additions & 23 deletions coderbot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from audio import Audio
from event import EventManager
from coderbotTestUnit import run_test as runCoderbotTestUnit
from balena import Balena

BUTTON_PIN = 16

Expand Down Expand Up @@ -95,7 +96,7 @@ def get_info():
backend_commit = "undefined"
coderbot_version = "undefined"
update_status = "ok"
kernel = 'undefined'
device = {}
motors = 'undefined'

try:
Expand All @@ -107,11 +108,6 @@ def get_info():
except Exception:
pass

try:
kernel = subprocess.check_output(["uname", "-r"]).decode('utf-8').replace('\n', '')
except Exception:
pass

try:
encoder = bool(Config.read().get('encoder'))
if(encoder):
Expand All @@ -123,12 +119,16 @@ def get_info():

serial = get_serial()

return {'backend_commit': backend_commit,
'coderbot_version': coderbot_version,
'update_status': update_status,
'kernel': kernel,
'serial': serial,
'motors': motors}
try:
device = Baleba.get_instance().device()
except Exception:
pass
return { 'backend_commit': device.get("commit"),
'coderbot_version': coderbot_version,
'update_status': device.get("status"),
'kernel': device.get("os_version"),
'serial': serial,
'motors': motors }

prog = None
prog_engine = ProgramEngine.get_instance()
Expand Down Expand Up @@ -161,21 +161,24 @@ def turn(body):
def takePhoto():
try:
cam.photo_take()
Audio.say(config.get("sound_shutter"))
audio_device.say(config.get("sound_shutter"))
return 200
except Exception as e:
logging.warning("Error: %s", e)

def recVideo():
try:
cam.video_rec()
audio_device.say(config.get("sound_shutter"))
return 200
except Exception as e:
logging.warning("Error: %s", e)

def stopVideo():
try:
cam.video_stop()
audio_device.say(config.get("sound_shutter"))
return 200
except Exception as e:
logging.warning("Error: %s", e)

Expand All @@ -184,24 +187,24 @@ def speak(body):
locale = body.get("locale", "")
logging.debug("say: " + text + " in: " + locale)
audio_device.say(text, locale)
return 200

def reset():
logging.debug("reset bot")
shutil.rmtree("data/*")
bot.restart()
Balena.get_instance().purge()
return 200

def halt():
logging.debug("shutting down")
audio_device.say(what=config.get("sound_stop"))
bot.halt()
Balena.get_instance().shutdown()
return 200

def restart():
logging.debug("restarting bot")
bot.restart()
Balena.get_instance().restart()

def reboot():
logging.debug("rebooting")
bot.reboot()
audio_device.say(what=config.get("sound_stop"))
Balena.get_instance().reboot()
return 200

def video_stream(a_cam):
while True:
Expand Down Expand Up @@ -287,13 +290,14 @@ def info():

def restoreSettings():
Config.restore()
restart()
return restart()

def loadSettings():
return Config.get()

def saveSettings(body):
Config.write(body)
return 200

def updateFromPackage():
os.system('sudo bash /home/pi/clean-update.sh')
Expand Down
44 changes: 44 additions & 0 deletions coderbot/balena/__init__.py
Original file line number Diff line number Diff line change
@@ - 10000 0,0 +1,44 @@
import os
from urllib.request import urlopen, Request
import json
import logging

class Balena():
_instance = None

@classmethod
def get_instance(cls):
if cls._instance is None:
cls._instance = Balena()
return cls._instance

def __init__(self):
self.supervisor_address = os.environ["BALENA_SUPERVISOR_ADDRESS"]
self.supervisor_key = os.environ["BALENA_SUPERVISOR_API_KEY"]
self.app_id_data = json.dumps({ "appId": os.environ["BALENA_APP_ID"] }).encode("utf-8")
self.headers = { 'Content-Type': 'application/json' }

def purge(self):
logging.debug("reset bot")
req = Request(f'{self.supervisor_address}/v1/purge?apikey={self.supervisor_key}', data=self.app_id_data, headers=self.headers, method='POST')
return urlopen(req).read()

def shutdown(self):
logging.debug("shutdown bot")
req = Request(f'{self.supervisor_address}/v1/shutdown?apikey={self.supervisor_key}', headers=self.headers, method='POST')
return urlopen(req).read()

def restart(self):
logging.debug("restarting bot")
req = Request(f'{self.supervisor_address}/v1/restart?apikey={self.supervisor_key}', data=self.app_id_data, headers=self.headers, method='POST')
return urlopen(req).read()

def reboot(self):
logging.debug("reboot bot")
req = Request(f'{self.supervisor_address}/v1/reboot?apikey={self.supervisor_key}', headers=self.headers, method='POST')
return urlopen(req).read()

def device(self):
logging.debug("reboot bot", f'{self.supervisor_address}get?apikey={self.supervisor_key}')
req = Request(f'{self.supervisor_address}/device?apikey={self.supervisor_key}', headers=self.headers, method='GET')
return json.load(urlopen(req))
12 changes: 1 addition & 11 deletions coderbot/coderbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import logging
import pigpio
import sonar
import hw.mpu
from hw import mpu
from rotary_encoder.wheelsaxel import WheelsAxel

# GPIO
Expand Down Expand Up @@ -268,13 +268,3 @@ def _cb_button(self, gpio, level, tick):
logging.info("pushed: %d, %d", level, tick)
cb()

def halt(self):
logging.info("halt requested")
pass

def restart(self):
sys.exit()

def reboot(self):
logging.info("reboot requested")

Empty file added coderbot/hw/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion coderbot/hw/mpu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hw import lsm9ds1
from . import lsm9ds1
import time

class AccelGyroMag:
Expand Down
7 changes: 2 additions & 5 deletions coderbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@
import os
import logging
import logging.handlers
import subprocess
import picamera
import connexion

from flask import (send_from_directory, redirect)

from flask_cors import CORS

from coderbot import CoderBot
from camera import Camera
from motion import Motion
from audio import Audio
from program import ProgramEngine, Program
from program import ProgramEngine
from config import Config
from cnn.cnn_manager import CNNManager
from event import EventManager
from coderbot import CoderBot

# Logging configuration
logger = logging.getLogger()
Expand Down
4 changes: 2 additions & 2 deletions coderbot/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import event
import music
import musicPackages
import hw.atmega328p
from hw.atmega328p import ATMega328

PROGRAM_PATH = "./data/"
PROGRAM_PREFIX = "program_"
Expand Down Expand Up @@ -66,7 +66,7 @@ def get_music():
return music.Music.get_instance(musicPackageManager)

def get_atmega():
return atmega328p.ATMega328.get_instance()
return ATMega328.get_instance()

class ProgramEngine:

Expand Down
2 changes: 1 addition & 1 deletion defaults/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"hw_version":"5",
"audio_volume_level":"100",
"wifi_mode":"ap",
"wifi_ssid":"coderbot_CHANGEMEATFIRSTRUN",
"wifi_ssid":"coderbot",
"wifi_psk":"coderbot",
"packages_installed":"",
"admin_password":"",
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ ADD docker/scripts/*.sh /tmp/.
RUN /tmp/install_generic_cnn_models.sh
RUN /tmp/install_lib_firmware.sh

ENTRYPOINT cd /coderbot && python3 coderbot/main.py
ENTRYPOINT cd /coderbot && modprobe i2c-dev && python3 coderbot/main.py
26 changes: 26 additions & 0 deletions stub/balena/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Balena():
_instance = None

@classmethod
def get_instance(cls):
if cls._instance is None:
cls._instance = Balena()
return cls._instance

def __init__(self):
pass

def purge(self):
return ""

def shutdown(self):
return ""

def restart(self):
return ""

def reboot(self):
return ""

def device(self):
return {}
0