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] Hub state encoding #1859

Open
laurensvalk opened this issue Oct 1, 2024 · 1 comment
Open

[Feature] Hub state encoding #1859

laurensvalk opened this issue Oct 1, 2024 · 1 comment
Labels
enhancement New feature or request software: pybricks-code Issues with https://code.pybricks.com application software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)

Comments

@laurensvalk
Copy link
Member

laurensvalk commented Oct 1, 2024

We could look into using the negotiated MTU on the firmware side so we can send whole messages in one go.

I was initially thinking we could send pre-formatted strings, in order to limit the device specific stuff we need to add to Pybricks Code. But if make device specific visualizations anyway, we can look at packing a single port value into a 19 byte message, which should be feasible.

Originally posted by @laurensvalk in pybricks/pybricks-code#2315 (comment)

These implementation details are probably worth discussing here in a separate issue. Pre-formatted strings sounded nice at first, but we'll also be applying device-specific visuals such as the motor angle or detected color. So if we're going to unpack and parse the strings in Pybricks Code anyway, we should probably come up with a protocol after all. Then it can be packet-based too, avoiding streaming issues.

As with any protocol, this means we'd need something properly versioned, so Pybricks Code knows how to display it. Maybe it needs to be part of the existing hub protocol version.


Information we need to send for each port:

  • Device ID

Motors:

  • Data: Angle in degrees (LE int32_t), speed in deg/s.
  • Visual: Motor angle on shaft, and total degree value (no need for separate modulo degrees and rotation count). Maybe speed on a vertical slider? The numbers change too fast to read them.
  • Commands:
    • Reset angle, by clicking on the motor?
    • track angle (future)

Ultrasonic sensor:

  • Data: distance in mm.
  • Commands:
    • Set threshold. Perhaps with a field and slider. And then we can visually turn the lights on if closer than threshold. This lets you instantly explore the usefulness of the sensor. Default to 200 mm?

Color Sensor:

  • Data (reflect mode): HSV, intensity
  • Data (ambient mode): HSV, intensity
  • Commands:
    • Set mode, by clicking on the lights?
    • Set detectable colors (future)

Note: I'm thinking we should perhaps not show the rounded color like Color.RED. Because this creates the impression that only the default colors are possible. It would be great to do something interactive with the detectable colors, but that is perhaps for a future version. Maybe just show the HSV as-is for now?


And so on. In essence, what we have already done in the port script, but we'd need to formalize it. Perhaps something like:

PORT_ID | TYPE_ID | DEVICE_SPECIFIC_VALUES

It is the same for internal things like the gyro, but with a special ID representing itself, and an identifier for the internal device.


And for the reverse, setting data:

PORT_ID | COMMAND_ID | PAYLOAD

This is primarily for setting the mode. And for setting the motor position (more on that later).


(At this point, should we just implement it in C, or go for the whole LWP3 protocol? 😄 Nah, probably not.)

@laurensvalk
Copy link
Member Author

See also #1958 for implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request software: pybricks-code Issues with https://code.pybricks.com application software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)
Projects
None yet
Development

No branches or pull requests

1 participant