Skip to content
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

[Feature, Bug] Remote close method. #802

Closed
laurensvalk opened this issue Nov 14, 2022 · 4 comments
Closed

[Feature, Bug] Remote close method. #802

laurensvalk opened this issue Nov 14, 2022 · 4 comments
Labels
bug Something isn't working enhancement New feature or request software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: bluetooth Issues involving bluetooth

Comments

@laurensvalk
Copy link
Member

laurensvalk commented Nov 14, 2022

Is your feature request related to a problem? Please describe.
This was proposed in pybricks/pybricks-micropython@a2b2e44 but never merged, so I had a look at how well it works.

Describe the solution you'd like
With close() included, you can quite easily make programs that allow the remote to hop between hubs.

For example, take a Prime Hub and a Technic Hub, each with a motor on Port A.

They both run this program, modified on the lines indicated with <----

from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Remote, Motor
from pybricks.parameters import Button, Color, Port
from pybricks.tools import wait

# Replace this with your hub. <----
hub = PrimeHub()

# Replace this with a unique color <----
pair_color = Color.GREEN

# Initialize a motor.
motor = Motor(Port.A)

while True:

    # Blink to indicate we want to connect.
    hub.light.blink(pair_color, (200, 200))

    # Try to connect, and retry on timeout.
    remote = Remote(timeout=None)

    # Light solid to indicate we are connected.
    remote.light.on(pair_color)
    hub.light.on(pair_color)

    while True:

        # Wait until a button is pressed.
        pressed = remote.buttons.pressed()

        if Button.CENTER in pressed:
            break
        elif pressed:
            motor.dc(50)
        else:
            motor.stop()
        
        # Wait some time.
        wait(10)

    # Disconnect.
    hub.light.on(Color.YELLOW)
    motor.stop()
    remote.close()

    # Give other hub a chance to connect.
    wait(2000)

Expected behavior:

VID_20221114_160958.mp4

problem

This uncovers a few interesting Bluetooth problems that may help us identify underlying bluetooth bugs seen elsewhere.

This only works well if the Prime Hub is connected to Pybricks Code. This was new to me.

When not connected, we get all sorts of strange conditions happening. Usually it will not jump to the Prime Hub, or the Prime Hub freezes.

So my vote is not to merge this for 3.2 but include it in the next big Bluetooth release (3.3 or 3.4).

@laurensvalk laurensvalk added enhancement New feature or request triage Issues that have not been triaged yet bug Something isn't working topic: bluetooth Issues involving bluetooth and removed triage Issues that have not been triaged yet labels Nov 14, 2022
@BertLindeman
Copy link

Laurens,

would using ThisHub make this program easier to be used on different hubs?

Or is ThisHub not to be promoted?

(You lack "<----" on the PrimeHub import above)

@laurensvalk
Copy link
Member Author

We're not advocating for it due to the difficulties we have seen in ev3dev. One class to fit all sounds good, but often leads to confusion over time as functionality diverges.

It also gives problems with autocomplete, since it wouldn't know which hub it is.

@dlech dlech added the software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) label Nov 26, 2022
@BertLindeman
Copy link

While thinking about discussions entry #975

Is your feature request related to a problem? Please describe.
This was proposed in pybricks/pybricks-micropython@a2b2e44 but never merged, so I had a look at how well it works.

Have been looking through "Actions" in github.com/pybricks/pybricks-micropython/actions
And found pybricks.pupdevices.Remote: add close() method #1221

Is that the firmware you refer to, Laurens?
That firmware is expired, so cannot download now.
But as it happens I DID download that firmware from 2021-08-18.
But of course that firmware is now incompatible with code.pybricks.com
Looks like a dead end for me at the moment.

@laurensvalk
Copy link
Member Author

This was also requested in https://github.com/orgs/pybricks/discussions/1445

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: bluetooth Issues involving bluetooth
Projects
None yet
Development

No branches or pull requests

3 participants