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 »

MechaduinoManual.pdf

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

Preview

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

  • 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

Xasin wrote 09/18/2019 at 11:29 point

Ohhh, good stuff!
I'm really glad you guys chose to make this open source, because this type of motor + controller is extremely useful (as you already figured :P)

I'm definitely gonna try and build one myself! 

I'm wondering though, why didn't you use a Trinamics stepper driver?
They have a lot of the features implemented in-hardware, such as current and torque sensing, and can be configured via SPI, which would offload the work from the MCU. Then again, your approach seems to be working just as well, so keep it up! 

Other question: Is there any chance the system can be adapted to use three-phase drone BLDC?
I'd imagine it'd require a fairly big rework of the motor driving and current sensing, so I'm guessing not for now.

  Are you sure? yes | no

evanyunartha12 wrote 09/14/2018 at 12:30 point

Hi this is great project. Can it used EMF Monitoring ?

  Are you sure? yes | no

Thomas Pointhuber wrote 10/21/2017 at 17:18 point

I developed a derivative of the original Mechaduino: https://hackaday.io/project/27823-highpower-mechaduino.

It can drive stepper motors up to 500W, and includes some nice improvements based on the original design.

  Are you sure? yes | no

artkiver wrote 02/06/2019 at 20:28 point

Very cool branch! It looks as though the uStepper team probably also derived some inspiration from this.

Has anyone attempted to utilize a RISC-V core in something similar? At the moment it seems as though most of the FOSS stepper motor controllers are still using ARM, and there are RISC-V Arduino compatible boards for under $100USD now (circa early 2019 for spacetime venturers who may be reading this from a vantage of excessive latency), and Linux compatible ones for closer to $1000USD. I see there are some Arduino powered CNCs for about $150USD, and presumably overhauling their servo motors with Mechduinos or something else FOSS with a closed loop error detection/correction would be an improvement as a minor upgrade, but RISC-V iterated Mechduinos seem potentially even more open/easier to reuse/relicense/etc. in the future.

If no one else does it, then I will explore it myself and share what I come up with, though it may be a while at the moment I am still primarily in the research phase of the CNC overhaul project.

  Are you sure? yes | no

David wrote 10/08/2017 at 00:10 point

Well got every thing working is there any special stuff i need to do after setting up step and dir.

I am using it on a makerbot 2x for the extruders (no more skipping :) )

  Are you sure? yes | no

gumush wrote 10/03/2017 at 06:53 point

hi , thats a great project. We want to use it with nema 34 high current motors. We already have drivers that accept classical step and direction input. Is there any way to get this data from mechaduino to work with external driver ( that will be great for really adaptable version of mechaduino for existing driver)

  Are you sure? yes | no

manuela ceron wrote 07/31/2017 at 13:54 point

Hi! How can this be implemented with a n linear optical encoder?

  Are you sure? yes | no

Daniel Collins wrote 05/14/2017 at 09:30 point

Is there a control mode whereby the stepper shaft can spin freely with no resistance ?

  Are you sure? yes | no

John Seiler wrote 03/30/2017 at 21:59 point

How much does the board weigh?  For a 3d printer, I'm curious it it would make sense to drive a small motor on a direct drive extruder for more precise extrusion or use a bigger motor open loop instead.  I have a feeling that a small motor driven efficiently would be better and overall lighter.    Regards and thanks!

  Are you sure? yes | no

JimmyK wrote 03/05/2017 at 07:34 point

Hi, this is great project. i make out by my own. but the calibration lookup table is too big...  cause the firmware overflowed by 137840 bytes... (samd21 only have 256k flash)... i have no idea how to resove this problem... who can help me?

  Are you sure? yes | no

Duke Circuit Co.,Ltd wrote 03/05/2017 at 03:15 point

It's a  helpful and valuable project,as a printed circuit boards manufacturer

 and PCB Assembly factory,we wish can do something for you,would glad to provide the free PCB Prototype and PCBA Prototype for your further research.

  Are you sure? yes | no

Dan Royer wrote 02/27/2017 at 21:27 point

Hi!  I've read your current github code.  I don't get how you're doing the adaptive behavior (letting a person turn the shaft).  How do you determine when a human is interfering?  how do you separate that from the torque of, say, gravity, or some other object attached to the shaft?  Thank you!

  Are you sure? yes | no

M.Frouin wrote 02/24/2017 at 13:49 point

Why not using driver A4988 or DRV8825 please?

  Are you sure? yes | no

Luke Weston wrote 12/30/2016 at 09:58 point

In a step/direction retrofit application, I assume the servo will fail to work properly unless the position loop tuning is good enough to keep the settling time very short - shorter than the step input period.

Is this simply a matter of good tuning, or is there a better way? It would be really nice to get this down to a couple of milliseconds or better.

  Are you sure? yes | no

Luke Weston wrote 12/30/2016 at 09:55 point

Nice project!


A few questions about your PID firmware:
- Does auto-tune capability exist or do you need to do it by hand?
I see you have a step-response serial dump feature which is useful, but it is still a tedious and patient process to get the control loop optimized.


Is separate tuning of the position-mode PID and velocity-mode PID required?

Is there a particular procedure that you find works well for PID tuning the system?

  Are you sure? yes | no

Misfittech wrote 12/02/2016 at 18:40 point

I have an upgrade on this project, see https://hackaday.io/project/18468-nano-zero-stepper

There are several fixes/improvements:

- 3.3V on the AS5047 fixed. 

- Heat sink on the A4954 solder to board

- LCD and push buttons added for user interface

- Calibration can be done without recompile, and through LCD interface

- Extra level shifted pin for error signal (or enable)

- complete clean rewrite of firmware, most all floating point removed

- basic feedback mode that does not require tuning

- works with 1.8 and 0.9 degree steppers with no recompiling

Plus many more items...

  Are you sure? yes | no

Ken Sturgis wrote 11/07/2016 at 00:00 point

I have a question about the schematic.  On the AS5047 the design doesn't have pins VDD and VDD3V3 connected.  The data sheet (Figure 10) recommends connecting these pins when in 3V3 mode.  is there a reason these are not connected?

  Are you sure? yes | no

Rainer wrote 11/06/2016 at 09:09 point

What are the electric specifications for the mechaduino?

I think of power supply voltage range, logic input voltage range, maximum output current and stepper motor internal resistance range?

I think these details would be really helpful for new users and should be mentioned in the details section.

And thanks for this great project. :)

  Are you sure? yes | no

edkirk1 wrote 11/04/2016 at 17:26 point

My x and y axis jitter and vibrate during printing, z and extruder don't exhibit any noticeable problems.  I just read that Smoothboard uses 3.3 volt output on the step/direction/enable pins.  Is the 3.3 volt output an issue for Mechaduino?

Thanks, E

  Are you sure? yes | no

2wice wrote 11/04/2016 at 18:58 point

I'm also keen on an answer for this as I'm also using a Smoothie.

  Are you sure? yes | no

Alex wrote 11/02/2016 at 05:39 point

Hi guys, has anyone looked at using the new A5995 driver from Allegro? It's a bit of an upgrade (3.2A) , but different packaging.

  Are you sure? yes | no

Misfittech wrote 12/02/2016 at 18:34 point

I am working on a 8A version for NEMA 23 motors. 

  Are you sure? yes | no

Andre Blanchard wrote 10/28/2016 at 10:29 point

Is it possible the add a velocity loop inside the position loop?

Is the code for examples like the toilet paper disbenser available?

I got my motors a while ago but just starting to play with them now.

  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