The moteus line of brushless motor controllers currently require a CAN-FD host to send commands in order to actually execute a motion profile. moteus has long provided a python library that can be used on desktop operating systems to send commands and parse responses, and recently added a C++ one as well. Next up, and described in this post, is a library for Arduino which provides the ability to command and monitor brushless motors using moteus motor controllers.
I’m impatient! How do I use it?
Just open the Arduino library manager and search for “moteus” and install. Then you can open one of the examples and modify it. ”WaitComplete” is a good one to get started with.
What is supported?
The library now supports many Arduino compatible boards and CAN-FD expansions that use the MCP2517FD or MCP2518FD CAN controllers. Anything that the acan2517FD library supports is fair game. It has been observed to work with:
There are two pieces of configuration that are board and controller specific that must be specified when setting up the library. First, the pin assignments and SPI peripheral must be passed to the ACAN2517FD constructor. That can be derived from the pins you used to connect the CAN-FD controller.
Second, you need to match the CAN-FD base clock rate that the board uses. The CANBed FD uses a 20MHz clock, which is what is set in the example. The Mikroe MCP2517FD Click defaults to a 40MHz clock, but can be configured by jumper. In any case, you need to pass the clock rate that your board in to the ACAN2517FDSettings object.
Caveats
The biggest caveat is that some operations with moteus still require a desktop computer with a standalone CAN-FD adapter, notably calibration and interactive modification of configuration. That means while Arduino can be used once a system is commissioned, you will need at least one desktop compatible adapter to perform provisioning operations. The fdcanusb from mjbots (included in each devkit) is a hassle free way to get that.
The Mikroe MCP2517FD CLICK and possibly other boards do not have onboard termination. A CAN-FD bus is specified to require a 120 ohm terminating resistor between CANL and CANH at each end of the linear bus. Most short busses will operate with only one end terminated, and as the fdcanusb has a built in terminator, with that often nothing else is required. However, with an Arduino shield or adapter that does not have an integrated terminator, an external one is required. You can crimp a 120 ohm resistor into a JST PH3 connector, or get a pre-built PH3 CAN-FD terminator from mjbots.
With some smaller Arduino platforms, notably the Arduino Uno or Longan Labs CANBed FD, the combination of the ACAN2517FD library and the moteus library can consume a significant fraction of the flash and RAM available. For simple applications this isn’t a problem, but if you want to execute something more complex, you may be better served using a more capable Arduino compatible processor, like a Teensy 3/4 or a Nano Sense 33.
Video
See it in action here!