-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Vinz1911/develop
Develop
- Loading branch information
Showing
7 changed files
with
366 additions
and
1,432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
# PrimePowerUP | ||
|
||
## Current Examples: | ||
- Spike Prime + Powerup Remote | ||
- 1: basic remote example for testing ble connection | ||
- 2: example about lighting up dot's on spike prime on button press on remote | ||
- 3: example to control the `advanced driving base` model from LEGO(R) with the PowerUP(TM) Remote | ||
|
||
- **NOTE: If you're using the official LEGO Spike APP to upload the code, you should just upload it and don't run it with attached console, this can be ended up in a frozen Spike Prime** | ||
- **NOTE: There is currently one problem: the ble code consumes lot of ressources from the spike prime, so it's necessary to restart the prime after a code execution because of mem alloc (bug)?** | ||
`PrimePoweredUP` contains a library for Lego Spike Prime to connect to PoweredUP Remote (Handset) over BLE. | ||
The core is based on the MicroPython ubluetooth low level api. | ||
|
||
### Description | ||
- the library use lot of memory. i recommend to pre compile the library from `remote/control` and install it on the prime hub. | ||
a very good way to do that is using this awesome tool: [Spike Tools](https://github.com/XenseEducation/spiketools-release/releases) | ||
pre compiled library can also be downloaded in releases section: [Pre-Compiled Library](https://github.com/Vinz1911/PrimePowerUP/releases) | ||
|
||
- there are two examples in `examples` folder. The first one shows how to light up dot's on Prime Hub and the second one | ||
shows how to control a motor pair with the remote. examples are created by using the control.py installed as pre compiled lib | ||
(it's also possible to copy all together and load it on the hub) | ||
|
||
### Known Problems: | ||
- the ubluetooth class has some problems with event loop based functions from Lego. This means, if you run a event loop based | ||
function within the button pressed callback, the entire hub will freeze. This is currently not possible to fix that, maybe with | ||
a new firmare which supports uasyncio library. **Event based functions ?!** are functions like playing sound until end, wait for or | ||
motor functions like run_to_position or run_for_degrees and so on. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from spike import PrimeHub, LightMatrix, Button, StatusLight, ForceSensor, MotionSensor, Speaker, ColorSensor, App, DistanceSensor, Motor, MotorPair | ||
from spike.control import wait_for_seconds, wait_until, Timer | ||
from remote.control import PoweredUPRemote, PoweredUPColors, PoweredUPButtons | ||
|
||
""" | ||
LEGO(R) SPIKE PRIME + POWERED UP | ||
-------------------------------- | ||
This is a basic example: | ||
This example let control a motor pair | ||
with the powered up remote | ||
""" | ||
|
||
|
||
def on_connect(): | ||
""" | ||
callback on connect | ||
""" | ||
hub.status_light.on("blue") | ||
|
||
|
||
def on_disconnect(): | ||
""" | ||
callback on disconnect | ||
""" | ||
hub.status_light.on("white") | ||
motor_pair.stop() | ||
|
||
|
||
def on_button(button): | ||
""" | ||
callback on button press | ||
:param button: button id | ||
""" | ||
if button == PoweredUPButtons.RIGHT_PLUS: | ||
motor_pair.start(speed=75) | ||
elif button == PoweredUPButtons.RIGHT_MINUS: | ||
motor_pair.start(speed=-75) | ||
elif button == PoweredUPButtons.LEFT_PLUS_RIGHT_PLUS: | ||
motor_pair.start(steering=-45, speed=75) | ||
elif button == PoweredUPButtons.LEFT_MINUS_RIGHT_PLUS: | ||
motor_pair.start(steering=45, speed=75) | ||
elif button == PoweredUPButtons.LEFT_MINUS_RIGHT_MINUS: | ||
motor_pair.start(steering=45, speed=-75) | ||
elif button == PoweredUPButtons.LEFT_PLUS_RIGHT_MINUS: | ||
motor_pair.start(steering=-45, speed=-75) | ||
elif button == PoweredUPButtons.RELEASED: | ||
motor_pair.stop() | ||
else: | ||
motor_pair.stop() | ||
|
||
|
||
# set up hub | ||
hub = PrimeHub() | ||
|
||
# set up motors | ||
motor_pair = MotorPair('A', 'B') | ||
motor_pair.set_stop_action('coast') | ||
|
||
# create remote and connect | ||
remote = PoweredUPRemote() | ||
remote.on_connect(callback=on_connect) | ||
remote.on_disconnect(callback=on_disconnect) | ||
remote.on_button(callback=on_button) | ||
remote.connect() |
Oops, something went wrong.