All posts by Josh Pieper

Voltage mode control for gimbal motors

The moteus brushless controller can drive many motors out of the box, but until now it has been challenging to use with gimbal style brushless motors. They are wound with thin wire so that they have a very high winding resistance, and thus can be driven by inexpensive low current controllers. Using something like moteus with a gimbal motor isn’t absolutely necessary, but does give benefits in terms of high performance trajectory tracking and torque control.

The problem

The primary challenge when using moteus with high winding resistance motors is the mechanism moteus uses to sense current through the motor phases. It has a set of 3 current sense shunts, basically resistors, that have a small voltage induced across them proportional to the amount of current flowing. When commanding a specific current, moteus continually adjusts the voltage on each of the phase windings until the desired current is achieved. These resistors are sized so that moteus has reasonable resolution up to its 100A maximum current rating. When used with a motor that has a maximum current of 1A though, almost all of this resolution is wasted.

In the past I have replaced the sense resistors on moteus boards in order to drive gimbal motors. That is the optimal solution, as it allows moteus to continue to sense the current through the windings and provide accurate torque control. But not everyone is set up to perform surface mount soldering, and accurate torque control at all speeds and temperatures is not required in many applications.

Voltage mode control

As of release 2021-12-03, moteus now has a new configurable option, called “voltage_mode_control”. In this mode, torque commands no longer use the current sense resistors for feedback. Instead, they use the calibrated phase resistance of the motor to derive what voltage would be necessary to achieve a given torque.

The downsides of this approach are that there are many factors that will make the mechanical output torque not match what was intended. For instance, the back EMF if the motor is moving at non-zero velocity, changes in the winding resistance due to temperature, or inductive coupling between the quadrature frames at non-zero velocity. All of these factors will reduce the accuracy of the torque command, so that the mechanical torque output will not match what was commanded. However, for many applications, the motor is not spinning quickly and precise torque control is not required.

Since this control mode takes effect only at the end of the normal moteus control loop, it means that all of the “position” mode control works as before. Thus the constant velocity mode, stop position, and the “within” mode can all be used without regard to whether the controlled motor is running in the normal “current mode control” mode, or in the new “voltage mode control”.

Results

With the new moteus_tool calibration mechanism, this means that gimbal motors can be used in a basic fashion out of the box with moteus by tweaking only a single configurable value: servo.voltage_control_mode. Here’s a video showing how that works with a real motor.

AS5600 support for moteus auxiliary encoders

The initial implementation of auxiliary encoders for moteus supported exactly one encoder, the AS5048B. The hardware can support any I2C based encoder, so supporting additional encoders has always been on the TODO list.

I’m excited to announce, that as of firmware release 2021-12-03, AS5600 encoders are now supported as well. They are a lot cheaper than the AS5048 as they have a much lower update rate and resolution, but that isn’t necessarily a problem if it is only used to disambiguate a modest gear reduction.

I tested this using an AS5600 evaluation board available from digikey:

Improved moteus_tool calibration

To use the moteus brushless controller with a motor, you first have to calibrate it with moteus_tool (for history, see “Encoder autocalibration” and “Auto-tuning current control loops“). This calibration process is primarily used to measure the mapping between electrical phases and the encoder, but as a secondary parameters also measures the winding resistance and Kv of the motor and determines the parameters necessary to set the current control bandwidth.

Motivation

To date, this process can be used with any motor, but making it work can involve fiddling with a number of inscrutably named command line parameters to moteus_tool. --cal-power, --cal-voltage, and --cal-speed are all there, however they don’t really do what you think based on their name, but it is necessary to adjust them to make many motors work.

I went to address this and make the calibration process more robust across a range of motor types, from small high speed motors, to large low Kv ones, high winding resistance, and low winding resistance. All of these can now be handled with mostly no additional options required.

The new process

In the new world, with no additional options, moteus_tool gradually eases up the voltage applied when measuring resistance and when measuring speed, so that it can be safely used with many motors with no additional tweaks. The power expended in the windings is limited to roughly 5W, which is about the only remaining necessary configurable parameter. You’d only need to change that for a very small motor for which 5W would unnecessarily heat it up.

The existing parameters all get new names which more precisely describe what they do. You rarely need to specify any of them anymore, but you can if for some reason you don’t want to trust the auto-detection mechanism.

NewOldWhat it does?
--cal-ll-encoder-voltage--cal-powerThe voltage used when spinning the motor open loop for encoder calibration.
--cal-ll-encoder-speed--cal-speedSpeed in electrical revolutions per second when spinning the motor open loop for encoder calibration.
--cal-ll-resistance-voltage--cal-voltageThe voltage used when measuring the winding resistance.
--cal-ll-kv-voltage--cal-kv-voltageThe voltage used when measuring the Kv parameter.
--cal-motor-powerThis new parameter controls how much power is dissipated in the windings when performing the encoder and inductance calibration with a default of 5W.
--cal-motor-speedThis new parameter controls how fast the motor is spun when measuring Kv with a default of 6Hz.

The old parameter names will continue to work for now and just emit a deprecation warning. Even so, the new parameters should now only very rarely be needed, as every motor I have tested works fine without specifying anything at all.

How to get it?

Just update your moteus python package to at least 0.3.30 and you’ll get all the new features in moteus_tool!

pip3 install --upgrade moteus

Pocket NC Touch Probe Video

I made an overview video for my Pocket NC touch probe integration!

The original write ups can be found at:

And the designs and source code can be found at:

I’m planning on making a batch of these for sale. If you want to find out more, fill out the survey at: https://forms.gle/SwVfNPBuj1oVYPQK8

Sousaphone sound-reactive lights

Blinking lights is something that I guess I’ve been enamored with for a while – see 2001 dorm (with awesome work from Brad on visualizations), 2007 bike, and 2015 trumpet. When I got a last minute opportunity to play sousaphone at this year’s HONK fest with Brassterisk I figured I needed something to dress up my otherwise rather drab horn.

The “control board”
Light installation on bell

It is just a Teensy 4.0 I had lying around, together with an audio board, a basic lav mic, and a spare 74XX245 from my grab bag held together with hot glue and proto wire. It drives a cheapo 300 LED RGB strip that is VHB’d to the bell. I think the LEDs will only last a few more transport sessions, but with any luck I’ll make a slightly more polished revision with better longevity in the not too distant future.

Behold, lights:

Pocket NC Touch Probe – Software (Part 4/4)

This is a series, check out the previous posts at part 1, part 2, or part 3. This time, I’m going to make this probe hopefully do something.

I started out just verifying that the Pocket NC would treat the vers.by probe the same as the built in tool setter probe. So I ran a tool measure cycle, and then just tweaked the probe by hand. Woohoo! It stopped the cycle just like normal. Actually measuring a tool worked too if the probe wasn’t activated, or if it wasn’t plugged in. Success.

Probing Scripts

Next, I got a crash course in G-Code. Mostly I used the Linux CNC reference, since that is what the Pocket NC used and all I needed to be interoperable with. Having done no real manual G-Code programming before aside from my limited python auto-generation, I was I guess surprised that there was any real support for in-program scripting. The fun limitations:

  • Variables can either be “numbered” or “named”. 30 of the “numbered” variables are function local, (and are also necessary for argument passing), and all the remainder are global variables. “named” variables can be global or function local.
  • All control flow requires human assigned unique integers for each instance of that control flow construct. i.e., an “if-else-endif” chain requires a human assigned integer that is unique script wide to be applied to the if, and its matching elses and end-if statements.
  • Largely, subroutines need to be in a file by themselves, and all in the same directory.
  • Annoyingly, expression grouping is with square braces “[]”, not parentheses, “()”.
  • “comments” are overloaded to also be used for all “non-machine” operations. If you want a comment to actually be a comment, the best and seemingly standard way is to ensure all comments are prefixed with a space.
  • Some things can be indirected natively, but not for instance, “which axis to move”. That must be specified using a literal character in each command.

The first probing function I needed was to reference the outer diameter of a cylindrical feature. I started by writing a subroutine which would perform a single linear probe in a parameterizable axis. It first probes quickly, then backs off a bit to probe again slowly. To work around the lack of axis indirection, it just uses if-else chains to handle the X, Y, and Z axes.

https://github.com/jpieper/pnc_probe/blob/main/gcode/pnc-probe-xyz.ngc

Next, I used that in an cylindrical feature probing script, where you manually position the probe along one of the major axes at the proper Z probing depth, assuming that the feature is “roughly” at the center of the current coordinate system. It would then probe all 4 axes, finally setting the coordinate system 0, 0 to be the center of the feature. For this, I “simulated” some arrays using the 30 numbered function local variables so that the probing logic could be implemented in a loop.

https://github.com/jpieper/pnc_probe/blob/main/gcode/pnc-probe-center.ngc

This did the trick, and now I could reference cylindrical (and square) features using G54.

Repeatability

I ran this around 30 times over the course of a few hours, including remounting the probe a few times and changing the temperature and airflow to get an idea of the repeatability of the probing process.

AxisStandard DeviationPeak to Peak
X0.00031″ (0.0079mm)0.0012″ (0.030mm)
Y0.00044″ (0.0112mm)0.0015″ (0.038mm)
Probing Repeatability

So, roughly around 1 thousandth or 0.02mm of absolute repeatability. I might be able to improve that by tweaking the probing speed or otherwise adjusting parameters, but the Pocket NC itself isn’t a whole lot better so it should be “good enough” for now.

Next Steps

First, all of the work I have so far is publicly available on github: https://github.com/jpieper/pnc_probe

This project is at a functional point for myself, but isn’t quite ready for others to use. The biggest issue is the necessary modifications to the shaft of the vers.by probe, as they aren’t easy to do and require additional equipment. The other pieces also still have some rough edges that should be filed off, including keeping chips out of the RJ45 connectors and getting a PCB in that doesn’t require bodge wires to work.

I also intend to do a little work to demonstrate that the probing can be used to register features across operations properly.

My eventual goal is to eventually get the design to a state where it is nearly “off the shelf” and list it on tindie. To do that will depend upon if I can figure out a better solution for the probe shaft.

Pocket NC Touch Probe – Electrical (Part 3/4)

In part 1 and part 2, I covered my motivation and the mechanical hardware behind a touch probe add-on for my Pocket NC V2-50. In this post, I’ll cover my prototype electrical hardware.

My intention with the probe was to connect it logically “in parallel” with the existing tool setter probe that the Pocket NC has. I figured that would be likely easiest to integrate with the Linux CNC scripts when I got to the software point. The existing tool setter probe is located in the rotating B axis. That is connected to the Y axis via a single CAT5-ish cable, so my hope was that I could devise something which would pass through the necessary signals on that cable while also paralleling in the new touch probe.

To start, I acquired some RJ45 to .1″ header breakouts from Amazon and broke open the bottom of the Pocket NC B axis table, and wired up a pass through on a breadboard:

Using a multimeter to probe around, it was pretty obvious the first 4 pins went directly to the B axis stepper motor. Of the remaining, 5 was pretty obviously ground. Slightly confusingly, the one that had 3.3V on it appeared to be a pullup for the open-drain normally open tool setter, while the pin with 2.8V on it was the power for tool setter and the B axis hall effect homing sensor. The one remaining pin was the output of the B axis homing sensor.

There were a few electrical challenges here. The first was that the vers.by probe needs 5V, not 2.8V. To begin with, I just wired in 4 AA batteries, and for a longer term solution I picked up a 5V charge doubler from digikey, the TPS60241.

The second required a fair amount of thought: how to make the normally closed vers.by probe act “in parallel” to the built in tool setter, while still being able to disconnect the probe and maintain tool setter functionality. Just inverting the normally closed signal would result in something that made the tool setter appear to be always activated whenever the touch probe was disconnected.

Here, I relied on a design artifact of the vers.by probe. The “USB cable” connector had both D- and D+ connected together, but in the probe itself. So if the probe or cable were disconnected, those two nets would have no connection. Thus I pulled one high, and pulled one low. Then the three states I cared about looked like:

D-D+
Probe Disconnected01
Probe Connected and Inactivated00
Probe Connected and Activated11

I used a 74HC series NAND gate to only activate a parallel N-FET in that final case, where the probe is connected and activated.

I breadboarded this with the 4 AA batteries, then did a proto-board implementation that used the 5V charge pump too. I was going to use the same SMT components on the proto-board implementation, but the NAND gates, despite being labeled as the same 8VSSOP package as the charge pump, and both from TI, turned out to be a package that was too small for me to “dead bug” solder. So, instead I just flipped over the DIP package NAND I had and wired that up.


The charge pump wired up under the microscope
The final “proto-board”

Then using some cardboard, hot glue, and a zip tie, I fastened it to the back of the A axis stepper motor on the Pocket NC:

Before I was able to really test this well, a PCB from OSHPark came in, so I used that with a 3D printed enclosure:

Next up, making it actually do something!

Pocket NC Touch Probe – Mechanical Hardware (Part 2/4)

Last time in part 1, I talked about why I wanted to add a touch probe to my Pocket NC. This time, I’ll cover the basic hardware necessary to make it happen.

I decided to start with an inexpensive probe so that as I was figuring things out, I wouldn’t be too sad if I smashed it a few times. I’ve seen a number of other hobby machinists use the “vers.by” probes, so I decided to give them a try too.

This probe requires 5V-24V power, has a 6mm shank, and provides a NPN-NC output with a USB connector as the physical connector. Note, it isn’t USB, but just uses that connector for power and the signal.

Mounting

To start with, I needed to get the probe such that I could mount it in the spindle of the Pocket NC. The V2-50 I have can handle a 4mm shank at most, and that is what I primarily use. Obviously, 6mm is bigger than 4mm, so something needed to be done.

So, I wouldn’t be a quality engineer if I didn’t have the brand new toy disassembled within hours of receiving it:

What I ended up doing was turning down the 6mm shaft to 4mm on one of the Artisan Asylum’s manual lathes.

This was pretty challenging. First because the shaft was already permanently mounted into that relatively thin base section, so getting the part trued up in the chuck took some time. Second, because it sticks out so far, I could only take excruciatingly light cuts. In hindsight, I should have worked harder to get the opposite side supported. The entire operation took something like 3 hours. However, when done, I had a probe with a 4mm shaft!

And hey, it fits!

After a bit of tuning with my 2 micron dial indicator, and the provided adjustment screws, it seems to pretty dialed in.

Pocket NC Touch Probe – Motivation (Part 1/4)

When machining, you need to accurately position the cutting tool with respect to the workpiece. With the stock Pocket NC, there are two methods for doing so. The first is to rigidly locate the workpiece with respect to the B axis reference point using a fixture. The second, is to do manual touch offs. Nearly all of my work so far has relied on the former method, as using a manually touch off on a machine without manual controls isn’t all that precise or pleasant. And while possible, it is tedious to touch off against features more complicated than a single edge.

My Approach So Far

To make that first approach work, I’ve been making 3D printed fixtures (1, 2, 3, etc) to hold the work while simultaneously registering it to the mounting holes or alignment pins on the B axis. Simultaneously, I need to keep the machine well calibrated so that the X, Y, Z, A, and B offsets are all aligned as closely as possible to the center of rotation of the A and B axis.

About the best alignment I’ve achieved between calibration and my fixture is about 50-150 micrometers (2-5 thousandths of an inch). So for any parts or features which need relatively alignment better than that, I need to design it such that all the features can be completed in a single operation without moving the A or B axes.

To date, all the parts for the qdd100 servo were designed with that constraint in mind, so that I could prototype them locally. The rotor and stator need to be aligned with precision approximately 25-50 micrometers, and there are multiple pieces involved in maintaining that alignment, all of which need to be machined accordingly. However, designing the assembly to satisfy those constraints made actually assembling it a relatively time consuming operation, which I would like to improve.

Touch Probes

A third method of workpiece locating, not mentioned above because the Pocket NC doesn’t support it natively, is with a touch probe. A touch probe, is a stylus mounted in the spindle like a tool, which can detect when it is deflected in one or more axes. Then the machine can move the spindle around, and sense where the part is located with respect to the machine coordinates directly.

In this series, I’m going to explore adding a touch probe capability to my Pocket NC. We’ll see how it goes!

Fixing a chip evacuation problem on the Pocket NC

My Pocket NC v2-50 is a fine machine for its size class, but there are still plenty of annoyances. One of them is that chips can accumulate places they shouldn’t, either during a run, or over the long term.

There is a cavity near the back of the machine where the Y axis cables and cable guide retract into. That cavity is exposed to chips flying around, so they tend to accumulate there. There is a hole in the bottom of the machine where the chips could maybe fall out, except the hole is too small for any but the smallest of chips, and further, it is completely sealed off when mounted in the stock Pocket NC enclosure.

Basically every time I’ve taken the machine out of the enclosure, I’ve found that cavity so packed with chips that you wouldn’t think the cables could even more anymore. That is even with a thorough vacuuming after every part and often every operation. Plus the Y axis cables are just ethernet cables, which means once you unplug them, those chips can easily fill the RJ45 jacks.

While replacing a failed cable chain, the always responsive Pocket NC support team mentioned that some customers had machined an extra hole in the back of the housing to allow for cleaning that cavity out. Why didn’t I think of that! I did mine with a hand drill and dremel, assuming it would be faster than either disassembling the entire machine or fixturing it assembled into a manual mill. While that was probably true, it was still a painful process.

Despite the pain and the unpolished finish, the end result seems like it will have the desired effect.