Close
0%
0%

Mechaduino

Mechaduino is an affordable, open-source, industrial servo motor. Position, torque, velocity, and custom modes. Arduino compatible.

Similar projects worth following
Engineers use servo motors to achieve the precision motion required in applications such as robotics, automation, and CNC manufacturing. Like RC servos, industrial servos actively correct for external disturbances. Unlike RC servos, industrial servos can provide very accurate motion, and often support advanced motion control modes. Unfortunately the cost of industrial servos is prohibitive to the individual maker (thousands of dollars per motor).

We've been developing an affordable open-source industrial servo motor, opening the door to sophisticated mechatronics applications. Our design leverages the low cost of mass produced stepper motors. We are able to achieve very high resolution via 14b encoder feedback (after calibration routine!). For more information, including demos of our working prototypes, check out the external links (below to the left).

Kickstarter campaign successful!

Missed the Kickstarter? Mechaduino is available for pre-order here!

Goals: (in no particular order)

  • Position, velocity, torque loops
  • Step & direction inputs for drop-in compatibility with stepper motors / step stick
  • I2c, serial inputs
  • Customizable/open source with access to internal variables
  • Transparent and user-definable control algorithms (commercial servos often lack this)
  • Arduino compatible with easy to use interface
  • High resolution pointing (sub 0.1 degree)
  • Low cost (should not be a huge leap from stepper+stepstick cost)
  • Serial interfaces for inter-motor communication
  • On-board processor allows for stand alone for simple applications
  • Adjustable commutation profiles
  • PID auto tuning
  • Anti-cogging capable
  • Open to customization. Outside of our firmware, we see Mechaduino as a very useful hardware package. If you would like to use the stepper motor in open loop mode w/ encoder to verify location, you can do that.

We also see could see Mechaduino as an educational tool. Since all the hardware is on one board (sensor, processor, motor driver), set up time is very low, and students can focus on playing with the controller.

Mechaduino 0.1 Hackaday Prize Video:


Mechaduino 0.0 Prototype:


Strategy:

An industrial servo motor can be broken down into four main components (below). First we looked at each of these components and tried to piece together an affordable breadboard-level prototype. After some experimentation, we were able to distill out a working lineup of components. From there, we've been iterating on our design, working out all the kinks, and tuning the control loops. It's starting to come together!

...Back to those four main components:

1) The actual motor, usually of the brushless dc variety. When you look at industrial servo motors, a big chunk of the cost is the motor itself. They are often custom built, or at least built in limited quantities, which means $$$. Watt for watt, I'd guess that a mass produced NEMA 17 or NEMA 23 stepper motor is between a tenth and a hundredth the cost of the BDC motors used in industrial servos. Although their design is optimized for "stepping," stepper motors are really just 50-pole brushless dc motors. They can be controlled exactly like a more traditional 3 phase BDC motor with more poles. So that's the plan. It's working!

2) A sensor for feedback, usually an encoder. Optical encoders are pretty standard, but get quite pricey if you want high resolution and/or absolute position information. We were intrigued by some of the cheap, high resolution magnetic encoders offered by vendors like AMS. It turns out that although they claim 12 and 14 bit resolutions (that's 0.09 and 0.02 degrees respectively), they suffer from non-linearities on the order of a degree or so! However, we found that this non-linearity is very repeatable, and we were able to develop a quick, self contained (on motor) calibration routine that restores resolution to better than 0.1 degrees. (More on this later. This was a significant design effort and is worthy of its own build log!)

3) Drive circuitry/power electronics to excite the motor windings. Many industrial servos use discrete H bridges. Each phase requires it's own H bridge ( for a two phase motor... half bridges for each in a three phase motor), which consists of at least 4 if not 8 (...including freewheeling diodes) discrete switching devices. Throw in gate drive circuitry, and things start to get expensive. We hoped to find a single-chip, integrated solution that would allow for current feedback, and we found just that in the A4954 dual full bridge PWM driver.

4) Control Electronics. Usually a microcontroller or FPGA. Early on, we decided that Arduino compatibility was a must in order to make the firmware as accessible as possible. We chose to use a SAMD21 ARM M0+ (Arduino Zero compatible) processor to balance cost and performance. Our breadboard prototype system verified that this processor was more than capable of executing the necessary algorithms....

Read more »

Adobe Portable Document Format - 1.51 MB - 01/02/2017 at 21:42

Preview
Download

Mechaduino01.sch

Eagle schematic

sch - 2.46 MB - 04/22/2016 at 19:35

Download

Mechaduino01.brd

Eagle board

brd - 858.11 kB - 04/22/2016 at 19:35

Download

Mechaduino_01_Schematic.png

schematic image

Portable Network Graphics (PNG) - 174.33 kB - 04/22/2016 at 19:35

Preview
Download

  • 1 × ATSAMD21G18 Arduino Zero compatible uC
  • 1 × AS5047 14bit absolute magnetic encoder
  • 1 × A4954 Dual full bridge PWM driver
  • 1 × Stepper motor NEMA 17 or other w/ adapter
  • 1 × Magnet: Diametrically Magnetized NdFeBr We are using a D42DIA from K&J Magnetics

View all 7 components

  • Hardware Available & New Firmware!

    jcchurch01/04/2019 at 19:48 1 comment

    After dealing with some parts shortages in 2018, We've finally completed another batch of Mechaduinos!

    Fully assembled Servos are now available here!  PCB kits are available here!

    We also released an update to the firmware!  The calibration table can now be stored in flash memory!  The Mechaduino Manual has also been updated (links below).

    Quick Links:

  • Mechaduino 0.2 PCBs Available

    jcchurch05/06/2017 at 06:55 1 comment

    The updated Mechaduino 0.2 PCB kit is now available for purchase here. A list of updates is available in the latest version of the Mechaduino Manual, and all source files are available on Github.

  • Update!

    jcchurch04/09/2017 at 22:44 0 comments

    We have another batch of Mechaduinos in production that will be available for purchase on our website in a few weeks. Sorry for the delay. We decided to add a couple of improvements to the boards which slowed things down a bit. We will be posting details about the improvements shortly in an updated version of the Mechaduino manual. We'll upload the updated source files to github as soon as we've polished them up.

    -Joe

  • Improved firmware released

    jcchurch11/25/2016 at 19:13 0 comments

    Hi all,

    We've uploaded a significantly improved version of the Mechaduino firmware. It is available here (master branch of our repo). Older versions of the firmware are still available here and here.

    Improvements include:

    -Menus now work!
    -Faster control loop (running 6kHz by default)
    -Ability to adjust PID gains from menu (does not use non-volatile memory yet, so you do have to update firmware for permanent changes, but this makes tuning a lot easier).
    -Generate sine/commutation table on startup, this makes it easy to experiment with different commutation profiles
    -Lots of documentation in code
    -Much cleaner code ( no more "magic" numbers, etc)

    We are almost ready to release a Mechaduino Manual that covers hardware, firmware, and example code. Please stay tuned!
    -Joe

  • CW & CCW Pins Example

    jcchurch11/22/2016 at 01:51 2 comments

    Here's a quick example showing one way to configure two digital IO pins to control the Mechaduino. Pull pin 2 low and the Mechaduino moves CW, pin 3 and it moves CCW:

    First, run the calibration routine and copy the lookup table in to parameters.cpp.

    Next, add the following code in the bottom of the setup function in Mechaduino.ino:

        pinMode(3,INPUT_PULLUP);  //pin for + direction
        pinMode(2,INPUT_PULLUP);  //pin for - direction 
        
        enableTCInterrupts();     //start in closed loop mode
        mode = 'x';

    ...and then enter this code in the loop:

    void loop()
    {
      if (digitalRead(2) & !digitalRead(3)){
        r+= 0.01;
      }
      else if (digitalRead(3) & !digitalRead(2)){
        r-= 0.01;
      }
      delayMicroseconds(5);
      //serialCheck();  
      //r=0.1125*step_count;
    }

    In this example we use the position mode 'x', and increment/decrement the setpoint based on the pin state. You could also use the velocity mode 'v' and set the setpoint to a velocity based on the pin state.

  • Position loop example: setting angle in code

    jcchurch10/25/2016 at 23:18 1 comment

    Here's a quick example demonstrating how to change the setpoint of the position control loop:

    This motion was implemented as shown below. "r" is our global setpoint variable. Since the control loop is implemented using interrupts, you don't really have to worry about it in your main loop once it is enabled!

  • Mechaduinos in the wild?!

    jcchurch10/09/2016 at 12:01 0 comments

    If you ordered Mechaduino hardware through our Kickstarter, you should receive your reward any day now (If you haven't already)! Sales from our website should start to appear next week! We've also heard from quite a number of folks who couldn't wait and built there own! If you would like to share your Mechaduino applications or design modifications, please feel free to post below in the comments!

  • Shipping Kickstarter Mechaduinos!

    jcchurch10/01/2016 at 05:29 0 comments

    We began shipping our Mechaduino Kickstarter rewards this week!

  • Step/Dir Interface Demo

    jcchurch09/15/2016 at 13:07 2 comments

    I've created a little video demonstrating one way to configure a Mechaduino to work with the popular RAMPS 1.4 3D printer shield. Check it out:


  • Automation!

    jcchurch08/21/2016 at 21:31 0 comments

    From the beginning, we have seen Mechaduino as a way to make motion control for automation accessible. Industrial motion control systems are pretty far outside of the budget of most makers and small businesses. By creating an open source servo motor that is affordable and programmable in the familiar Arduino environment, we hope to give makers a powerful tool to design their own automated systems.

    As a simple example, here's how we used a Mechaduino to help us automate the assembly of (you guessed it!) Mechaduinos! For each motor, we need to replace the stock screws with our custom screws/standoffs. This fixture helps to streamline the process. Though simple, we estimate that this fixture saves us about 10 seconds per motor... that adds up when you have to repeat a process 1000 times!


View all 26 project logs

  • 1
    Step 1

    OVERVIEW:

    Here are some preliminary instructions on how to get your Mechaduino up and running.

  • 2
    Step 2

    ASSEMBLY:You will need to mount the magnet to the back of the motor shaft. Note: the magnet must be diametrically magnetized, as opposed to axially magnetized. The magnet may naturally stick to the shaft, but we recommend a dab of epoxy or super glue to hold it in place. The magnet should be fairly centered, but the calibration routine will correct for minor misalignment.

    The Mechaduino PCB must be mounted so that the magnet is directly under the encoder chip (Very close but not touching. See the AS5047 datasheet for details). We replaced the standard motor hardware with M3 threaded rods and short standoffs to mount on our Mechaduinos, but there are other ways this could be done.

    When wiring your motor up to the Mechaduino board, please make sure that one phase is connected to ouputs 1&2, and the other phase is connected to phases 3&4.

  • 3
    Step 3

    BOOTLOADER:

    You will need to make sure your Mechaduino has the latest Arduino Zero bootloader. If you are getting a Mechaduino as a reward from our Kickstarter, it will already have this! Otherwise you will need an Atmel-ICE or similar SWD programmer...

View all 8 instructions

Enjoy this project?

Share

Discussions

Deep-Thought wrote 06/02/2016 at 08:40 point

Wow, this is truly amazing.

How would one go about integrating this in a existing CNC setup?

I guess a stepper driver compatible interface could be done for a drop-in replacement.

But I guess there are gcode engines out there already who can drive servo style motors? In opensource of course...

  Are you sure? yes | no

jcchurch wrote 06/02/2016 at 21:15 point

Right now you can use the Mechaduino as a drop in replacement for stepper drivers & motors (it takes step and direction pulses).  It also has serial, i2c, and soon SPI interfaces.  Since all the firmware can be edited in the Arduino environment, it's easy to create a custom interface/protocol if you have something else in mind.

We are trying to make the Mechaduino as versatile as possible.  If there is some other interface you would like to see us support, please let us know!

  Are you sure? yes | no

Deep-Thought wrote 06/03/2016 at 07:46 point

I think step/direction pulses are actually the most important interface. Glad to see that this is already supported.

Not because it's cool. But because it allows running it in legacy environments.

I suppose modern CNC machines have some kind of servo protocol. IIRC the good ones do closed loop these days. I wonder if they stayed with step/direction pulses for modern applications.

Not my industry. Just a thought...

  Are you sure? yes | no

palantux@gmail.com wrote 06/02/2016 at 06:31 point

Kickstarter is a great idea. I'm in. You could include only the card in the kickstarter project? Regards 

  Are you sure? yes | no

Domen wrote 05/29/2016 at 16:34 point

This is an amazing project!
If only one could get cheap NEMA stepper motors from china :s 

  Are you sure? yes | no

jcchurch wrote 05/29/2016 at 19:07 point

Thanks!

If there is enough interest, we are hoping to run a small kickstarter and sell the whole Mechaduino (with a decent stepper motor) for around $50.

  Are you sure? yes | no

Trevor Johansen Aase wrote 05/28/2016 at 12:27 point

Have you made a test jig to measure positional repeatability yet? If you mount it to a board with a surface deviation gauge and cycle into the gauge 1000x  you should get a pretty good idea of accuracy. Also are you able to retain the 1.8deg positioning? From the code and the CPR number it looks like you increased resolution.

  Are you sure? yes | no

jcchurch wrote 05/29/2016 at 19:05 point

Hi Trevor,

CPR is our encoder "Counts Per Revolution": 2^14 or 16384.  Our closed loop position control actively forces the motor to move until the correct encoder position is reached.  This gives a resolution of 360 degrees/ 16384 = 0.02 degrees.  So yes, we've increased the resolution considerably! Thanks to our calibration routine, the accuracy should be close to the same (we're going to measure this soon).  

We have measured repeatability by stepping into and out of full step positions in open loop mode 1000x and looking at the distribution of encoder readings (similar idea to what you recommended).  The results look promising:  I don't have the data in front of me, but the error distribution appeared to be Gaussian with zero mean, and a standard deviation of less than 1 LSB (0.02) degrees.  I'll post this data soon.

Thanks for your suggestion!  We're looking to get a really accurate, high resolution encoder for a test jig to measure the Mechaduinos accuracy at all encoder increments, not just one position.

-Joe

  Are you sure? yes | no

Trevor Johansen Aase wrote 05/30/2016 at 03:52 point

Very interesting indeed. I am working on a remote telescope robot and need a minimum of 4,000 step resolution but >10,000 would be phenomenal. Being able to drive the axis via SPI in a single mount solution is my ideal goal.

I see an automated BOM in "Mechaduino01.txt" do you have a Mouser/Digikey parts list? Thinking about selling beta boards via Tindie (boards & components)? Or even just keeping an updated design on OSH Park so it's easy to order?

  Are you sure? yes | no

jcchurch wrote 05/31/2016 at 19:25 point

That's awesome!  I actually had a telescope pointing application in mind myself!  The Mechaduino can be controlled via I2C, UART, step/dir, and we're working on implementing SPI.  The hardware is there, we just haven't finished the code.


If there is enough interest, we're hoping to run a small kickstarter and offer the whole Mechaduino (with a decent stepper motor) for around $50.   To keep the price down, it makes a lot of sense to order the boards/components in quantity.  Eventually we hope to make the boards available on tindie/our website/some other outlet.

Thanks for your interest!

  Are you sure? yes | no

penelopeblue330 wrote 05/01/2016 at 05:26 point

Lovely project! Just wondering how are you coupling the shaft to a magnet? And do you need dual shafts (the shaft is long enough to extend from the back of the motor)?

  Are you sure? yes | no

jcchurch wrote 05/02/2016 at 04:32 point

Thanks!  You do not need a dual shaft stepper, just one with an exposed rear shaft.  The magnet naturally sicks to the shaft, but a dab of epoxy makes it a little more permanent.  

  Are you sure? yes | no

ottoragam wrote 04/25/2016 at 23:17 point

Nice project, guys! I've been designing my closed loop motor controller too (for bigger, brushed DC motors), and I also started to use those magnetic rotary encoder ICs. I've yet to test for repeatability of the magnetic encoder feedback, it is awesome to know that it is doable :)

  Are you sure? yes | no

jcchurch wrote 04/26/2016 at 00:56 point

It is doable, but watch out for the non-linearity spec.  It's hidden pretty deep in the datasheet, but out of the box, all of these sensors have a non-linearity of up to a degree or two.  This error is sinusoidal in nature and seems to be very repeatable.  I've been able to successfully calibrate encoder readings to motor full-steps and get most of the resolution back (more on that in an upcoming build log.)  These devices are pretty cool, but if you need sub-degree accuracy, you will need to calibrate them.

Cool project by the way!

  Are you sure? yes | no

ottoragam wrote 04/26/2016 at 03:35 point

I'm looking forward to that build log! Hopefully in the mean time I can make a test jig to check the positioning error of my motor. BTW, thanks for following my project!

  Are you sure? yes | no

AmorphousEngineer wrote 04/25/2016 at 20:34 point

jcchurch,

Do you have issues with the  electromagnetic coils in the stepper motor interfering with the AS5047? I would assume the AS5047 would need to be farther away from the stepper motor.

Thank you for publishing your work! It looks awesome!

  Are you sure? yes | no

jcchurch wrote 04/26/2016 at 00:47 point

This was a concern of mine as well.  I think there are really two potential issues here: 

1) High frequency EMI noise due to the high frequency coil switching.
2) Low frequency biasing of the encoder reading due to the coil excitation state.


The good news is that neither seem to be a problem.  

I just ran a simple test to try to quantify the first case.  I collected 1,000 encoder readings with the motor stationary and the windings off, and then 1,000 readings with the windings on (but constant excitation phase).  The noise in the readings was about the same for both cases. I calculated a standard deviation of 0.0118 degrees power off, and a standard deviation of 0.0131 with power on.  13 ten-thousandths of a degree is pretty small.


I haven't been able to come up with a great way to measure the second case yet.  However, I can say that the effects can't be too large:  In playing around with the system, I've found that if the phase excitation angle is off by more than a couple tenths of a degree, the motor does not run properly.  Since I've been able to get reliable performance out of the system, I'd say that this isn't a big issue.


Why isn't interference an issue?  By design, the motor's magnetic structure keeps the coil's fields pretty well constrained. Also, AMS claims to have some fancy techniques that make their encoders "immune to stray fields."  How they do this, I'm not sure.

Thanks for asking!

  Are you sure? yes | no

jcchurch wrote 04/22/2016 at 20:10 point

I'm just beginning to post information on the Mechaduino project here.  Stay tuned for more details!

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates