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

See BOM 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

  • 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 1 comment

    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!


  • Kickstarter PCBs Arrive at Manufacturer!

    jcchurch08/18/2016 at 23:16 0 comments

    Our manufacturer, MacroFab, was kind enough to send us these photos of the PCBs!


View all 25 project logs

  • 1

    OVERVIEW:

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

  • 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

    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

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

Jimmy 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

jcchurch wrote 10/25/2016 at 23:59 point

Hi david,

Please see our latest build log (above)!

-Joe

  Are you sure? yes | no

david wrote 10/25/2016 at 14:16 point

Hi,

I assumed the firmware would support a 'Go to angle: x' function but I can't see any example?

  Are you sure? yes | no

Ben Holmes wrote 11/05/2016 at 21:55 point

There doesn't seem to be any 'angle' function but there is a 'position' function.

  Are you sure? yes | no

edkirk1 wrote 10/23/2016 at 19:33 point

also noticed you have 250000 for baudrate.  My driver is maxed out at 115200.  does that matter?   Thanks, Ed

  Are you sure? yes | no

Kai Wolter wrote 10/23/2016 at 21:52 point

it shouldn't make any difference, just set it to 115200 (mine is working fine with 250000).

got the error: the step_response.pde shouldn't be in the same folder. just deleted it. It's an processing script to plot the serial data so you dont need it anyways. It just makes it easier to tune the pid loop. (you need processing to use ist: https://processing.org/download/?processing)

  Are you sure? yes | no

edkirk1 wrote 10/23/2016 at 19:31 point

l tried to upload but got 'serialEvent' declared void

  Are you sure? yes | no

Kai Wolter wrote 10/23/2016 at 18:21 point

Made some changes to the firmware:

- faster digitalwirte with direct register manipulation

- enable pin integrated

- deleted the other modes for faster performance (only used in a 3d printer)

- fixed the serial parameter editor

- added an menu to generate a step response (PID tuning)

Maybe someone want to try it or take a look at it to get it even faster and better, by now i'm getting 4500 Hz.

https://github.com/Kaiwol1990/Mechaduino

- Kai

  Are you sure? yes | no

Simon Benoit wrote 10/29/2016 at 23:23 point

Did you tune the PID to make it work at 4500hz ?
Do you get error and oscilliation when the motor reach its setpoint ?? I can't get rid of that

  Are you sure? yes | no

Kai Wolter wrote 10/30/2016 at 10:50 point

oscilations are a sign for overtuned PID settings. Mine is reaching its setpoint, it's more of an balance between sounds an performance for me. Maybe take a look at this article about pid tuning:

http://support.motioneng.com/downloads-notes/tuning/pid_overshoot.htm#1

It's another way to tune your settings, maybe you get better performance with this methode.

  Are you sure? yes | no

nicolas.rambaud.95 wrote 10/30/2016 at 14:07 point

I've had good results with  a nema 17 42BYGHW804 (200 steps/turn, 1.2A) and these PID settings:

Kp:30

Ki:0.1

Kd:30.0

Frequency: 3000

I reduced a lot the noise and vibration levels but i haven't checked on scope if i had any mechanical oscillations

The best would be to find out a way to have an pid auto tune as marlin firmware has

  Are you sure? yes | no

Simon Benoit wrote 10/30/2016 at 15:25 point

I was going to make an iterating PID setting and count the oscillation to try to converge to a good value. The best way would be to consider the dead zone of the motor and the non linearities. I had a class on tuning with servo motors. I should take a look at my notes when i'll find them :P

  Are you sure? yes | no

Kai Wolter wrote 10/30/2016 at 20:46 point

I've also thought about an autotune feature, but hadn't enough time and i'm not sure how they work . I'm coming more from the mechanical site of this stuff, so maybe someone else knows more about that.

Also I'm running mine at a frequency of 4000 Hz and an implemented biquad filter to reduce the noise.

  Are you sure? yes | no

Kai Wolter wrote 10/30/2016 at 23:28 point

I've made an huge step today, got my steady state error down to about 0.04 degree.

Moved the encoder reading in its own interrupt that runs at 40kHz and filtering it with an biquad filter, so the noice of the signal gets down quiet a bit.

If you want to try it take a look at the develoment folder on GitHUB.

- Kai

  Are you sure? yes | no

Ben Holmes wrote 11/05/2016 at 21:54 point

Also remember, it's only useful to tune PID while the motor is mounted in-line. Tuning PID without the motor hooked up to anything is like choosing a toothpick as a lever to move a 50 pound boulder, it doesn't really mean anything.  I'm not talking about any initial configuration to get everything to move, I'm talking about tuning.

  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