It occurred to me I might be able to find more cheap ESCs in this size profile on aliexpress and I did find some offers that were far cheaper than amazon. The ones I bought on Amazon were'n't too bad on price but these were a lot cheaper but take longer to ship from China on aliexpress. Here was my haul of 11 more:
Also pay special attention to the first ESC in that list. It is for $3.25 each SHIPPED and that is CHEAPER than the cost in parts to make my own motor controller from parts. Now THAT is a deal!
Ok so with these off the shelf ESCs in route to me, I decided to go digging into what their behavior might be and how I might modify their behavior to fit what the robot needs rather than what a drone needs. Firstly, these ESCs run a firmware called BLHeli_S which is open source and is downloaded/flashed onto their onboard microcontroller via the two signal wires coming off the ESC. Now in a typical drone/quadcopter setup a separate microcontroller called the "flight controller" usually sends commands to each of 4 ESCs to get them to flight a little harder or a little less to achieve the right balance of the quadcopter or w/e or accelerate or w/e. The commands are throttle percentage and brake from what I gather. The analogy for these commands is they work the same way you use the gas and brake pedal of a car. So the gas pedal commands are press gas pedal hard or soft etc and that results in changes to acceleration and speed of a car. So you don't command the acceleration and speed directly but instead command the pressing of the gas pedal harder or softer. The brake command I believe is more stock though - it doesn't have a brake hard or soft but only a brake command I think. That's not good so we'd want to implement a change to make the brake command able to brake harder or softer just like the throttle command lets you do. In my setup, my arduino is going to be sending these commands to the ESC microcontroller just like the flight controller usually would. So my arduino is like the flight controller even though we aren't doing flight here. Anyways, the next issue is once they do brake enough to come to stop, they shut off power and go into a standby mode. That is no good. For a robot we'd want to brake enough to stop the rotation but once stopped we'd want to actively hold the joint of the finger say in place, not just have the finger go limp the moment it arrives at its desired joint angle. So that too needs to be added to the braking behavior. Another issue is that once the motor has not crossed a zero crossing back emf event for a certain countdown, it determines that the motor is stalled, and once it determines it has stalled for enough time, it gives up and shuts off, then periodically runs a start sequence again hoping to get unstuck. This is NOT what we want for a robot. When a robot finger contacts a obstruction, we want it to keep pressing on it indefinitely as that obstruction could be gripping a cup of water and that was exactly intended that the motor keep pressing at same intensity as it grips the cup. It is NOT to independently say ok we are stalling on this cup of water lets let go. That is fine for a quadcopter whose blade is stuck against a tree branch but NOT fine for a robot finger holding an instrument. Making the decision to let go or press the same firmness or press harder or press softer and how long to press is up to the arduino "flight controller" or even the higher level PC running the robot, NOT the microcontroller on the drone. That decision is above his pay grade. He needs to just keep pressing in that case and await further instruction beyond that. So that behavior also has to change. There may have been one or two other mods I wanted but those were the big ones that came to mind.
Edit: actually one more thing: since we now have the motor when stuck just endlessly press waiting till it hits a zero crossing event, we have to first make sure it is listening for incoming commands during this endless waiting period and we also have to be able to command it to press harder or softer or reverse. However, if it is stuck because of some bug or quirk where it was advancing as normal then an obstruction pushed it backwards a bit and now it is waiting endlessly to detect a move forward that will now not happen since it is just commutating the same commutation step PWM endlessly and not attempting any further rotating of the 6 commutation steps anymore, it could just stall forever. So to fix this, we want to create a nudge command that essentially forces into a restart sequence that attempts to actively rotate the motor a full 360 degrees. This would break it past whatever infinite loop it had entered by accident. So basically this is the arduino flight controller's way of saying ok you aren't moving and should be, try to restart - the same way it would behave if it had determined it was stalling in its stock code but in this case the determination to try to unstuck is being made by the higher level microcontroller rather than its own firmware.
That being said, BLHeli_S firmware for the drone is almost universally upgraded now adays to a open source upgrade called BlueJay. You simply hook up a arduino to the two signal wires of the ESC, then plug the arduino into a PC, then you use a software suite calls BLHeliSuite I believe to flash whatever new firmware you want onto the ESC's microcontroller and boom, you have your modified firmware on the ESC and its behavior is tweaked. So using that workflow we plan to replace BLHeli_S with BlueJay, HOWEVER, the mods I mentioned in my last paragraph must be made to the BlueJay firmware before we can flash the modded version of the firmware onto the ESC.
That said, to mod the BlueJay source code, one must first download the full code repository of BlueJay from github onto their desktop PC and then use notepad or w/e to view and edit the code which is stored in .asm files. The code is about 20 files and the total lines of code in the firmware is about 3k lines I think. All written in assembly language. Yuck. Then once one has modified the code to tweak the behavior as I've laid out, then one must convert the .asm files into a single .hex file which then must be flashed/downloaded onto the ESC. The conversion of the .asm files into a single hex file requires one to download the "Keil® PK51 Developer's Kit" which you can only download if you register an account on silabs.com. That kit contains the necessary 3 executable files that do the 3 conversion steps that convert the .asm files into a single .hex file. Those 3 .exe files are an assembler, a linker, and a hex converter. On windows I will have to run each of these .exe's using the command prompt to run them on the .asm files to convert to the .hex file. Or to make it a bit easier one can create a .bat file that runs the command prompt commands sequentially one at a time for you and so you double click the .bat file and the .hex file is made - boom done.
That said, I downloaded that developer's kit and downloaded the github repo for bluejay and have studied the code with chatgpt and began formulating enough understanding of the codebase to begin plans for how to modify the code in the ways I mentioned without breaking the code. This way that codebase can be repurposed into a humanoid robot appropriate variant of an ESC rather than a quadcopter variant. This process is ongoing. I also want to credit chatgpt that 80% of the steps to get this far into this process were largely directed and assisted by chatgpt and would have taken me ages to get this far otherwise. For example, I thought maybe I'd learn how to change the firmware via youtube videos and the first video I saw was discussing the company history behind the company that originally developed and maintained BlueHeli_S firmware. It then went into details of that company's legal problems and politics and world events surrounding decisions that company made. I had to stop and leave the damn video. Holy crap I do not care I just want the ESC to work on my robot WTH! So it was back to chatgpt where I can just get the necessary info I want and not hear a million unrelated things that make me FORGET the original question I had to begin with. I just want my questions answered quickly and concisely so I can figure out what I need to know right away to then get to my next question that the first question pertained to and thereby in a uninterrupted flow of Q&A I can figure out exactly what is going on, what I need to do, why that is the best route to go or if there's a better route, etc.
Note: I did consider just coding the firmware from scratch but after learning as much as I have about the existing firmware, it is VERY involved and complicated and clearly alot of time and effort was put into it and it is useful in many ways so at this time I think its best to try to mod it. But if modding it proves to break it and I cannot mod it successfully without screwing it up, I may have to rewrite it from scratch. It can be very hard to modify someone elses large and complex codebase for ME. I have rarely done this successfully and usually give up quickly due to being overwhelmed and unsure where to even start and unwilling to deeply learn their codebase enough to begin the mod to begin with. Other people's giant code bases tend to feel like a impenetrable fortress and tangled mess and making any change is not only a matter of finding the needle in a haystack of where you need to make that change but also understanding every downstream impact your change will have on other unrelated parts of their code so as to not break something else the moment your change goes into effect. And this feels impossible to do without reading their whole codebase and understanding it fairly deeply. Which is a HUGE time investment that borders on the same challenge difficulty of just rewriting the whole codebase from scratch. Its HORRIBLE. But with chatgpt's help MAYBE I can pull this off in a reasonable time-frame without too much pain. We'll see. I am NOT a big fan of assembly language coding but here we are.
So I'm in this now. I'm committed. We'll see how this goes. I will probably wait to get the ESC to make significant changes to the firmware. I think I should make the code change then test it on the motor/ESC in a live test to see if the behavior changed and if the code all still works. If it does work then I can make the next small change. I can rinse repeat this until all changes are made and working. That is the plan for now.
Also pay special attention to the first ESC in that list. It is for $3.25 each SHIPPED and that is CHEAPER than the cost in parts to make my own motor controller from parts. Now THAT is a deal!
Ok so with these off the shelf ESCs in route to me, I decided to go digging into what their behavior might be and how I might modify their behavior to fit what the robot needs rather than what a drone needs. Firstly, these ESCs run a firmware called BLHeli_S which is open source and is downloaded/flashed onto their onboard microcontroller via the two signal wires coming off the ESC. Now in a typical drone/quadcopter setup a separate microcontroller called the "flight controller" usually sends commands to each of 4 ESCs to get them to flight a little harder or a little less to achieve the right balance of the quadcopter or w/e or accelerate or w/e. The commands are throttle percentage and brake from what I gather. The analogy for these commands is they work the same way you use the gas and brake pedal of a car. So the gas pedal commands are press gas pedal hard or soft etc and that results in changes to acceleration and speed of a car. So you don't command the acceleration and speed directly but instead command the pressing of the gas pedal harder or softer. The brake command I believe is more stock though - it doesn't have a brake hard or soft but only a brake command I think. That's not good so we'd want to implement a change to make the brake command able to brake harder or softer just like the throttle command lets you do. In my setup, my arduino is going to be sending these commands to the ESC microcontroller just like the flight controller usually would. So my arduino is like the flight controller even though we aren't doing flight here. Anyways, the next issue is once they do brake enough to come to stop, they shut off power and go into a standby mode. That is no good. For a robot we'd want to brake enough to stop the rotation but once stopped we'd want to actively hold the joint of the finger say in place, not just have the finger go limp the moment it arrives at its desired joint angle. So that too needs to be added to the braking behavior. Another issue is that once the motor has not crossed a zero crossing back emf event for a certain countdown, it determines that the motor is stalled, and once it determines it has stalled for enough time, it gives up and shuts off, then periodically runs a start sequence again hoping to get unstuck. This is NOT what we want for a robot. When a robot finger contacts a obstruction, we want it to keep pressing on it indefinitely as that obstruction could be gripping a cup of water and that was exactly intended that the motor keep pressing at same intensity as it grips the cup. It is NOT to independently say ok we are stalling on this cup of water lets let go. That is fine for a quadcopter whose blade is stuck against a tree branch but NOT fine for a robot finger holding an instrument. Making the decision to let go or press the same firmness or press harder or press softer and how long to press is up to the arduino "flight controller" or even the higher level PC running the robot, NOT the microcontroller on the drone. That decision is above his pay grade. He needs to just keep pressing in that case and await further instruction beyond that. So that behavior also has to change. There may have been one or two other mods I wanted but those were the big ones that came to mind.
Edit: actually one more thing: since we now have the motor when stuck just endlessly press waiting till it hits a zero crossing event, we have to first make sure it is listening for incoming commands during this endless waiting period and we also have to be able to command it to press harder or softer or reverse. However, if it is stuck because of some bug or quirk where it was advancing as normal then an obstruction pushed it backwards a bit and now it is waiting endlessly to detect a move forward that will now not happen since it is just commutating the same commutation step PWM endlessly and not attempting any further rotating of the 6 commutation steps anymore, it could just stall forever. So to fix this, we want to create a nudge command that essentially forces into a restart sequence that attempts to actively rotate the motor a full 360 degrees. This would break it past whatever infinite loop it had entered by accident. So basically this is the arduino flight controller's way of saying ok you aren't moving and should be, try to restart - the same way it would behave if it had determined it was stalling in its stock code but in this case the determination to try to unstuck is being made by the higher level microcontroller rather than its own firmware.
That being said, BLHeli_S firmware for the drone is almost universally upgraded now adays to a open source upgrade called BlueJay. You simply hook up a arduino to the two signal wires of the ESC, then plug the arduino into a PC, then you use a software suite calls BLHeliSuite I believe to flash whatever new firmware you want onto the ESC's microcontroller and boom, you have your modified firmware on the ESC and its behavior is tweaked. So using that workflow we plan to replace BLHeli_S with BlueJay, HOWEVER, the mods I mentioned in my last paragraph must be made to the BlueJay firmware before we can flash the modded version of the firmware onto the ESC.
That said, to mod the BlueJay source code, one must first download the full code repository of BlueJay from github onto their desktop PC and then use notepad or w/e to view and edit the code which is stored in .asm files. The code is about 20 files and the total lines of code in the firmware is about 3k lines I think. All written in assembly language. Yuck. Then once one has modified the code to tweak the behavior as I've laid out, then one must convert the .asm files into a single .hex file which then must be flashed/downloaded onto the ESC. The conversion of the .asm files into a single hex file requires one to download the "Keil® PK51 Developer's Kit" which you can only download if you register an account on silabs.com. That kit contains the necessary 3 executable files that do the 3 conversion steps that convert the .asm files into a single .hex file. Those 3 .exe files are an assembler, a linker, and a hex converter. On windows I will have to run each of these .exe's using the command prompt to run them on the .asm files to convert to the .hex file. Or to make it a bit easier one can create a .bat file that runs the command prompt commands sequentially one at a time for you and so you double click the .bat file and the .hex file is made - boom done.
That said, I downloaded that developer's kit and downloaded the github repo for bluejay and have studied the code with chatgpt and began formulating enough understanding of the codebase to begin plans for how to modify the code in the ways I mentioned without breaking the code. This way that codebase can be repurposed into a humanoid robot appropriate variant of an ESC rather than a quadcopter variant. This process is ongoing. I also want to credit chatgpt that 80% of the steps to get this far into this process were largely directed and assisted by chatgpt and would have taken me ages to get this far otherwise. For example, I thought maybe I'd learn how to change the firmware via youtube videos and the first video I saw was discussing the company history behind the company that originally developed and maintained BlueHeli_S firmware. It then went into details of that company's legal problems and politics and world events surrounding decisions that company made. I had to stop and leave the damn video. Holy crap I do not care I just want the ESC to work on my robot WTH! So it was back to chatgpt where I can just get the necessary info I want and not hear a million unrelated things that make me FORGET the original question I had to begin with. I just want my questions answered quickly and concisely so I can figure out what I need to know right away to then get to my next question that the first question pertained to and thereby in a uninterrupted flow of Q&A I can figure out exactly what is going on, what I need to do, why that is the best route to go or if there's a better route, etc.
Note: I did consider just coding the firmware from scratch but after learning as much as I have about the existing firmware, it is VERY involved and complicated and clearly alot of time and effort was put into it and it is useful in many ways so at this time I think its best to try to mod it. But if modding it proves to break it and I cannot mod it successfully without screwing it up, I may have to rewrite it from scratch. It can be very hard to modify someone elses large and complex codebase for ME. I have rarely done this successfully and usually give up quickly due to being overwhelmed and unsure where to even start and unwilling to deeply learn their codebase enough to begin the mod to begin with. Other people's giant code bases tend to feel like a impenetrable fortress and tangled mess and making any change is not only a matter of finding the needle in a haystack of where you need to make that change but also understanding every downstream impact your change will have on other unrelated parts of their code so as to not break something else the moment your change goes into effect. And this feels impossible to do without reading their whole codebase and understanding it fairly deeply. Which is a HUGE time investment that borders on the same challenge difficulty of just rewriting the whole codebase from scratch. Its HORRIBLE. But with chatgpt's help MAYBE I can pull this off in a reasonable time-frame without too much pain. We'll see. I am NOT a big fan of assembly language coding but here we are.
So I'm in this now. I'm committed. We'll see how this goes. I will probably wait to get the ESC to make significant changes to the firmware. I think I should make the code change then test it on the motor/ESC in a live test to see if the behavior changed and if the code all still works. If it does work then I can make the next small change. I can rinse repeat this until all changes are made and working. That is the plan for now.