Skip to content

Commit

Permalink
merge develop 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
previ committed Feb 10, 2019
2 parents c41027a + 4dafeb7 commit 36b84f9
Show file tree
Hide file tree
Showing 96 changed files with 1,871 additions and 1,268 deletions.
53 changes: 53 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: coderbot/python-gpac:3.5

working_directory: ~/repo

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "requirements_stub.txt" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements_stub.txt
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "requirements_stub.txt" }}

# run tests!
- run:
name: run tests
command: |
. venv/bin/activate
export PYTHONPATH=./stub
mkdir test-reports
python3 -m unittest test/coderbot_test.py 2>&1 | tee test-reports/test_report.txt
#python3 -m unittest test/cnn_test.py 2>&1 | tee test-reports/test_report.txt
python3 -m unittest test/camera_test.py 2>&1 | tee test-reports/test_report.txt
echo "test complete"
- store_artifacts:
path: test-reports/
destination: tr1

- store_test_results:
path: test-reports/

24 changes: 21 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ photos/*.mp4
photos/*.h264
photos/*.json

#cnn models
cnn_models/*
cnn_models/cache/*

# Sounds recorded
sounds/*.wav

Expand All @@ -48,9 +52,6 @@ logs/*.log.*
# User programs
data/*.data

# CNN Models
cnn_models/*

# Tutorial
static/blockly-tutorial

Expand All @@ -72,5 +73,22 @@ Thumbs.db

bin/
lib/
lib64/
lib64
share/
pyvenv.cfg

# Vue build
dist/
# Docs
cb_docs/

coderbot.cfg

swagger-ui/

# Photos
photos/metadata.json

# Uploaded updates folder
updatePackages/
2 changes: 2 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(C) 2014 - 2019 Roberto Previtera, Antonio Vivace, CoderBot contributors.

GNU GENERAL PUBLIC LICENSE
Version 2, June 1991

Expand Down
34 changes: 14 additions & 20 deletions MPU6050.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import print_function
"""This program handles the communication over I2C
between a Raspberry Pi and a MPU-6050 Gyroscope / Accelerometer combo.
Made by: MrTijn/Tijndagamer
Released under the MIT License
Copyright 2015
"""

import smbus2 as smbus
import time
import smbus2 as smbus

class MPU6050:

Expand Down Expand Up @@ -88,10 +87,9 @@ def read_i2c_word(self, register):

value = (high << 8) + low

if (value >= 0x8000):
if value >= 0x8000:
return -((65535 - value) + 1)
else:
return value
return value

# MPU-6050 Methods

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

def read_accel_range(self, raw = False):
def read_accel_range(self, raw=False):
"""Reads the range the accelerometer is set to.
If raw is True, it will return the raw value from the ACCEL_CONFIG
register
Expand All @@ -141,10 +139,9 @@ def read_accel_range(self, raw = False):
return 8
elif raw_data == self.ACCEL_RANGE_16G:
return 16
else:
return -1
return -1

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

if g is True:
return {'x': x, 'y': y, 'z': z}
elif g is False:
if g is False:
x = x * self.GRAVITIY_MS2
y = y * self.GRAVITIY_MS2
z = z * self.GRAVITIY_MS2
return {'x': x, 'y': y, 'z': z}
return {'x': x, 'y': y, 'z': z}

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

def read_gyro_range(self, raw = False):
def read_gyro_range(self, raw=False):
"""Reads the range the gyroscope is set to.
If raw is True, it will return the raw value from the GYRO_CONFIG
register.
Expand All @@ -214,8 +209,7 @@ def read_gyro_range(self, raw = False):
return 1000
elif raw_data == self.GYRO_RANGE_2000DEG:
return 2000
else:
return -1
return -1

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

def get_all_data(self):
"""Reads and returns all the available data."""
temp = get_temp()
accel = get_accel_data()
gyro = get_gyro_data()
temp = self.get_temp()
accel = self.get_accel_data()
gyro = self.get_gyro_data()

return [accel, gyro, temp]

Expand All @@ -267,4 +261,4 @@ def get_all_data(self):
if abs(gyro_data['z']) > mpu.GYRO_THRESHOLD_Z:
dz = gyro_data['z'] * dt
z = z + dz
print( "z: ", z, end="\r")
print("z: ", z, end="\r")
46 changes: 41 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
CoderBot
========
# backend

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

See the [wiki](https://github.com/CoderBotOrg/coderbot/wiki) for the documentation
### Quickstart

Prerequisites:

```bash
sudo apt install python3 python3-venv
```

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).



```bash
git clone https://github.com/CoderBotOrg/coderbot.git
cd coderbot
python3 -m venv .
source bin/activate

# Install the basic requirements
pip3 install -r requirements_stub.txt
# Additional packages if you are running the real thing
pip3 install -r requirements.txt

# Start the backend in stub mode
PYTHONPATH=stub python3 init.py

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

Once started, the backend will expose a number of endpoints:

- Legacy API: [localhost:5000/`<LEGACY_METHOD>`](http://localhost:5000/);
- Legacy JQuery web application: [localhost:5000/old](http://localhost:5000/old);
- API v2: [localhost:5000/v2](http://localhost:5000/v2);
- 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);
- Documentation: [localhost:5000/docs](http://localhost:5000/docs) assuming a [docs](https://github.com/coderbotorg/docs) build is placed in the `cb_docs/` folder);
- 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).

1 change: 1 addition & 0 deletions _programs.json

Large diffs are not rendered by default.

Loading

0 comments on commit 36b84f9

Please sign in to comment.