Comments (4)
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 theStartPowerAsync
/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.
- directly using the
from powered-up.
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.
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.
Cool. If you have other questions, just create an issue
from powered-up.
Related Issues (20)
- Remove device from the Windows List of known devices!!!! HOT 4
- Update Mario
- Adjust Modes to use scale-safe data type
- Improve Linux Buildability
- Internalize WinRT dependency & re-release CLI as a net6.0 only HOT 1
- Update to .NET 6 / C# 10
- Embed README.md in NuGet
- Add Support for LEGO Education SPIKE Essential Devices
- Linux install failed: nuget reports signature expiration and self-signed certificate HOT 3
- "System.NullReferenceException: Object reference not set to an instance of an object." during "Discover Ports. Receiving Messages ..." when using CLI HOT 4
- System.ObjectDisposedException: The object has been closed. after a few seconds HOT 11
- Controlling two hubs not working (Lego 42100) HOT 6
- Update to .NET 8 / C# 12
- poweredup device list hangs HOT 4
- Device discovery still uses static port information HOT 3
- Code Quality v5.0
- Investigate Impact of supporting WeDo 2.0 (HUB)
- How turn on lights on ColorDistanceSensor ? HOT 12
- Code Quality v6.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powered-up.