Recently I decided to start working on an ambitious new project with one of my computer science friends. The initial idea came from the desire to use my VR headset for research. I wanted a way to feel like I was shrunk and I could explore the world as a tiny robot. After some searching online, I discovered that not only was this possible, but it would be surprisingly simple compared to what I expected. I began this project by studying how BLDC motors are controlled and discovered an amazing open source project: SimpleFOC. This project is designed for Arduino-based microcontrollers, but can be used with other IDEs as well. It provides drivers and simple setups for motor drivers and encoders, allowing people like me to create an actuator easily without starting from scratch. I ordered some magnetic encoders and some gimbal motors, and began testing.
Once the motor, motor driver, and encoder had arrived, I had to design a mount for the actuator. This is needed because the magnetic encoder requires a special diametric magnet attached to the rotating shaft to provide the rotational data. After modeling each part from measurements, I finalized the placement of the magnet and encoder to within the specifications listed in the datasheet. Once designed, I printed and tested the fitment on the motor.
Using the 3D models for the cameras and raspberry pi, I was able to put together a CAD design of what I wanted the robot head to look like. Both of the motors are integrated as seamlessly as possible, as I wanted this to look like a finished product without motors and wires everywhere. The design will allow the motors to be powered with 20V from a USB PD trigger, and the raspberry pi will be powered from this with a stepdown converter supporting 5V 3A. The plan is to have this head attach to a body with an arm, so the base is a temporary placeholder.
While working on this, I fell into the rabbit hole that is compact Field Oriented Control (FOC) motor driver design. SimpleFOC has a huge open-source hardware library, with many custom controllers people have designed for their projects. I decided to try it out, and learned a lot about how integrated microcontroller PCBs work when using turnkey PCB solutions. Managing cost with a solution like this was quite the challenge when many of the parts needed are expensive and rare. Making something like this with as many of JLCPCBs basic parts as possible is harder than I expected, but I managed to get my drivers down to around $20 each which I think is pretty impressive. My first design was a FOC driver designed for a compact round stepper motor from a 3D printer extruder.Â
I had a lot of fun designing this motor controller. The STM32F103C8T6 microcontroller it uses is common in hobby spaces, usually called the STM32 Bluepill. It has a bit of an unconventional method for programming, using 2 pins in different positions for different boot modes. It has USB programming support, but it can be confusing and requires extra work. This motor controller uses 2 integrated H-bridge ICs, with a magnetic encoder on the back. One of the reasons I stopped working on this design was my shift from stepper motors to BLDC motors in my design. Stepper motors can be controlled like they are BLDC motors, but due to the way they are designed, they act like a BLDC motor that has 200 poles instead of 4 -14 ish poles. This means that the FOC method requires immense precision to reliably control the angle of the motor. These types of encoders are a lot more expensive, so I opted to switch my designing to some cheap BLDC gimbal motors like the ones in the photo at the top of this page. I also wasn't able to design any mounting holes at this size.
Following the Microspora project and AIOLI-FOC, I decided to start designing with a more modern STM32 microcontroller. The STM32G431 has built-in USB support and is more powerful and compact. Using JLCPCBs library, I was able to find a motor driver IC that has all the features I wanted built-in for a better price than the other common ICs: the DRV8311HRRWR. Unfortunately, the built in current sensing requires some extra work, but I feel that writing custom firmware would be an interesting challenge.