Skip to content

Commit b6c4694

Browse files
committed
Merge remote-tracking branch 'origin/main' into old_branch
2 parents e43cf09 + 325fdff commit b6c4694

File tree

16 files changed

+849
-149
lines changed

16 files changed

+849
-149
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Upload Python Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
deploy:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.x'
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install setuptools wheel twine
25+
- name: Build and publish
26+
env:
27+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
28+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29+
run: |
30+
python setup.py sdist bdist_wheel
31+
twine upload dist/*

.github/workflows/python-test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
test:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: [3.7, 3.8, 3.9]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install flake8 pytest
30+
python -m pip install -e .
31+
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32+
- name: Lint with flake8
33+
run: |
34+
# stop the build if there are Python syntax errors or undefined names
35+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38+
# - name: Test with pytest
39+
# run: |
40+
# pytest

LICENSE.txt

Lines changed: 363 additions & 0 deletions
Large diffs are not rendered by default.

demos/bluedot/led_only.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from bluedot import BlueDot
2+
from signal import pause
3+
import usb_arm
4+
5+
arm = usb_arm.Arm()
6+
7+
8+
def led_pressed(pos):
9+
arm.tell(usb_arm.LedOn)
10+
11+
12+
def stop(*args):
13+
arm.tell(usb_arm.Stop)
14+
15+
16+
bd = BlueDot(cols=3, rows=2)
17+
led = bd[1, 0]
18+
19+
bd.when_released = stop
20+
led.when_pressed = led_pressed
21+
bd.when_client_disconnects = stop
22+
pause()

demos/bluedot/simple_grid.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from bluedot import BlueDot
2+
from signal import pause
3+
import usb_arm
4+
5+
arm = usb_arm.Arm()
6+
7+
8+
def led_pressed(pos):
9+
arm.tell(usb_arm.LedOn)
10+
11+
12+
def stop(*args):
13+
arm.tell(usb_arm.Stop)
14+
15+
16+
def grip_pressed(pos):
17+
if pos.top:
18+
arm.tell(usb_arm.GripsClose)
19+
if pos.bottom:
20+
arm.tell(usb_arm.GripsOpen)
21+
22+
23+
def wrist_pressed(pos):
24+
if pos.top:
25+
arm.tell(usb_arm.WristUp)
26+
if pos.bottom:
27+
arm.tell(usb_arm.WristDown)
28+
29+
30+
def elbow_pressed(pos):
31+
if pos.top:
32+
arm.tell(usb_arm.ElbowUp)
33+
if pos.bottom:
34+
arm.tell(usb_arm.ElbowDown)
35+
36+
37+
def shoulder_pressed(pos):
38+
if pos.top:
39+
arm.tell(usb_arm.ShoulderUp)
40+
if pos.bottom:
41+
arm.tell(usb_arm.ShoulderDown)
42+
43+
44+
def base_pressed(pos):
45+
if pos.left:
46+
arm.tell(usb_arm.BaseCtrClockWise)
47+
if pos.right:
48+
arm.tell(usb_arm.BaseClockWise)
49+
50+
51+
bd = BlueDot(cols=3, rows=2)
52+
led = bd[1, 0]
53+
54+
bd.when_released = stop
55+
led.when_pressed = led_pressed
56+
bd.when_client_disconnects = stop
57+
pause()

demos/key_ctrl.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""key_ctrl - key based arm controller"""
2+
from functools import partial
3+
import usb_arm
4+
import pygame
5+
from pygame.locals import *
6+
import sys
7+
8+
9+
def handle_key(arm, delay, key_map, key):
10+
def do_it():
11+
if key in key_map:
12+
print("Doing key ", key)
13+
arm.move(key_map[key], delay)
14+
arm.safe_tell(do_it)
15+
16+
17+
def make_keymap():
18+
"""Bp - an initialised arm bitpattern.
19+
returns the keymap"""
20+
return {
21+
K_z: usb_arm.BaseClockWise,
22+
K_x: usb_arm.BaseCtrClockWise,
23+
K_r: usb_arm.CloseGrips,
24+
K_f: usb_arm.OpenGrips,
25+
K_a: usb_arm.ShoulderDown,
26+
K_q: usb_arm.ShoulderUp,
27+
K_s: usb_arm.ElbowDown,
28+
K_w: usb_arm.ElbowUp,
29+
K_d: usb_arm.WristDown,
30+
K_e: usb_arm.WristUp}
31+
32+
33+
def key_loop():
34+
km = make_keymap()
35+
try:
36+
arm = usb_arm.Arm()
37+
except AttributeError:
38+
print("Please make sure the arm is connected and turned on")
39+
sys.exit(1)
40+
handle = partial(handle_key, arm, 0.5, km)
41+
exit_key = K_ESCAPE
42+
43+
while True:
44+
for event in pygame.event.get():
45+
if event.type == QUIT:
46+
pygame.quit()
47+
return
48+
if event.type == KEYDOWN:
49+
if event.key == exit_key:
50+
return
51+
else:
52+
handle(event.key)
53+
54+
55+
def main():
56+
pygame.init()
57+
key_loop()
58+
59+
60+
main()

demos/web_arm/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Web Control USB Arm Demo
2+
3+
This demonstration code shows how to use this library with the Maplin/OWI edge USB robot arm to control it over the web via a browser.
4+
5+
Install flask (with pip3 install flask) and follow along with the video at <https://youtu.be/wqt1u-WdOxY>.

demos/web_arm/arm_hello.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import usb_arm
2+
from flask import Flask, Response
3+
4+
5+
arm = usb_arm.Arm()
6+
app = Flask(__name__)
7+
8+
9+
@app.route('/')
10+
def flash():
11+
def inner():
12+
yield "starting</br>\n"
13+
arm.move(usb_arm.LedOn)
14+
yield "completed\n"
15+
return Response(inner())
16+
17+
18+
app.run(host="0.0.0.0")

demos/web_arm/arm_server.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import usb_arm
2+
from flask import Flask, Response, request
3+
4+
5+
arm = usb_arm.Arm()
6+
app = Flask(__name__)
7+
8+
movemap = {
9+
"GripsClose": usb_arm.GripsClose,
10+
"CloseGrips": usb_arm.CloseGrips,
11+
"GripsOpen": usb_arm.GripsOpen,
12+
"OpenGrips": usb_arm.OpenGrips,
13+
"Stop": usb_arm.Stop,
14+
"WristUp": usb_arm.WristUp,
15+
"WristDown": usb_arm.WristDown,
16+
"ElbowUp": usb_arm.ElbowUp,
17+
"ElbowDown": usb_arm.ElbowDown,
18+
"ShoulderUp": usb_arm.ShoulderUp,
19+
"ShoulderDown": usb_arm.ShoulderDown,
20+
"BaseClockWise": usb_arm.BaseClockWise,
21+
"BaseCtrClockWise": usb_arm.BaseCtrClockWise,
22+
"LedOn": usb_arm.LedOn
23+
}
24+
25+
26+
@app.route('/move', methods=['POST'])
27+
def move():
28+
pattern = movemap[request.form['pattern']]
29+
30+
def inner():
31+
yield "starting<br>\n"
32+
arm.move(pattern)
33+
yield "completed\n"
34+
return Response(inner())
35+
36+
37+
app.run(host="0.0.0.0")

demos/web_arm/arm_server2.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import usb_arm
2+
from flask import Flask, Response, request, render_template
3+
4+
5+
arm = usb_arm.Arm()
6+
app = Flask(__name__)
7+
8+
movemap = {
9+
"GripsClose": usb_arm.GripsClose,
10+
"CloseGrips": usb_arm.CloseGrips,
11+
"GripsOpen": usb_arm.GripsOpen,
12+
"OpenGrips": usb_arm.OpenGrips,
13+
"Stop": usb_arm.Stop,
14+
"WristUp": usb_arm.WristUp,
15+
"WristDown": usb_arm.WristDown,
16+
"ElbowUp": usb_arm.ElbowUp,
17+
"ElbowDown": usb_arm.ElbowDown,
18+
"ShoulderUp": usb_arm.ShoulderUp,
19+
"ShoulderDown": usb_arm.ShoulderDown,
20+
"BaseClockWise": usb_arm.BaseClockWise,
21+
"BaseCtrClockWise": usb_arm.BaseCtrClockWise,
22+
"LedOn": usb_arm.LedOn
23+
}
24+
25+
26+
@app.route('/')
27+
def index():
28+
return render_template('index.html', patterns=movemap)
29+
30+
31+
@app.route('/move', methods=['POST'])
32+
def move():
33+
pattern = movemap[request.form['pattern']]
34+
35+
def inner():
36+
yield "starting<br>\n"
37+
arm.move(pattern)
38+
yield "completed\n"
39+
return Response(inner())
40+
41+
42+
app.run(host="0.0.0.0")

0 commit comments

Comments
 (0)