Git Product home page Git Product logo

Comments (4)

tthiery avatar tthiery commented on September 2, 2024 1

Yes, there is a Bluetooth Ping Pong. Problem with the protocol is that hubs have a buffer ... so if you send them commands too fast, they might drop them.

So let me see how I can help you. From your code snippet, I assume you have somewhere input for currentAccelerationValue and currentTurnValue which you synchronize into the motor using that loop.

Depending on your use case I would recommend on of the following:

  • directly dispatch from your UI or handler or whatever the command and await the feedback. Bluetooth should be much faster than your UI input.
  • considering that a loop with Bluetooth may take some ms .... maybe implement a threshold when you start sending commands to it
  • you do not need to await the response of the StartPowerAsync / GotoPositionAsync, you can just let them hang or you can resolve the tasks later. There is a risk that you having commands being dropped by the motor in this case. There is a risk that the dispatching of the commands to the bluetooth stack is out of order because you would also skip the await for the SendMessage and not only for the receiving.
  • if all of the above is not matching your use case, you can consider
    • directly using the ILegoWirelessProtocol as demonstrated in the README. The related motor messages you can see in the implementation of the motor.
    • I am also open for a pull request if you want to implement a "fast-mode" in the StartPowerAsync method.

from powered-up.

LiamDobbelaere avatar LiamDobbelaere commented on September 2, 2024

The detailed feedback is much appreciated, thanks!
I'll give it a shot later and see if I can get it to work faster. It's good to know about the command drops and out-of-order delivery if you send too fast. Maybe a threshold will work just fine.

from powered-up.

LiamDobbelaere avatar LiamDobbelaere commented on September 2, 2024

For whoever comes across this, I ended up solving it using a command pool. Basically, waiting for every command to complete is too slow, but sending them all at once overloads the device's buffer.

public partial class MainWindow : Window {
    List<Task> commandPool = new List<Task>();
    const int maxCommands = 2; // can be tweaked
// ...

private void TimerTick(Object stateInfo) {
// ...
    // trying to send commands every tick
    if (commandPool.Count < maxCommands) {
        commandPool.Add(aMotor.StartPowerAsync((sbyte) -currentAccelerationValue));
    }

    // remove completed commands every tick
    commandPool.RemoveAll(t => t.IsCompleted);
// ...

from powered-up.

tthiery avatar tthiery commented on September 2, 2024

Cool. If you have other questions, just create an issue

from powered-up.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.