
ODrive Project – Using inexpensive brushless motors in high performance robotics - madcowswe
https://odriverobotics.com/
======
stevendhansen
Very impressive! I love to see this kind of thing on HN. I scanned through
your code a bit on mobile, and here are a few quick suggestions:

1) It looks like you are using field oriented control. This is used 99% of the
time in industry, but if you really want high torque bandwidth you should
check out alternate control techniques. My favorite is an up-and-coming algo
developed at UW-Madison called Deadbeat Direct Torque and Flux Control (DB-
DTFC when searching for papers). It uses an inverse motor model paired with
rotor/stator flux estimators to produce a deadbeat (one timestep later) torque
and flux response. I have heard apocryphal stories of people who implement DB-
DTFC accidentally snapping motor shafts when they forget to limit the torque
slew rate. It is a very high performance algorithm, and beats FOC and DTC
hands down at the cost of a bit more complexity.

2) If you are sticking with FOC for now, you can make a few quick improvements
that will help a lot. First add qd-axis decoupling on you current loop
commands (may have missed them, but I didn't see them in your code). You will
want reference frame speed ("omega") decoupling multiplied by current and the
transient inductance of the machine, which undoes a lot of the cross coupling
that causes issues at high speeds or fast changes in torque. Flux decoupling
will help with integrator wind-up, and stator resistance decoupling also helps
lessen integrator wind-up at low speeds.

3) Have you considered implementing a sensorless algorithm? It can be done
with both FOC or DB-DTFC, although there are some constraints on changing your
switching frequency on the fly. If you have a fixed switching frequency a
common technique is to superimpose a high frequency carrier on top of your
voltage commands and then demodulate the high frequency response in the
currents. Since a BLDC has salient poles on the rotor, this technique lets you
estimate speed even down to zero! Then you wouldn't need encoder/resolver
feedback which would be especially nice for robotics projects.

4) If you really want to get all of the current out of those FETs check out
discontinuous PWM strategies. This are especially helpful at low speeds when
your applied voltage is low, and can lower your switching losses enough to
give you an extra ~40% current rating.

Great work overall. The hardware looks really clean and well designed, and it
is easy to tell you put a lot of thought and effort into the site and this
project.

~~~
madcowswe
Thank you!

1\. Thanks for the suggestion, I have DB-DTFC to my motor control theory
bookmarks. There are a few reasons I am sticking to FOC for now. The main one
is that it is, as you say, the more standard one used, and hence there is more
material on it which makes it easier. The other reason is that I read that you
need high quality current measurement to get a good flux estimate: if your
flux estimators are not high bandwidth, you aren't getting the extra control
bandwidth anyway, and there is no point. The ODrive is trying to be as
inexpensive as possible, hence the current sensors have a fair bit of noise.

2\. Yes the decoupling terms will be added soon, it is something that I know
should be there but wasn't a priority to put in once the motor was up and
running (there is a thousand of other tasks I have to do to get this product
out). The control engineer in me won't rest until all the standard feedforward
terms are there ;D

3\. Yes, I actually implemented a sensorless estimator based on this paper:
[http://cas.ensmp.fr/~praly/Telechargement/Journaux/2010-IEEE...](http://cas.ensmp.fr/~praly/Telechargement/Journaux/2010-IEEE_TPEL-
Lee-Hong-Nam-Ortega-Praly-Astolfi.pdf) It is a non-linear flux estimator, so
it won't work at zero speed. I did look into the high frequency injection
techniques as well, but haven't implemented any of them yet. Right now there
is no sensorless estimator in this instance of the code, and I don't think we
will need one for the basic demos, since they will all require accurate
enocder feedback anyway.

4\. Okay, I'll look into it!

Thank you so much! I actually took the liberty of copying your reply over to
the ODrive forums: [https://discourse.odriverobotics.com/t/control-
suggestions/5...](https://discourse.odriverobotics.com/t/control-
suggestions/54) This is so that I can easier refer back to your excellent
advice even once this HN topic fizzles out. Cheers!

~~~
stevendhansen
Fair point about the quality of the current measurement. I probably take that
for granted because I usually don't have to hit low cost targets! But that
being said, a flux observer is inherently doing some kind of integration which
tends to add a filtering effect. So noisy current sensors may still give you
OK results, especially if comparing FOC with noisy sensors vs DB-DTFC with
noisy sensors.

Ha, I am the same way with feedforward terms. No rest until the integrators
don't budge under the largest command steps!

I will have to keep your site bookmarked. It is rare to see a high quality
motor controller in this space. Most others I have seen are pretty
underwhelming, so kudos on the cool project!

------
MichailP
Can someone more familiar with embedded design explain a bit more on this? Can
this really turn cheap motors into industrial level motors suitable for
hobbyists?

~~~
analog31
Historically, hobbyists have chosen stepping motors because they can be
controlled with a fairly simplistic controller, and there are lots of
solutions out there... check out some of the step motor drive boards at Pololu
Electronics. But stepping motors have limitations, namely speed and torque per
unit motor size. Note that as a hobbyist, I'm still living in the stepper
motor world, so I'm interested in this project.

Brushless servo motors offer the potential for much higher torque and speed in
a small package, but require a different form of electronic control, and the
gist of this project is that such controls haven't been available for
hobbyists. So it's a matter of finding a gap in the existing project / product
space, and filling it.

Note that e-bikes use brushless servo motors, so somebody has done the math on
what motor technology is most efficient. I also think these motors are in
electric cars, and even appliances such as washing machines.

I will be reading with interest. I'll also start keeping an eye out for what
kinds of motors are available.

As for "industrial level," I'd say that it's a matter of pushing machine
speeds up to a level similar to what you might see in a factory. Often, with
stepper motor driven gadgets, you accept the fact that your machine will take
a long time to do anything, but who cares, it's a hobby.

On the industrial side, you very quickly run into the situation where your
motor is no longer the limiting factor affecting speed and precision, but the
design and assembly of the mechanism is.

~~~
jacquesm
Stepper speed can be quite impressive with the right driver, still not up to
servo levels but much higher than you might think possible, it is all about
getting to and past the resonance points in the motor and the whole dynamic
assembly. Once you can do that steppers can run quite fast.

As for torque, servos again have the edge, but there are pretty large steppers
too (1" shaft...).

If you drive steppers with a standard H-bridge you will _never_ get close to
what that stepper can do, driving stepper motors to their potential is a black
art where at some point during the operational domain you'll be taking energy
_out_ of the motor rather than putting it in in order to get past the
resonance point. There are companies that specialize in such high speed
drivers (Berger-Lahr and RTA for instance), they're not cheap and by the time
you're done making this work you might as well install a servo system.

~~~
jbay88
I do motor design and research for a robotics and automation firm. In my
experience, steppers often can provide significantly higher torque than a
similarly sized BLDC. Their reputation comes from their use in low cost
applications, where they are run open-loop and so the load torque must be kept
well below what the motor is actually capable of providing, to avoid missing
steps. Close the loop with an encoder and stepper performance is more like a
geared BLDC. It was a big surprise to me when I first noticed this, because it
didn't align with the reputation that stepper motors had.

~~~
Animats
ShopBots, the big CNC routers, use big steppers with closed loop control, and
get considerable power and speed out of a small motor without missing steps.
Tormach CNC mills are stepper-driven without feedback; the motor is powerful
enough and geared down enough that missing steps isn't a problem.

Steppers do consume full power when not moving, of course, so they're not
favored for battery powered systems.

~~~
ycui1986
The Tormach CNC actually uses a special driver that can detect missing step
without feedback.

~~~
Animats
Shopbot has a closed loop stepper on some models [1], but Tormach says they
don't.[2] Tormach just has a big enough stepper and enough gear reduction to
avoid missed steps by brute force.

[1]
[http://www.shopbottools.com/mProducts/ShopBotdesign.htm](http://www.shopbottools.com/mProducts/ShopBotdesign.htm)
[2]
[https://www.tormach.com/technical_questions.html](https://www.tormach.com/technical_questions.html)

------
fest
I have been following this project since it was published on hackaday.io.
Congratulations to Oskar and the rest of the contributors for getting it to at
least alpha production.

Question: I could not find information on what kind of control modes are
supported- position, velocity, current/force?

Aside: I have previously used another similar product: VESC, which was born as
a driver for electric skateboard motors (Odrive was not available yet). I used
two of them in current control mode with feedback from magnetic encoders.
Since motor current is proportional to torque, it's quite useful control
scheme if the motion equations of the system can be expressed in terms of
force/torque (which most of them are, if you think about it).

One such example is car's accelerator pedal: it controls the torque exerted by
motor, which exerts force against road, which makes mass to accelerate. The
acceleration in turn increases velocity of the car, which in turn changes the
car's position. While this looks obvious after one has thought about it, it
actually means that the common linear control methods (e.g. PID) won't work
optimally (if at all) if you try to control position by changing acceleration.

~~~
madcowswe
Position, velocity and current/force are the currently supported modes, see:
[https://github.com/madcowswe/ODriveFirmware/blob/master/Moto...](https://github.com/madcowswe/ODriveFirmware/blob/master/MotorControl/low_level.c#L168-L187)

Coming soon will also be go-to commands which track 3-rd order polynomial
position trajectories.

------
TaylorAlexander
Glad to see you on HN! I'm an alpha contributor. I can't wait to put this
thing in my brushless robot arm! I still gotta make that forum post. :-D

------
chii
i hate sites that autoplay video, especially if there's audio involved. How
difficult is it to make it only play when the play button is pressed?

~~~
moreati
I use [https://chrome.google.com/webstore/detail/disable-
html5-auto...](https://chrome.google.com/webstore/detail/disable-
html5-autoplay/efdhoaajjjgckpbkoglidkeendpkolai) to address this

------
hla19
Brushless motors are more expensive. There are open source drivers such as
simonk and blheli and they are pretty popular in drone DIY world.

~~~
kawsper
When you mention BLHeli, don't forget BLHeli_S, and (soon) BLHeli_32 which is
a re-implementation written in C (before it was assembler) built to run on
32-bit hardware (before it was 8-bit), but sadly the project is closed source
:-(

------
zkms
The website mentions "supports power regeneration" but I couldn't find any
reference to it inside the code. Can someone who knows about this explain how
it works, both in the hardware and in the software? I'm super curious to be
honest, I know some basic electronics but have never designed a circuit this
complex before.

~~~
stevendhansen
The power electronics are built using MOSFET half-bridges, which naturally
support the ability to flow current in either direction. This allows current
to flow from battery to motor or from motor to battery (regeneration).

In regeneration the motor is actively slowing down the speed (creating
negative torque) by pushing energy into the battery. This is achieved in
software by regulating a "negative" current, which causes the inverter to
produce a voltage that is lower on average than the back EMF generated by the
motor. Because the motor is effectively at a higher voltage than the inverter
in this condition, current will flow from high voltage to low voltage and
therefore flows back through the MOSFETs (and MOSFET body diodes) into the
battery.

This is a bit of an over-simplification as brushless DC motors are actually
excited by an AC waveform so the current is constantly reversing each half
cycle, but the principle remains the same.

~~~
zkms
Ah, so the circuit with the MOSFET bridges is symmetric and can convert in
both directions, and the software is capable of making that happen. That makes
sense, thank you for answering my question in a detailed manner.

As a clarification -- is "back EMF" related to the open-circuit voltage that
the motor generates when it's forcibly spun?

