imurvai / brickcontroller2

Cross platform application for controlling Lego creations using a bluetooth gamepad.
104 stars 28 forks source link

Support for Mould King Hub #91

Open ernprivado opened 1 year ago

ernprivado commented 1 year ago

Hi I notice that there is no support for mould king hub. I was just wondering if there is a plan for it

imurvai commented 1 year ago

Hi, unfortunately I don't have any mould king device, so I can't add support for it. But the repo is open, so if someone implements it I'll release a new version :)

J0EK3R commented 9 months ago

Hello :)

I just sniffed some BT LE telegrams sent by the Mould King App with the free Android App "nRF Connect".

It seems that the App from Mould King (and the others from China) simply send Advertisement telegrams to their Hub-Bricks...

You don't need to have any Hardware to sniff the telegrams - just install the App und start sniffing...

Do you think it would be possible to integrate a BT-Device in your App that sends predefined Advertisement telegrams? The difference to the current implemented devices is that this device could not be scanned. You have to add it manually...

This BT device don't need any GATT functionality.

How and where would you start implementing such a device in your Code?

I'm able to compile your projects to a running APK with VS Community Edition.

J0EK3R commented 9 months ago

Screenshot_2023-09-18-17-14-32-943_no nordicsemi android mcp

J0EK3R commented 9 months ago

I've forked your repo and added a new branch "BluetoothLEAdvertisingDevice".

https://github.com/J0EK3R/brickcontroller2/tree/BluetoothLEAdvertisingDevice

There is a new base class "BluetoothAdvertisingDevice" for "chinese" devices wich are controlled over one-way Bluetooth Advertising Messages.

I've implemented two devices:

Till now - for proof-of-concept - if you start a scan in the app bouth devices were inserted. Then you can handle them like the others and bind channels.

Screenshot_2023-09-30-06-28-41-055_com scn BrickController2

regystro commented 5 months ago

That's awesome!!

I'd like to try it with my Mould King Robot. Would it be possible to merge this into a new version of the app?

arthurson commented 3 months ago

I've forked your repo and added a new branch "BluetoothLEAdvertisingDevice".

https://github.com/J0EK3R/brickcontroller2/tree/BluetoothLEAdvertisingDevice

There is a new base class "BluetoothAdvertisingDevice" for "chinese" devices wich are controlled over one-way Bluetooth Advertising Messages.

I've implemented two devices:

Till now - for proof-of-concept - if you start a scan in the app bouth devices were inserted. Then you can handle them like the others and bind channels.

Screenshot_2023-09-30-06-28-41-055_com scn BrickController2

can you give us app so we can try

J0EK3R commented 3 months ago

Here ist the try: Sorry, Android only: Release J0EK3R3.3

arthurson commented 3 months ago

Here ist the try: Sorry, Android only: Release J0EK3R3.3

just tried, always show Bluetooth devices will not be available, i can connect my radio through Bluetooth, but i cant connect mk4.0, the apps shows tons of options btw, i tried all without luck

20240403_135724

arthurson commented 3 months ago

i can only use old black moukking 2.2 to connect mk4.0 at the moment https://youtu.be/I4xvohZ80MI?si=piuzx8aMSXQ7fo4S

regystro commented 3 months ago

Here ist the try: Sorry, Android only: Release J0EK3R3.3

I just tested MouldKing 6.0 Module and seems to work pretty well. Also connecting same hub as MoludKing Mecanum Module, it works as expected.

J0EK3R commented 3 months ago

Here ist the try: Sorry, Android only: Release J0EK3R3.3

just tried, always show Bluetooth devices will not be available, i can connect my radio through Bluetooth, but i cant connect mk4.0, the apps shows tons of options btw, i tried all without luck

20240403_135724

Did you give all Bluetooth rights to the app?

J0EK3R commented 3 months ago

Here ist the try: Sorry, Android only: Release J0EK3R3.3

I just tested MouldKing 6.0 Module and seems to work pretty well. Also connecting same hub as MoludKing Mecanum Module, it works as expected.

Yes, I "developed" the MK stuff with MK6.0 and with the MK Mecanum Model. I don't know if another MK - like the MK4.0 - would Work Out of the Box.

arthurson commented 3 months ago

Here ist the try: Sorry, Android only: Release J0EK3R3.3

just tried, always show Bluetooth devices will not be available, i can connect my radio through Bluetooth, but i cant connect mk4.0, the apps shows tons of options btw, i tried all without luck 20240403_135724

Did you give all Bluetooth rights to the app?

i installed to 3 android, different results all dont ask bt rights but location and storage rights only, like original app

on android 10, it shows few options, no pf1-pf4, it says connected but no response on hardware when choosing mk stuff

on older tablet samsung tab s based on android 6, it has pf1-pf4, and it says failed to connect

tried samsung a71 based on android 13, it dont have bt warning, but still the app cant connect to mk4.0

J0EK3R commented 3 months ago

pf1-pf4 is the infrared part - that plays no role with bluetooth. When starting the app for the First time I grant every rights and it works...

arthurson commented 3 months ago

pf1-pf4 is the infrared part - that plays no role with bluetooth. When starting the app for the First time I grant every rights and it works...

maybe mk4.0 and mk6.0 has different setting. like when i chose mk6.0 to connect mk4.0 battery on old black mk app , it wont works as well.

it seems you are the only person who knows how to make mk stuff work on this app at the moment, will you implement mk4.0 as well? like 13107 and 17036, these products use 2 batteries to handle 8ch at the same time, if we can use better radio to play with it, it will be a big surprise to mk users

J0EK3R commented 3 months ago

...if I find some time - and that's the problem ;) - I will try to add support for MK4.0. I just ordered the MK4.0 from the China man. Stay tuned on this channel! :)

J0EK3R commented 3 months ago

But the next problem would be how to differ between the two Bluetooth-Receiver-Bricks, hmmm...

J0EK3R commented 2 months ago

Here ist another try 3.3_J0EK3R_Beta_3.

I tryed (without having such devices) to implement (3 devices of) MK4.0 and (3 devices of) MK6.0.

MK6.0: To bind MK6.0-Device 1 to DeviceA in the app just go to the device-page, select MK 6.0 - Device A and press the button on the MK6.0 brick. Test the channels. Same for the second and third MK6.0.

MK4.0: There is just one device for the MK4.0 in the app - but with 12 channels. The first 4 channels are for device 1, the second 4 channels for device 2 and the third 4 channels for device 3. I don't know how to bind the devices? - Are the MK4.0-bricks hard-coded to device 1, 2 and 3?

arthurson commented 2 months ago

just quick tested, now the app can connect 2 mk4.0, 8ch works at this test page Screenshot_20240408_205358_com scn BrickController2

yet i can't select the ch on this page so my rc controller can't test, normally i should choose the ch i want. Screenshot_20240408_205140_com scn BrickController2

Screenshot_20240408_203835_com scn BrickController2

J0EK3R commented 2 months ago

Puuuuh - weird ;) I take a look....

J0EK3R commented 2 months ago

Next try: 3.3_J0EK3R_Beta_4

arthurson commented 2 months ago

Screenshot_20240409_014602_com scn BrickController2 now ui shows 1-12, 1 is red, but actually i cant control ch1 by my rc radio, and i cant choose other ch to test

https://youtu.be/ldqnyEwmIbw?si=QiOsmM0qLiBoIKvI

J0EK3R commented 2 months ago

Nice video :) Tomorrow I will look for the UI problem... On my mobile or my tablet I have more pixels.

All the channels of the two MK4.0 are working, right?

arthurson commented 2 months ago

Nice video :) Tomorrow I will look for the UI problem... On my mobile or my tablet I have more pixels.

All the channels of the two MK4.0 are working, right?

yes, the app will connect 2 batteries at the same time after presing scanning, both are ch1-4, pressing hard button once on battery will switch to 5-8, just like mkapp

J0EK3R commented 2 months ago

Next day, next try ;) 3.3_J0EK3R_Beta_5

J0EK3R commented 2 months ago

Now with Button "Delete All Devices" 3.3_J0EK3R_Beta_6

arthurson commented 2 months ago

now i can select the ch, but my rc radio cant control it, no matter i use bt or usb cable

every beta make a good step progress

https://youtu.be/1XeEG6RoC70?si=1HmMjP979_CX7u9s

J0EK3R commented 2 months ago

After binding a controller action to a channel you have to press the OK-button on right top to save that. Then - after binding all controller actions to channels - you have to RUN your Controller-Profil or Creation by pressing the Play-Button on right top.

arthurson commented 2 months ago

yes, you are right, previously i didn't see tick on right size Screenshot_20240409_173947 now i can use rc radio to control mk4.0, thx lots there are some bugs here, but at least it proves working, i will make a video after finishing my settings

J0EK3R commented 2 months ago

I think there ist a Bug with the negative direction in the MK4.0 Module: If you pull the Slider to the left - negative direction - the connected motor starts with full Speed and decreases speed when the Slider moves more left. Do you have the Same behavior?

arthurson commented 2 months ago

I think there ist a Bug with the negative direction in the MK4.0 Module: If you pull the Slider to the left - negative direction - the connected motor starts with full Speed and decreases speed when the Slider moves more left. Do you have the Same behavior?

yes, the curve is nonlinear. if you set ch from -100 to100, one direction will not be activated, like -70 to 70 will be ok for both sides

J0EK3R commented 2 months ago

Now it's fixed: 3.3_J0EK3R_Beta_7

J0EK3R commented 2 months ago

Now with fotos for MK4.0, MK6.0, Mecanum 3.3_J0EK3R_Beta_8

arthurson commented 2 months ago

beta8 tested, it seems you reduce the output to 70% so gimbal can control both direction.

my toy 17036 backhoe use clutch to change gear, i tested it for long run, the motor brunt after 10 mins, the design of that part is not relible. now i need to find a replacement.

i found even the ble joystick has 16ch signal, only 8 ch are proportional, throttle is 0-1, that is no enough in my case. it use 10ch to fullfil all the actin. need some time to change settings

also i ddnt test the setting the app given, i use my radio to set, like dead point, end point and cruve etc.

arthurson commented 2 months ago

https://youtu.be/kk-63aSYCuA?si=gamkOwaD_-rchZM8

now the backhoe can run as it should be, except i need to change the gear manually as motor broken yesterday, it really prove that we should have a good controller for the better handling.

thx now i am satisfied

J0EK3R commented 2 months ago

https://youtu.be/kk-63aSYCuA?si=gamkOwaD_-rchZM8

now the backhoe can run as it should be, except i need to change the gear manually as motor broken yesterday, it really prove that we should have a good controller for the better handling.

thx now i am satisfied

Great! And thanks for the nice video!

But let's have a look at you problem with the broken motor - does the problem still exist?

I tested with a MK4.0 and a "normal motor".

What I'm doing: The BT-Telegram for MK4.0 has 12 channels - 4 channels for each of the 3 supported MK4.0 bricks.

Each channel has 4 Bits - that's a nibble. 2 channels are mapped in 1 byte (high-nibble and low nibble) - so there are 6 bytes channel-data in the telegram.

A nibble can have the values from 0x0 to 0xF - that are 16 different values (for different speeds). A value of 0x8 is sent as "Off", a value of 0x7 means full speed negative, a value of 0xF means full speed positive.

The Brickcontroller-App sends me values from -1 over 0 to +1 and all the comma-values between for a channel for full speed negative, zero speed and full speed positive.

Can you try to explain your problem? And please send me a link or give me a number of broken motor...

arthurson commented 2 months ago

it is purely a moc design default, mouldking dont use clutch wheel to protect the motor, it makes the motor overheat when it keeps on pushing one direction, motor died as result.

if you wanna know how they design the gear , find the 17036 manual, b1 motor is for changing gear.

it is well-known that mould king always steal moc without any credit, their excavator crane backhoe are no exception. this complicated product actually come from this designer.

https://www.moc-builder.com/jcb-backhoe/

i will teardown this L motor for repairing tomorrow.

J0EK3R commented 2 months ago

And is the problem with the MK4.0 implementation fixed with the Beta 8?

arthurson commented 2 months ago

ive posted this beta on fb group, hoping more people to test it, here is the link https://m.facebook.com/groups/mouldkingfans/permalink/1136277217565127/?mibextid=Nif5oz

arthurson commented 2 months ago

to repair the motor ive already teardowned my car, no further test can be done at the moment, for me beta8 is quite successful, just wait other people to find bugs

J0EK3R commented 2 months ago

I did some beautifying and little fixes. Here is another try:

3.3 J0EK3R Beta 9

elclaudio commented 1 month ago

I would love official support for mould king hub (especially the 6.0 which has 6 ports !) I have a few of them,all is ok but now I see that for serious stuff, I need programability with sensors (simple switchs at first would be enough).

For this, I was thinking about using a cheap raspberry pi pico W to manage the sensors via gpio (switch only) or better via I2C (TCS34725 RGB Color Sensor, TOF10120 distance sensor, MCP23008 or MCP23017 for input switch...) the pico then receive the input from the sensor and send the propers orders through bluetooth to drive the PF motors, servos, light etc via the mould king hub. The python program would drive the motors accordingly.

All we need is already here (the mould king protocol), but we need a library in python to drive the mould king hub. Could this be done ? may be @J0EK3R could help ? this would be fantastic because Lego spike hub and sensors are insanely pricey and to big

@J0EK3R Is it possible to isolate the mould king part of the app to make such a library ?

J0EK3R commented 1 month ago

Hi @elclaudio, your project sounds very interesting and i think it would be possible...

The "mould king part" is already separated - look at

Sadly the code isn't very cleaned up and optimized but with some comments and self speaking... ;)

I don't know if your platform supports that kind of advertising telegrams. Android works very well, i.e. Windows doesn't - till now, I wasn't able to send the needed bluetooth advertising telegrams on Windows because of windows limitations. I haven't tested other platforms yet like IOS or Linux.

elclaudio commented 1 month ago

@J0EK3R thanks you for your prompt response. Yeah, the problem right now is that there is no "HAT" for raspi or other SBC to drive PF motors (only exists the build HAT to drive new lego powered up motors and even then there is only 4 ports, non stackable which is clearly not enough. The advantage here with mould king is that you can drive at least 3 hub with 6 PF ports per hub = 18 motors ! + possibility of stacking) While looking at the code, I've found theses files indeed. But I'm not familiar with coding, I've done a little bit of C# but not enough to start something like this, at least not without serious help. The plateform to be used is not written in stone, we can use whatever works best. I've talked about the pico because it cost nothing, have many gpio and i2c, uart etc and power consumption is lower than a regular pi with linux. Sadly, I've 2 pico right now but without bluetooth... I could buy one to test naturally. OR, I could try using a raspberry pi zero W which have bluetooth and running linux. So basically, first, we need some very basic code (either python, C whatever) to connect to the mould king hub and eventually send motor ON / OFF commands to test feasibility. Compatibility with windows is not required since the plan is to run it on either a micro controller (pico) or very light hardware like pi zero W

edit: even without code, may be we can try to send the proper telegrams (connect, motor on/off) under linux shell to test if hardware is capable, I could try with my raspi zero W ?

J0EK3R commented 1 month ago

Hello @elclaudio, I'm very sorry but I have no experiance in python yet - but the main problem is: I have no time for such a project. If somebody was porting the code to a python lib I could perhaps help if there were problems but... sorry, I have no time at the moment... :|

elclaudio commented 1 month ago

Hello @elclaudio, I'm very sorry but I have no experiance in python yet - but the main problem is: I have no time for such a project. If somebody was porting the code to a python lib I could perhaps help if there were problems but... sorry, I have no time at the moment... :|

I understand. But may be can you just help me with sending the command under linux shell. I tried with nrf connect, cloning some commands, it works but I haven't managed to make it work with linux commands :

for exemple, the telegram to connect: bluetoothctl advertise menu manufacturer 0xFF00 0x6D 0xB6 0x43 0xCF 0x7E 0x8F 0x47 0x11 0x88 0x16 0x7B 0x38 0xD1 0x7A 0xAA 0x26 0x33 0xC2 back advertise on

the telegram is send, but the led's status doesn't change on the hub. If I replay the very same telegram (send by the raspi) on nrf connect in android, it connect successfully. Tried 2 other pc on linux (x86-64 and arm), but it never connect. then what, is there a limitation on linux ?

or with hcitool : sudo hcitool -i hci0 cmd 0xFF00 0x6D 0xB6 0x43 0xCF 0x7E 0x8F 0x47 0x11 0x88 0x16 0x7B 0x38 0xD1 0x7A 0xAA 0x26 0x33 0xC2 I don't understand the usage and meaning of ogf, ocf cmd [parameters]

I miss something... but I believe I'm close. If we can send such commands directly to drive the motor (working with nrf connect) a simple shell script could do the job

J0EK3R commented 1 month ago

Hi @elclaudio :) I'm absolutely no BT-expert and I also did not manage to send the correct advertisement telegrams with bluetoothctl on my raspi.

Btw.: the manufacturer Id is 0xFFF0

bluetoothctl
advertise menu
manufacturer 0xfff0 0x6D 0xB6 0x43 0xCF 0x7E 0x8F 0x47 0x11 0x88 0x66 0x59 0x38 0xD1 0x7A 0xAA 0x26 0x49 0x5E 0x13 0x14 0x15 0x16 0x17 0x18
back
advertise on

Hmmm...

elclaudio commented 1 month ago

Hi @elclaudio :) I'm absolutely no BT-expert and I also did not manage to send the correct advertisement telegrams with bluetoothctl on my raspi.

Btw.: the manufacturer Id is 0xFFF0

bluetoothctl
advertise menu
manufacturer 0xfff0 0x6D 0xB6 0x43 0xCF 0x7E 0x8F 0x47 0x11 0x88 0x66 0x59 0x38 0xD1 0x7A 0xAA 0x26 0x49 0x5E 0x13 0x14 0x15 0x16 0x17 0x18
back
advertise on

Hmmm...

So, this works in android each time (tested on a old phone and a recent tablet) with nrf connect but never works on linux, be it on x86 or arm. The common stuff is the bt stack, bluez on linux. I still haven't found what is going on. A test on windows could be possible if proper tool or code is available.

J0EK3R commented 1 month ago

Heureka! :)

I managed to send the proper telegrams with hcitool on my raspi - without knowing what I was doing...

sudo su

hciconfig hci0 up
hciconfig hci0 leadv 3

// switch MK6.0 to BT-Mode
hcitool -i hci0 cmd 08 0008 25 02 01 02 1b ff f0 ff 6D B6 43 CF 7E 8F 47 11 88 66 59 38 D1 7A AA 26 49 5E 13 14 15 16 17 18

// stop all channels
hcitool -i hci0 cmd 08 0008 25 02 01 02 1b ff f0 ff 6D B6 43 CF 7E 8F 47 11 84 66 59 38 D1 7A AA 34 67 4A 55 BF 15 16 17 18

// channel 1 fullspeed
hcitool -i hci0 cmd 08 0008 25 02 01 02 1b ff f0 ff 6d b6 43 cf 7e 8f 47 11 84 66 59 47 d1 7a aa 34 67 4a ed b7 15 16 17 18

Screenshot 2024-05-15 072432

hcitool -i hci0 cmd 08 0008 
length:     25 (hex!)
flags:      02 01 02
length:     1b
type:       ff (-> manufacturer specific)
company id: ff f0
data:       rest
J0EK3R commented 1 month ago

Here is a link how to increase BLE advertisement