SimpleFOC Balancer

Hello from a newbie!
With a fascination for robots but no programming or electronic skill set at all, I’ve decided to do something about it and build myself a robot from scratch. I’m self-learning along the way with an end-goal of building a mobile inverted pendulum robot with articulated legs to vary its height. Like many, I guess I was taken up with the Ascento robot project (https://www.ascento.ethz.ch).

I was also very impressed with Antun’s SimpleFOC Balancer which inclined me to adopt SimpleFOC as the core of my control strategy. The wealth of guidance in the ‘Docs’ and community are very helpful but as I said, this is a steep learning curve for me. I’ve having to teach myself FreeCAD and get to grips with 3d printing, Arduino’s, sensors, coding, etc. The scratch build so far has legs, gimbal motors, position sensors and two SimpleFOC shields (V2.0.4) on an Arduino Mega MCU platform. I now have everything fixed to a rig to begin testing sensors and learn how to code.

I’ve been able to use the SimpleFOC library example to get angle and velocity readings off the AS5600 magnetic position sensors (mounted in bespoke housings on the legs) its at this point however, my ignorance becomes evident. I’m using I2C and I’ve found my choice of position sensors have a fixed address. Can I use an I2C multiplexer or am I expecting too much from my Arduino Mega processing performance? Searching the community forum I’m beginning to doubt my choice of MCU.

Whilst I’m generally pleased with the construction so far, I’m not confident that a stable Balancer is viable on the route I’m taking. I’m now realizing just how ambitious my articulated leg project is.

I propose therefore to take a side step and progress my learning on a proven solution (aka Antun’s Balancer). This should improve my chances of a successful outcome and I can come back to my scratch build from that. Before I re-purpose the hardware on my current build however, is there a better choice of MCU I should be looking at suited to both builds? Are magnetic position sensors reliable enough or would I be better cutting my losses and using AMT-103 encoders?

I looked at AS5048a magnetic sensors with addressable I2C but the I2C solder pad sizes are too small for me. I could manage the PWM option solder pads but my reading on the community forum led me to believe the PWM option is the least reliable for position sensor performance. Lots left to learn but education is a privilege. Thank you for the privilege of such an informative web site!

3 Likes

Welcome to the forum, @Dennis_Beever! Thanks for using SimpleFOC. :slight_smile:

Wow, great project! And your 3D design looks totally awesome! But I do agree with your approach of starting off a bit simpler…

Yes, there is definately a better choice of MCU - while the ATMega chips revolutionised embedded development together with Arduino IDE/Framework, they are quite ‘venerable’ MCUs by this point, and only 8-bit. It is really too slow to control more than one motor, and even on one motor, performance will be limited.
Choose a 32bit MCU, ideally with floating point capability. Here is a quick roundup/summary:

STM32 MCUs, like the STM32G4 or STM32F4 series are very powerful, well supported in Arduino, fairly easy to use and excellent for motor control. “STM32 Nucleo” development boards are quite inexpensive, and plug to the computer using USB, since most of them have the programmer “built in”. The Nucleo64 boards have Arduino form factor, so Arduino Shields (like the SimpleFOC shield) plug right in.

ESP32 MCUs, like a ESP32 DevKit V3 or ESP32 Pico D4, are super-fast MCUs, which additionally integrate WiFi support - that can make it super-easy to control your creation from remote. They’re also among the cheaper boards, only costing a few $.

Raspberry Pico MCU is quite fast, and very inexpensive. It is quite well suited for simple motor control tasks. It is based on the ARM-Cortex M0 architecture.

Other ARM-Cortex M0 MCUs include the Arduino MKR1010 Wifi and Arduino MKR boards, less fast, but sufficient for controlling one motor. They’re very easy to use, since they’re Arduino original boards.
In the same performance category, and also supported and easy to use are the Arduino Nano 33 IoT, Nano 33 BLE and Arduino Nano 33 Sense boards.

Regarding your sensor question:

  • the AS5600 isn’t a very good sensor for motor control. It isn’t super-accurate and has limited bandwidth. And the single I2C address is a problem for multi-motor setups.
  • you could use two separate I2C buses, with one sensor on each
  • but really you should switch to an SPI sensor, like the AS5048A, AS5047, etc…
  • using SPI you can attach multiple sensors to the same SPI bus (using a different chip-select line for each)

@Dennis_Beever

Welcome to the forum, that’s great!

Let’s see if anyone else more competent than me answers first.

Cheers,
Valentine

Thank you Richard for such a comprehensive response. That’s tremendously helpful and gives me a lot to work with. Some difficulties on the position sensor you suggest though as I’ve found it difficult to find one on a break out board that doesn’t require soldering to the tiny spi pads. I’ll keep looking - the search is part of the fun!
Thanks

@Dennis_Beever

Mouser has 2.5mm pitch AS5047P sensor boards. Solder pins and use normal jumper wires. Comes with a magnet.

AS5047P-TS_EK_AB

https://www.mouser.com/ProductDetail/ams/AS5047P-TS_EK_AB?qs=Rt6VE0PE%2FOfJKFTMKo%2BL0Q%3D%3D

Perfect - thank you! I can get it in the UK too.

There are newer versions of the as5600 that have changeable address. With a little bit of solder practice you can swap out the chips on the boards from China…I’ve done it and it works:). But as others say spi is better/less noisy and just nicer…I like the AS5047

Please make sure you get the one with a magnet, for some reason the mouser picture doesnt show the magnet, but it’s supposed to. I haven’t checked recently hopefully they haven’t removed it from the packet.

This one (AS5047D) on digikey has the magnet in the picture. Please double check. These days with all the strange things happening in the world that may not be surprising.

Hey @Dennis_Beever,

Nice project, I am really interested to see it balance :smiley:

I just wanted to add few points from my experience.

Position sensor

It is true that for many foc implementations as5600 is not really a good solution. Using I2C communication is slow, most of the sensors support only one address and it does not have very good resolution. However for balancing robots you don’t need that good resolution and if you can use this sensor in the analog output mode, I would argue that it is a perfect sensor for this application. AS5047 has much better resolution and supports spi and encoder interface. It will work well for sure, but in my opinion you will not see the performance difference in between the two in terms of balancing, provided you can use analog ouptut of the sensor (not i2c or pwm).

Keep in mind that unfortunately, if you use the spi sensor with arduino uno, you will not be able to stack two boards. Because the spi uses pin 11 which is a PWM pin on arduino uno. If you use nucleo board, you will have a bit more freedom when assigning SPI communication pins.
That is also one reason why I think the analog output based as6500 could be a perfect solution, because you only need one analog pin per sensor.

Microcontroller

When handling balancing robots, the faster mcu the better. Even though you might be able to make it balance with the atmega328, as the guys have already stessed, I would certainly suggest a nucleo or esp32 boards. The benefits of higher grade mcus are numerous and arguably the most important are faster loop times, more flexible spi and i2c pin assignment and larger program memory on the chip allowing for less worries about the code size which is particularly important in the debugging and tuning phase :smiley:

Our star member for balancing robots @Rem666 has been using the atmega328 and as5600 (analog output) for his balancing robots too :smiley:
So it is possible but if it is the first time you’re dealing with balancing robots I would not recommend this approach. :smiley:

Thank you for the input Antun. With all of the community guidance offered, I’m now in the process of reviewing STM32 board options. The Nucleo 64 (Arduino form factor) will allow me to use the SimpleFOC shields I already have so looks favoured at the minute. I also purchased the Deng dual BLDC SimpleFOC board when I ordered the shields (I was shipping from China) so that may provide additional options. The Deng board documentation seems to be limited to Chinese though so determining compatible ESP32 options might be an issue. It came with a non-descript ESP32 board that looks like a clone so can’t be sure of what I have there.
I noted you favored the AMT-103v encoders on your Balancer build. As I maybe looking at buying position sensors anyway, I was wondering why you favored them over magnetic position sensors?

That’s what I had in hand. :smiley:
I did not have any other pair of sensors but the atm-103s, so that’s what I’ve used.

As Antun pointed out, available pins and interfaces can be the limiting factor…

In my experience playing with the sensors, the ABI mode of the magnetic sensors gives you the best of all worlds - contact free measurement, compact sensors, digital precision, up to 14bit on some models, and instant response. SimpleFOC has an interrupt based driver, and there is also a hardware-based driver for STM32 MCUs in our drivers repository - then you get all these benefits with additionally zero MCU overhead, as the MCU hardware handles the encoder signals.

Next best is SPI or SSI, not much difference between the two. They’re also very fast, but you have to poll them and wait for the response (or in the case of SSI, just clock out the response). So there is additional latency compared to the ABI interface.

Analog can be precise, and is very fast, but has the disadvantage of being analog, i.e. requiring far more careful circuit design to ensure good performance.

I2C and PWM based sensors lose out for motor control based on their slow speed.

I2C is nice because (assuming you have control over device addresses) you can attach multiple sensors easily to one bus.

But some SPI sensors (e.g. the AS5048A) also allow for connecting multiple sensors to the same SPI bus (using only one CS line), and generally you can connect multiple SPI devices to the same bus using separate CS lines for each device.

Thanks for that Richard. With my limited knowledge and experience the path to a successful outcome is inevitably going to involve a lot of fault isolation and subsequent learning. The AS5048 on SPi appears the least problematic option so I will be going with that on Nucleo STM32F401.

Thanks again for the huge help from everyone contributing!

Yes, I agree that the AS5600 is not the best solution. I connect via an analog pin because SPI sensors cannot be used (atmega328 and two motors).
But it works. :slight_smile: Even speed is enough. The robot is fast and aggressive. :slight_smile:
It really simple. If anybody want to make it, you can found source and print files here:

1 Like