Skip to content

Commit 36b84f9

Browse files
committed
merge develop 3.0
2 parents c41027a + 4dafeb7 commit 36b84f9

File tree

96 files changed

+1871
-1268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1871
-1268
lines changed

.circleci/config.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Python CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-python/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
- image: coderbot/python-gpac:3.5
11+
12+
working_directory: ~/repo
13+
14+
steps:
15+
- checkout
16+
17+
# Download and cache dependencies
18+
- restore_cache:
19+
keys:
20+
- v1-dependencies-{{ checksum "requirements_stub.txt" }}
21+
# fallback to using the latest cache if no exact match is found
22+
- v1-dependencies-
23+
24+
- run:
25+
name: install dependencies
26+
command: |
27+
python3 -m venv venv
28+
. venv/bin/activate
29+
pip install -r requirements_stub.txt
30+
31+
- save_cache:
32+
paths:
33+
- ./venv
34+
key: v1-dependencies-{{ checksum "requirements_stub.txt" }}
35+
36+
# run tests!
37+
- run:
38+
name: run tests
39+
command: |
40+
. venv/bin/activate
41+
export PYTHONPATH=./stub
42+
mkdir test-reports
43+
python3 -m unittest test/coderbot_test.py 2>&1 | tee test-reports/test_report.txt
44+
#python3 -m unittest test/cnn_test.py 2>&1 | tee test-reports/test_report.txt
45+
python3 -m unittest test/camera_test.py 2>&1 | tee test-reports/test_report.txt
46+
echo "test complete"
47+
- store_artifacts:
48+
path: test-reports/
49+
destination: tr1
50+
51+
- store_test_results:
52+
path: test-reports/
53+

.gitignore

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ photos/*.mp4
3838
photos/*.h264
3939
photos/*.json
4040

41+
#cnn models
42+
cnn_models/*
43+
cnn_models/cache/*
44+
4145
# Sounds recorded
4246
sounds/*.wav
4347

@@ -48,9 +52,6 @@ logs/*.log.*
4852
# User programs
4953
data/*.data
5054

51-
# CNN Models
52-
cnn_models/*
53-
5455
# Tutorial
5556
static/blockly-tutorial
5657

@@ -72,5 +73,22 @@ Thumbs.db
7273

7374
bin/
7475
lib/
76+
lib64/
77+
lib64
7578
share/
7679
pyvenv.cfg
80+
81+
# Vue build
82+
dist/
83+
# Docs
84+
cb_docs/
85+
86+
coderbot.cfg
87+
88+
swagger-ui/
89+
90+
# Photos
91+
photos/metadata.json
92+
93+
# Uploaded updates folder
94+
updatePackages/

LICENSE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
(C) 2014 - 2019 Roberto Previtera, Antonio Vivace, CoderBot contributors.
2+
13
GNU GENERAL PUBLIC LICENSE
24
Version 2, June 1991
35

MPU6050.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
from __future__ import print_function
21
"""This program handles the communication over I2C
32
between a Raspberry Pi and a MPU-6050 Gyroscope / Accelerometer combo.
43
Made by: MrTijn/Tijndagamer
54
Released under the MIT License
65
Copyright 2015
76
"""
87

9-
import smbus2 as smbus
108
import time
9+
import smbus2 as smbus
1110

1211
class MPU6050:
1312

@@ -88,10 +87,9 @@ def read_i2c_word(self, register):
8887

8988
value = (high << 8) + low
9089

91-
if (value >= 0x8000):
90+
if value >= 0x8000:
9291
return -((65535 - value) + 1)
93-
else:
94-
return value
92+
return value
9593

9694
# MPU-6050 Methods
9795

@@ -120,7 +118,7 @@ def set_accel_range(self, accel_range):
120118
# Write the new range to the ACCEL_CONFIG register
121119
self.bus.write_byte_data(self.address, self.ACCEL_CONFIG, accel_range)
122120

123-
def read_accel_range(self, raw = False):
121+
def read_accel_range(self, raw=False):
124122
"""Reads the range the accelerometer is set to.
125123
If raw is True, it will return the raw value from the ACCEL_CONFIG
126124
register
@@ -141,10 +139,9 @@ def read_accel_range(self, raw = False):
141139
return 8
142140
elif raw_data == self.ACCEL_RANGE_16G:
143141
return 16
144-
else:
145-
return -1
142+
return -1
146143

147-
def get_accel_data(self, g = False):
144+
def get_accel_data(self, g=False):
148145
"""Gets and returns the X, Y and Z values from the accelerometer.
149146
If g is True, it will return the data in g
150147
If g is False, it will return the data in m/s^2
@@ -174,13 +171,11 @@ def get_accel_data(self, g = False):
174171
y = y / accel_scale_modifier
175172
z = z / accel_scale_modifier
176173

177-
if g is True:
178-
return {'x': x, 'y': y, 'z': z}
179-
elif g is False:
174+
if g is False:
180175
x = x * self.GRAVITIY_MS2
181176
y = y * self.GRAVITIY_MS2
182177
z = z * self.GRAVITIY_MS2
183-
return {'x': x, 'y': y, 'z': z}
178+
return {'x': x, 'y': y, 'z': z}
184179

185180
def set_gyro_range(self, gyro_range):
186181
"""Sets the range of the gyroscope to range.
@@ -193,7 +188,7 @@ def set_gyro_range(self, gyro_range):
193188
# Write the new range to the ACCEL_CONFIG register
194189
self.bus.write_byte_data(self.address, self.GYRO_CONFIG, gyro_range)
195190

196-
def read_gyro_range(self, raw = False):
191+
def read_gyro_range(self, raw=False):
197192
"""Reads the range the gyroscope is set to.
198193
If raw is True, it will return the raw value from the GYRO_CONFIG
199194
register.
@@ -214,8 +209,7 @@ def read_gyro_range(self, raw = False):
214209
return 1000
215210
elif raw_data == self.GYRO_RANGE_2000DEG:
216211
return 2000
217-
else:
218-
return -1
212+
return -1
219213

220214
def get_gyro_data(self):
221215
"""Gets and returns the X, Y and Z values from the gyroscope.
@@ -249,9 +243,9 @@ def get_gyro_data(self):
249243

250244
def get_all_data(self):
251245
"""Reads and returns all the available data."""
252-
temp = get_temp()
253-
accel = get_accel_data()
254-
gyro = get_gyro_data()
246+
temp = self.get_temp()
247+
accel = self.get_accel_data()
248+
gyro = self.get_gyro_data()
255249

256250
return [accel, gyro, temp]
257251

@@ -267,4 +261,4 @@ def get_all_data(self):
267261
if abs(gyro_data['z']) > mpu.GYRO_THRESHOLD_Z:
268262
dz = gyro_data['z'] * dt
269263
z = z + dz
270-
print( "z: ", z, end="\r")
264+
print("z: ", z, end="\r")

README.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
1-
CoderBot
2-
========
1+
# backend
32

4-
A RaspberryPI-based bot controller
3+
> CoderBot is a RaspberryPI-based programmable robot for educational purposes. Check the [project website](https://www.coderbot.org) for more information.
4+
>
5+
> For further information about development and technical documentation, see the [Wiki](https://github.com/CoderBotOrg/coderbot/wiki).
56
6-
The module provide a simple web interface to a raspberry py "robot".
7+
This repository contains the backend, exposing the [CoderBot API](https://github.com/CoderBotOrg/backend/wiki/API-v2).
78

8-
See the [wiki](https://github.com/CoderBotOrg/coderbot/wiki) for the documentation
9+
### Quickstart
910

11+
Prerequisites:
1012

13+
```bash
14+
sudo apt install python3 python3-venv
15+
```
16+
17+
Be sure you have Python **3.6**. You may need to use `python3.6` and `python3.6-venv` packages on some repositories with python3 already pointing to **3.7** (e.g. debian unstable/sid).
18+
19+
20+
21+
```bash
22+
git clone https://github.com/CoderBotOrg/coderbot.git
23+
cd coderbot
24+
python3 -m venv .
25+
source bin/activate
26+
27+
# Install the basic requirements
28+
pip3 install -r requirements_stub.txt
29+
# Additional packages if you are running the real thing
30+
pip3 install -r requirements.txt
31+
32+
# Start the backend in stub mode
33+
PYTHONPATH=stub python3 init.py
34+
35+
# or, run the real thing if you're on a physical RPi
36+
python3 init.py
37+
```
38+
39+
Once started, the backend will expose a number of endpoints:
40+
41+
- Legacy API: [localhost:5000/`<LEGACY_METHOD>`](http://localhost:5000/);
42+
- Legacy JQuery web application: [localhost:5000/old](http://localhost:5000/old);
43+
- API v2: [localhost:5000/v2](http://localhost:5000/v2);
44+
- New Vue web application: [localhost:5000/](http://localhost:5000/) (assuming a [vue-app](https://github.com/coderbotorg/vue-app) build is placed in the `dist/` folder);
45+
- Documentation: [localhost:5000/docs](http://localhost:5000/docs) assuming a [docs](https://github.com/coderbotorg/docs) build is placed in the `cb_docs/` folder);
46+
- Swagger UI dynamic documentation of the API v2: [localhost:5000/v2/ui/index.html](http://localhost:5000/v2/ui/index.html) (once you cloned the [swagger-ui](https://github.com/coderbotorg/swagger-ui) repository inside the backend folder).
1147

_programs.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)