-
Notifications
You must be signed in to change notification settings - Fork 19
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
Investigate Impact of supporting WeDo 2.0 #58
Comments
Managed to get this working with my Bluegiga dongle and the new 88012 hubs that came with the Liebherr Excavator, but it was not simple to make work as the Bluegiga acts as a singleton on a serial port and this meant some of the async connection tasks broke... I got around it by making a separate repository and translating to/from the sharpbrick objects, but this will need cleaning up. The TechnicMediumHub ports work for the internals (LED light, etc), but the motors appear to be on different ports, so am probing the HubAttachedIO to try and work out where they are... Anyway, https://github.com/Sodoshi/SharpBrick.PoweredUp.Bluegiga is where I am at... |
@Sodoshi can you open a separate Issue for this. Very interested in how this further evolves. I was confused first but then I realized you talk about Control+ and not WeDo 2.0. The motors however, should work if the internals work. A bit concerned about that. Maybe post a example. The motors self-register at the beginning of the connection. Maybe you loose some characteristics notification at the beginning. I also took a mental note that the Bluetooth Abstraction is now an external contract. At the current early state, I cannot promise that I - or you 😀 - will not break it. |
I've just started using the library with my Mercedes Zetros Truck . I think it has this motor (it's the bottom one): It is reported on the hub as device type 'Motor (id 1)'. Which doesn't seem supported. I would love to help adding support for this motor, I am an experienced c# programmer, but I have no clue what needs to be done here :) |
So this is the "LEGO 6290182 - 21980 - Electric, Motor WeDo 2.0 Medium". But it seems to operate on a Technic Medium Hub. Which is good since the communication partner of this library is the hub not the motor. The first thing you should do, is use the command line to dump the motor self-description. Let us see what that provides. https://github.com/sharpbrick/powered-up/blob/master/docs/development/adding-new-device.md |
I'm afraid for my system the commandline tool hangs on receiving messages (also if I do I'm sure it is on port 2, the others motors I can access.
|
That is ugly. I do not have a device and my knowledge is a bit rusty to read raw traces. Maybe you can try first running the it on the raw Lego Wireless Protocol (that is the Bluetooth Library) and write power on/off into the device. The technic motors have three levels. Try using the raw messages against the WeDo 2.0 motor. That might work. The README has a tutorial.
|
Yeah, the I will give that a try, might take a while to get back to you though. Thx for all the quick responses. |
I just run the tool on I have checked the code with the JavaScript library. They support the WeDo 2.0 motor. However, that library is not as "sophisticated" as this library (I tried to implement the protocol not just make the devices work). That is the reason that library works. Which is good news, because it can work in theory. I also checked there the code ( Once we have evaluated which functions work, we can try to build a device which ignores the discoverability and provides just the methods. Let us create then a new issue (other than this) and run a release (v5.0 hopefully) including it. ps: there was a "typo" above it was |
I tried your suggestions, I think :) With respect to the raw messages, do you mean: 'Connect to Hub and Send a Message and retrieving answers (directly on protocol layer)'. This seems to be a bit outdated, as it doesn't compile (and the examples dir doesn't have a compiling example that does the same). For instance: BluetoothKernel does not have a property BluetoothAddress EDIT the issue below seems to be the same as #190 I adapted it like this, but it fails to connect:
The error is:
I'm pretty sure I know my devices mac adress, I converted it to long using the helper class BlueGigaBLEHelper, double checked it with the Hub.PrimaryMacAddress and it is the same as the hex input there. (note that I use the default WinRt bluetooth).
Also after that I can't use the style |
Yeah seems like the README needs some update. Discovery and DI scope creation works easiest when re-using host logic and host functions. I justed tested this with a using SharpBrick.PoweredUp;
using Microsoft.Extensions.DependencyInjection; // SharpBrick.PoweredUp uses the DI system
using Microsoft.Extensions.Logging;
using SharpBrick.PoweredUp.Bluetooth;
using SharpBrick.PoweredUp.Protocol;
using SharpBrick.PoweredUp.Protocol.Messages; // SharpBrick.PoweredUp also logs stuff
var serviceProvider = new ServiceCollection()
.AddLogging()
.AddPoweredUp()
#if WINDOWS
.AddWinRTBluetooth() // using WinRT Bluetooth on Windows (separate NuGet SharpBrick.PoweredUp.WinRT; others are available)
#endif
.BuildServiceProvider();
// getting utilities
var bt = serviceProvider.GetService<IPoweredUpBluetoothAdapter>();
var host = serviceProvider.GetService<PoweredUpHost>();
// discover a LWP bluetooth device
var tcs = new TaskCompletionSource<ILegoWirelessProtocol>();
bt.Discover(async deviceInfo =>
{
if (!tcs.Task.IsCompleted)
{
var p = host.CreateProtocol(deviceInfo);
tcs.SetResult(p);
}
});
var protocol = await tcs.Task;
// connect the protocol
await protocol.ConnectAsync();
// send a raw message which should work with ANY motor connected to a hub
var response = await protocol.SendPortOutputCommandAsync(new PortOutputCommandStartPowerMessage(
0, // PORT A
PortOutputCommandStartupInformation.ExecuteImmediately, PortOutputCommandCompletionInformation.CommandFeedback,
100
)
{
HubId = 0, // as if we ever see another one
});
await Task.Delay(2000);
await protocol.DisconnectAsync(); with the following csproj <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net8.0-windows10.0.19041.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SharpBrick.PoweredUp\SharpBrick.PoweredUp.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0-windows10.0.19041.0' ">
<ProjectReference Include="..\..\src\SharpBrick.PoweredUp.WinRT\SharpBrick.PoweredUp.WinRT.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
</ItemGroup>
</Project> and the following invocation dotnet run -f net8.0-windows10.0.19041.0 |
I fixed the problem with the manual connection, the address conversion is wrong (at least for the WinRT version). I just used the commandline logged one from I ran your example, it works! I get the following errors (I updated the not supported messages in the Device.GetStaticPortInfoMessages to add some info, I can make a PR if you want it): // Device 'RgbLight' does not support Systemtype 'LegoWeDo20_WeDoHub' on Hardware '1.0.0.0' and Software '1.0.0.0' You also get those? (I also get them if I run without any motors, should be the same as you have). |
Added PR #194 which is needed to support this. The output of discovery now works (for this, not yet for my large lineair motors.
Are you interested in a PR that adds some improved error messages? |
And here is the output from device list:
|
I lost a bit oversight of what you all did. Let me try to summarize
|
Yeah I can image, I'm doing everything at the same time and didn't really know what I am doing lol :)
|
This should not be. Either we discover the device OR use static port inform messages. Do not remember why the behavior is like that. Device enumeration not necessarily need to discover the devices but my just pretty print our existing knowledge. Fix what you find, do PRs. I completely open to it. If you want to do some major rework, discuss it first. |
Ok I'll make a separate ticket for that then, I really think it did both. It was requesting port mode information and got a reply for 5 modes, but actually requested information for 6 modes, which is the amount in the static port info. |
* Created SimpleMediumLinearMotor #58 non-breaking Co-authored-by: Menno Lodder <menno@lodder>
Lesson Learnt from #48
Note: Note to everyone: I do not have the hardware and have in the foreseeable future no interest in purchasing them. If you want support for this hardware in this library, please contribute. I will guide you through the process and assist with everything needed.
The text was updated successfully, but these errors were encountered: