Posted June 27, 2024Jun 27 Hi everyone! I'm new to Eurobricks, so don't know if this is the correct forum for this topic. However I really want to share my recent findings about Mould King Servo Motor. I spent last weekend testing MK Servo Motor and MK 4.0 controller with a LEGO Technic MOC. MK 4.0 has a controller with analog sticks, so one can think that it supports proportional control for motors. However there are many controversial reviews about this on youtube/reddit/forums etc. It seems that proportional steering was supported by MK some years ago, but they dropped it (probably) due to problems with fluttering and quick battery drain. Part 1. Out-of-the-box MK capabilities Soon after receiving the order with MK components, my first findings where: 1.1) MK 4.0 does not currently support proportional steering with MK Servo Motor 1.2) MK 4.0 supports proportional power output to M/L motors I've also ordered MK 6.0, and it works absolutely the same way (the only difference is 6 outputs). So everything written below is true both for MK 4.0 and 6.0. This was of course very disappointing, because full left/full right inputs are not comfortable enough for controlling a fast moving Technic MOC. This triggered the beginning of my research. My hope was that if MK supported proportional steering in the past, then it could be controlled by software in some way. Part 2. MK Hub output The first thing I've done was looking at C1/C2 signals from the hub (since Power Functions is not a new thing, there's a lot of information on how PF Servo should be controlled). (Actually, before doing that, I've soldered dupont pins to a cutted PF connector cable to intercept the signal) This showed: 2.1) MK hub does output of PWM signals to C1/C2 wires with duty cycle proportional to the input on MK controller 2.2) The frequency of this signal is 470 Hz , which is 2 times lower than expected for a PF Servo Part 3. MK Servo input So the next obvious thing to do was to test how the MK Servo Motor performs when it gets a PF-compatible input signal. The original LEGO Power Functions components work at 1200 Hz, but there are many videos on YouTube showing Arduino-controlled LEGO servos, and Arduino's out-of-the-box frequency for PWM on digital pins is 980 Hz. To make this test, I've built an assembly utilizing Arduino Nano and L298N motor driver for making 9V output PWM signal (Arduino itself can produce just 5V with very low current). This showed: 3.1) MK Servo motor can rotate to intermediate positions, proportional to C1/C2 duty cycle of 980 Hz signal But, unlike LEGO PF Servo, which has 15 fixed positions and stops itself when it reaches specific position, MK Servo performs differently: 3.2) MK Servo does not have specific fixed intermediate positions 3.3) MK Servo does not stop in any of intermediate positions, which results in fluttering (even if when there's no noise in input signal) and, probably, higher power consumption as a result By the way, statements 2) and 3) are true not only for 980 Hz, but also for 1200 Hz signal, which I tried in hope that it will make MK Servo perform exactly as a LEGO PF Servo. Part 4. The PoC At this point I had an MK hub, which produced PWM signals at 480 Hz, and an MK Servo which expected 980 Hz. To solve this problem I've designed some kind of "frequency modifier", also based on Arduino. Please mind that this is a Proof-of-Concept, which needs to be made in a more compact way and to be more simple technically (Arduino seems to be over-engineering here). Anyway, what this PoC does is quite simple: 4.1) It intercepts the connection between MK Hub and MK Servo 4.2) It reads C1/C2 signals at 470 Hz from the MK hub (which are proportional to the inputs on MK Controller) 4.3) It outputs these C1/C2 signals at 980 Hz for the MK Servo 4.4) There are also some workarounds specific for MK Servo to solve fluttering and power consumption which I will not describe here as this post has already become huge - you can find them in sketch code here (the wiring diagram is also on github) https://github.com/igrolabs/ServoBrick The limitations are: - it has huge size (but I managed to perform a test drive of my MOC car with it) - the code is specific for Mould King - it is not working with other servo motors (I've also tried it with CaDa with no luck) - it can be modified to work also with original LEGO PF Servo (but I didn't do it) Part 5. So, what's next ? First of all, I would be glad to hear any of your feedback about this stuff. As for me, my thoughts are: 5.1) The test drive I've performed with my MOC car showed that there's little value in intercepting just the steering signal. 5.2) MK 4.0 controller showed to have bad sensitivity (6.0 was slightly better), which is not enough for precision steering 5.3) One possible evolution of the PoC can be in intercepting both steering and throttle signals, and to limit maximum steering angles when throttle input is high. This can make sense even when using MK controller 5.4) Controlling both steering and throttling signals results in bigger size of the "modifier box" and makes MK hub useless, so maybe it's more reasonable to develop a custom RC hub with battery, receiver and logic controller in one box. 5.5) Option 5.4 gives the possibility to use 2.4Ghz RC or PS4/PS5/XBox controllers, all of which have better sensitivity 5.6) It is unclear for me at the moment whether the PoC can be made small enough to fit in 1:16 scale MOC. 5.6.1) A hub bigger than MK 4.0 is not reasonable, because my overall goal is to build a fast 1:16 car with proportional steering, which requires use of currently available PF-compatible components (as you know, original LEGO PF Servo is discontinued). 5.6.2) There's already out-of-the-box solution (LEGO C+/PUP motors and hub + pybricks), but it is significantly bigger in size and can be fitted only in larger scale MOCs Edited June 27, 2024Jun 27 by LabManager
June 27, 2024Jun 27 Interesting findings about the Mk servo. I have always wondered what is so hard about copying the PF servo when everything else is easily copied. So you suggest that the core problem could be the lack of fixed positions and the fluttering of the servo? Maybe the use of a different signal is intentional to dumb the servo down to 3 positions instead of letting it flutter which would be even worse? By seeing you experiment with Arduino, I guess you might be okay with RC electronics and 3rd party components? Have you heard of GeekServos? Small, fast, precise, cheap. Only catch is that it requires a proper RC transmitter/receiver to control, and an ESC to control the drive motor. Plus a LiPo battery.. But those can be small, so might fit your scale needs..
July 1, 2024Jul 1 Very interesting work! One thing I'm confused about is that I have proportional control from a MK 6.0 box working perfectly with Lego PF Servos, even though you're saying that the output signal is half what the servos are expecting. Should there be a problem with that?
July 2, 2024Jul 2 Author On 7/1/2024 at 6:44 AM, 2GodBDGlory said: One thing I'm confused about is that I have proportional control from a MK 6.0 box working perfectly with Lego PF Servos, even though you're saying that the output signal is half what the servos are expecting. Should there be a problem with that? Unfortunately I don't have an original Lego PF Servo to test MK 6.0 with it. But I guess MK can load different firmware versions to their hubs over the years. So you might have a "special" version of MK 6.0, which outputs the signal with correct frequency that works with Lego PF Servo and will also work with an MK Servo. And as MK 6.0 is a consumer product there should not be any problems with it. Anyway, the design of the product is up to MK and it's not opensource so we can only make assumptions. I agree with @gyenesvi that it may be intentional to dumb the servo down to 3 positions instead of letting it flutter which would be even worse On 6/28/2024 at 2:25 AM, gyenesvi said: Have you heard of GeekServos? Small, fast, precise, cheap. Thank you for this suggestion! Didn't know about GeekServo, but it really meets most of my needs, so I've ordered it and now waiting for delivery. One tricky thing is that the GeekServo has 5V power supply, while PF is 9V, so my controller will require an additional DC converter taking some more space. For now, my prototype has become smaller and I've changed the overall design so it will not need the MK hub and controller any more: 1) Power will be supplied from external 7.4V LiPo battery with JST plug 2) USB BT 4.0 dongle allows to directly pair with PS4 controller (or any other which can make wireless connection by USB dongle, Logitech F310 is an example) 3) Outputs for 2x PF motors (4 pins, with hack for MK Servo) + 1x GeekServo (3 pins) + LEDs (3 pins) 4) Fits into 7x9x3 stud box (yet to be 3D-printed)
July 2, 2024Jul 2 3 hours ago, LabManager said: Thank you for this suggestion! Didn't know about GeekServo, but it really meets most of my needs, so I've ordered it and now waiting for delivery. One tricky thing is that the GeekServo has 5V power supply, while PF is 9V, so my controller will require an additional DC converter taking some more space. Glad to hear you see it fit! (I forgot to mention that a GeekServo is also stronger, despite being smaller :D) True that you need to convert power to 5-6V, but don't forget that you also need a control signal as in RC receivers, meaning a PWM signal where the pulse width defines the servo position (between 500 and 2500 usec, 1500 usec being the center position). Are you going to produce that signal with the Arduino? Your prototype looks nice so far!
July 6, 2024Jul 6 Author GeekServo is fantastic! It gives so accurate control for my 4WD car now! If I knew about GeekServo before, the topic should be given a different name... However there's still a lot of work to be done (factory-made PCB, LiPo discharge protection, 3D-printed box, more functional software and so on, not to mention that my car needs a body too ))) Edited July 6, 2024Jul 6 by LabManager
July 7, 2024Jul 7 On 7/2/2024 at 1:02 PM, LabManager said: One tricky thing is that the GeekServo has 5V power supply, I have always powered my GeekServo with 2S (7.4V) LiPo battery and I had no issue. But, it is at your own risk. Here, you can see my work : GeekServo - real 360° - Programming - LEGO Technic, Mindstorms, Model Team and Scale Modeling - Eurobricks Forums 12DOF-Q-3 Quadruped whith GeekServos - LEGO Technic, Mindstorms, Model Team and Scale Modeling - Eurobricks Forums 8DOF-Q-3 - Quadruped line follower with Huskylens. Training for TRR contest 2022 - In my garage - LEGO Technic, Mindstorms, Model Team and Scale Modeling - Eurobricks Forums https://youtu.be/FSxC97ZcFZ4?si=xYAiwn1GRvq1h5YM
July 7, 2024Jul 7 Author 46 minutes ago, oracid said: I have always powered my GeekServo with 2S (7.4V) LiPo battery and I had no issue. But, it is at your own risk. Here, you can see my work : GeekServo - real 360° - Programming - LEGO Technic, Mindstorms, Model Team and Scale Modeling - Eurobricks Forums 12DOF-Q-3 Quadruped whith GeekServos - LEGO Technic, Mindstorms, Model Team and Scale Modeling - Eurobricks Forums 8DOF-Q-3 - Quadruped line follower with Huskylens. Training for TRR contest 2022 - In my garage - LEGO Technic, Mindstorms, Model Team and Scale Modeling - Eurobricks Forums https://youtu.be/FSxC97ZcFZ4?si=xYAiwn1GRvq1h5YM You have a very interesting YouTube channel! I've found you video about controlling GeekServo 360 and it was very helpful. By the way, Arduino's library has these defines in Servo.h: #define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo For GeekServo 360 the limits should be 500 and 2500 respectively, but it still works fine. I'm not coming any close to these limits in my application, but does the Servo Library need to be modifed to use full rotation ?
July 7, 2024Jul 7 3 hours ago, LabManager said: does the Servo Library need to be modifed to use full rotation ? No ! Those are default values that you can change. You just have to use the function servo.attach(pin, min, max) in your code. Here : Servo - attach() - Arduino Reference Please consult my code in the video at 15'00". If the values 500µs and 2500µs are not good for 0° and 360° or 180°, you can ajust them. That is the goal of .attach() function.
July 7, 2024Jul 7 Details : If you want to use the Grey GeekServo to 0° to 180°, you must code servo.attach( pin, 500, 1500 ); if you want to use the Grey GeekServo to 0° to 360°, you must code servo.attach( pin, 500, 2500 ); I have tested the torque of the Grey GeekServo at 180°, I measured 3.95kg.cm (almost 4kg.cm). You must consider that this is very good.
July 17, 2024Jul 17 Question here: Have you opened a MK Servo once to look at the PCB? If I remember correctly, it has just 5 different contact-fields: +100 position "between" (>0 and <100) 0 position "between" (>0 and <100) -100 position (dont kill me for the greater / lesser than fieldsnot being changed accordingly... :P) I am still not sure from the cost / decision perspective to not directly 1:1 copy a "fully stepped" version or investing in some other electronical solution to read the values in analogue values. But I think it may have been "good enough" back then and as they are still selling those (or we are buying them), why changing a working concept which may just result in more prodution costs per unit.. :D
September 11, 2024Sep 11 Hi LabManager, Thanks for the informative post with your research and for putting up a GitHub repo. I am VERY interested in the topic of your initial post, "proportional control of MK servo". Due to a severe character flaw, I happen to have a fair number of those MK 4.0 motors and I'd like to use them. I'm going to dig into your Github docs some more, but I think you've created the solution I'm looking for. Replace the controller brick with something else (Arduino based) that allows the existing MK motors to work better. I have an extra PS4 controller as well, and I love the idea of using it. Would you prefer that I continue this thread, or that I contact you via Github as I explore this option? Thanks again!
September 16, 2024Sep 16 Author On 9/11/2024 at 11:18 PM, lagerratrobe said: Would you prefer that I continue this thread, or that I contact you via Github as I explore this option? Hi, lagerratrobe! Well, it seems now that this topic should be renamed since it covers more of Arduino and schematics than just MK Servos. But I think it might be useful to collect such information, so feel free to ask any questions here. BTW - I moved the repo to another account, so please look at https://github.com/pink0D/TechnicPF. There are also some Arduino schematics for classic Arduino board (Pro Mini) and USB Bluetooth Dongle , but if you are ok with Arduino you can replace it with ESP32 (which has embedded BT). However, a lot of wiring is still needed to implement a custom controller. I didn't adandon the idea of making a custom PCB for that, but PCB design is really tricky for me. Edited September 16, 2024Sep 16 by LabManager
September 16, 2024Sep 16 This is just out. It's the marriage of a servo with a DC motor. I don't know much about this kind of motor, but I thought it might interest you, especially since the assembly is Lego compatible, which is always the case with M5STACK. https://shop.m5stack.com/products/roller485-unit-with-bldc-motor-stm32?mc_cid=7bb51ca148&mc_eid=4f7d23ce1c&variant=45585634754817 https://shop.m5stack.com/products/roller485-lite-unit-without-slip-ring-stm32
October 8, 2024Oct 8 Hi Dmitry, Didn't want you to think I'd forgotten about this. Truth is that I've had to come back to proficiency with my Arduino stuff and that's been a project by itself. However, some progress has been made, with the ultimate goal of being able to replicate your work. So far, I've cobbled together a little TB6612 driver board with hookups for an external battery and 2 motors. This won't be used with the Mould King servo/L motor, but rather with a little 2-motor Lego hybrid tank that I'm using for testing. Separately, I have an HC06 BLE board and I need to decide if I'm going to bother with that, or just plug an old RC receiver into the Arduino and use that. It's a fun challenge for me, but I'm definitely working slowly through each piece of the puzzle.
November 6, 2024Nov 6 Author It’s been a while since I posted updates on this topic. Meanwhile, I think I’ve found the solution for most of my initial goals. These were the key features I wanted to have in my RC setup for LEGO: 1) Proportional steering (reason: it’s really needed to make a fast vehicle more controllable). 2) Using of PF-motors (reason: they are cheap and widely available). This goal is not fully met because I’ve chosen to use the GeekServo, but it is also cheap, and its quality is at least as good as 3rd party PF motors 3) Controlling the vehicle with a hardware gamepad without any kind of smartphone between the controller and the hub (reason: the less components, the better) And here is the list of the components I’m using now: 1) Mould King Power Module 4.0 is still the core component of my setup. This includes both the hub and the remote controller with proportional inputs. 2) Mould King Black L-Motor, which provides enough torque for a 1:16 car (however, I didn’t use it in the test vehicle for my demo videos, because they were shot indoors with limited space available) 3) The GeekServo for proportional steering 4) ESP32-CAM. It is not the smallest ESP32 board, but I thought it would be interesting to include realtime-FPV functionality. Can’t say this was a success, but it also works! 5) Custom PCB that acts as an adapter between MK hub and the GeekServo, implementing the logic which I described in the first post here. The PCB has 4.8mm holes so it can be fixed on a LEGO beam with 3/4 pins or axles. More detailed description, PCB files and Arduino sketches are available at my GitHub (https://github.com/pink0D/CameraBrick). I tried to use only commonly available components (even custom PCB’s can be also easily ordered nowadays), so I hope it will be possible to reproduce my work for anyone with basic soldering and programming skills. Some pictures of how it all looks like: And of course the videos: FPV demo GeekServo demo
November 6, 2024Nov 6 Wooooooah! That FPV car is awesome! I was thinking of getting an ESP32-CAM for machine vision stuff but I didn't realize it can stream live video. Long ago there was an online simulator game in which the player controls a Mars rover based on images sent back from the rover. The game had a simulated time delay to represent the transmission time, so you had to program your movements and then see the result. I always thought it would be cool to make a real version where you control a model rover in a different room.
November 7, 2024Nov 7 Very good work ! I use to use GeekServo with 2S (7.4V to 8.4V) battery. It works very well.
November 7, 2024Nov 7 @LabManager, this is really amazing! I have always wondered how it would be possible to convert the PF signal to a proper servo signal. You seem to be the guy to understand it, so hopefully you can explain to me some further details that I still unclear to me. What I don't clearly understand is what are the roles of the custom PCB and the ESP32. As far as I understand, what the custom PCB does, apart from simplifying the wiring, is that it takes the C1 and C2 PF signals and that comparator thingy generates one signal out of the two? And then the ESP32 takes that one signal and maps that into the PWM signal required for the servo? For that you had to program the ESP32 to do the right thing, but the ESP32 has a PWM signal generator built in, right? What I have really been wondering though, is whether all this could be done with existing electronics components, without using an ESP32, just a custom PCB with the right components, such as a PWM signal generator. Does such an electronics component exist at all? Would it be possible to make a PCB that does just that without the need for programming it?
November 7, 2024Nov 7 Author @gyenesvi your understanding is correct. The PCB is used mostly for simplifying the wiring, and 4.8 mm holes are used to fix it on the vehicle (this is also an important function ) Everything else is done in the ESP32: with interrupts, read incoming PWM from pins connected to C1/C2, save LOW and HIGH timings in memory => calculate the rotation angle based on it => generate new signal for GeekServo (which is also PWM, but with completely different parameters). And this cycle is repeated continiously every 10 milliseconds. I don't think this can be done on a bare PCB with just basic electornic components, and some chip is needed anyway. I agree that the ESP32 is an overkill for a such trivial use case, and it could be implemented on some primitive chip like PIC, but that would require much more skills and knowledge than I have in electronics. Arduino is much easier to start with.
November 7, 2024Nov 7 I wonder if there is a microcontroller inside the Mould King Power Module 4.0. It is probably not open source, but if the microcontroller is common, then maybe someone with the skills could program it.
November 7, 2024Nov 7 4 hours ago, LabManager said: I agree that the ESP32 is an overkill for a such trivial use case, and it could be implemented on some primitive chip like PIC, but that would require much more skills and knowledge than I have in electronics. Arduino is much easier to start with. I completely agree on this. I am in the same boat and used ESP32's and even Vroom boards for far less demanding tasks than yours - programmed using the Arduino IDE or the VS Code IDE with the platformio plugin. This is simply brilliant, @LabManager! Best wishes, Thorsten
November 7, 2024Nov 7 6 hours ago, LabManager said: @gyenesvi your understanding is correct. Thanks for the answers! 6 hours ago, LabManager said: The PCB is used mostly for simplifying the wiring, and 4.8 mm holes are used to fix it on the vehicle (this is also an important function ) Indeed, that's also important :) 6 hours ago, LabManager said: Everything else is done in the ESP32: with interrupts, read incoming PWM from pins connected to C1/C2, save LOW and HIGH timings in memory => calculate the rotation angle based on it => generate new signal for GeekServo (which is also PWM, but with completely different parameters). And this cycle is repeated continiously every 10 milliseconds. This clarifies things, initially I thought it differently, I mixed the resistors up with something that does some signal processing of the two control signals; but now I understand that it just lowers the signals and passes both of them to the board. One thing is not clear though about the voltage divider. On one hand you have the buck converter to provide 5V signal to the ESP, and on the other hand the control signals are also transformed by the voltage divider for the same reason, because the ESP32 cannot handle 9V. So what's the difference between the two, why are two different techniques required to down-regulate the 9V signals? Is it that the power needs to be regulated precisely to 5V and for that you need a voltage regulator, but for the control signals it is enough just to lower them to some arbitrary low enough value that the board can handle? I also looked at your code and now understand that the analog control signals first get converted to duty cycle values, and then the output PWM signal for the servo is generated. I guess the Servo class which does the actual signal generation (write PWM signal with specified microseconds of frequency) is a system class on the ESP32, right? 6 hours ago, LabManager said: I don't think this can be done on a bare PCB with just basic electornic components, and some chip is needed anyway. I agree that the ESP32 is an overkill for a such trivial use case, and it could be implemented on some primitive chip like PIC, but that would require much more skills and knowledge than I have in electronics. Arduino is much easier to start with. Sure, I understand that Arduino programming is much easier :) I just wanted to understand what would be required. The reason I think this should be doable electronically, is that a hobby RC receiver should have a similar circuitry if I am not mistaken. Such a receiver gets a 5V signal and GND and also receives some digitally represented control signal from the transmitter, and generates the appropriate PWM signal in its pins. Maybe in that case the task is one step simpler since the control signal is probably not analog but already digitally received from the transmitter, but the PWM signal needs to be generated. At least that is what I would guess, but I have little knowledge in electronics. So if anyone has more input on this, I'm all ears :)
November 8, 2024Nov 8 I've done something similar a few years ago to connect hobby servos to Power Functions. (In the image below, a 2x5 studful Geek servo). This custom PCB has an ATTINY84 microcontroller to read the C1/C2 PWM and drive the servo accordingly. There is also an IR receiver which allows direct control without a Power Functions receiver.
November 8, 2024Nov 8 On the subject of converting C1/C2 to servo PWM without a microcontroller, this is doable... As a rough concept, I would suggest the following: 1. Convert C1/C2 to analog by RC filter. Combine these two signals into one with an opamp subtractor. 2. Generate a PWM for the servo from a 556 timer. (The 556 is two timers. The first produces a constant frequency to trigger the second timer, which is configured as a one-shot). 3. Let the combined analog signal determine the pulse width of the one-shot timer. The result is the servo signal. There are a number of issues with this approach that are solved by a microcontroller. Foremost is that it would take at least double the space - although it could be a few cents cheaper in volume.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.