chipKIT® Development Platform

Inspired by Arduino™

Four stepper motors with AccelStepper library

Created Tue, 07 Feb 2012 02:57:50 +0000 by EmbeddedMan


EmbeddedMan

Tue, 07 Feb 2012 02:57:50 +0000

I wanted to see how easy it would be to run the fantastic AccelStepper library on our chipKIT boards. Turns out it's a piece of cake.

Download the library zip file from [url]http://www.open.com.au/mikem/arduino/AccelStepper/AccelStepper-1.14.zip[/url], copy the AccelStepper folder to your hardware\pic32\libraries folder, and off you go.

I'm using my Big Easy Driver stepper motor driver boards [url]http://www.sparkfun.com/products/10735[/url], and some rather beefy steppers I had lying around. The Big Easy Drivers are available from SparkFun. They're all plugged into my Big Easy Driver Backpack (which is designed to plug into a MAX32 or Mega style board).

Here's a video of some really simple back and forth motion:

[url]http://www.youtube.com/watch?v=7Ga6RMYwuQI[/url]

And here's the (very basic) code:

#include <AccelStepper.h>

// Define some steppers and the pins they will use
AccelStepper stepper1(1, 26, 27); 
AccelStepper stepper2(1, 28, 29);
AccelStepper stepper3(1, 30, 31);
AccelStepper stepper4(1, 32, 33);

void setup()
{  
    stepper1.setMaxSpeed(11000.0);
    stepper1.setAcceleration(10000.0);
    stepper1.moveTo(12000);
    
    stepper2.setMaxSpeed(8000.0);
    stepper2.setAcceleration(10000.0);
    stepper2.moveTo(35203);
    
    stepper3.setMaxSpeed(20000.0);
    stepper3.setAcceleration(10000.0);
    stepper3.moveTo(26010); 

    stepper4.setMaxSpeed(6000.0);
    stepper4.setAcceleration(10000.0);
    stepper4.moveTo(29010); 
}

void loop()
{
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
	stepper1.moveTo(-stepper1.currentPosition());
    if (stepper2.distanceToGo() == 0)
	stepper2.moveTo(-stepper2.currentPosition());
    if (stepper3.distanceToGo() == 0)
	stepper3.moveTo(-stepper3.currentPosition());
    if (stepper4.distanceToGo() == 0)
	stepper4.moveTo(-stepper4.currentPosition());
    stepper1.run();
    stepper2.run();
    stepper3.run();
    stepper4.run();
}

I hope it's really plain to everyone how easy and simple it is to create fast, smooth stepper motion on chipKIT boards using this library.

As you can see from the above code, I only went up to about 20,000 steps/s. However, I can easily run all four motors at about 29,000 steps/s. And that's not even a limit due to the chipKIT or AccelStepper library - it's just where the motors stall out. I'm sure I could go faster if I had better drivers and motors.

This is really cool (to me) because there are so many fun things you can do with the ability to create very precisely timed and accurate motion.

Anyway, I thought you all would like to see what I worked on this afternoon.

*Brian


luismi911

Fri, 17 Feb 2012 07:05:50 +0000

Hello Forum!

I am really amazed with the potential of the chipKIT systems, after seeing EmbeddedMan post, i realized that my current project could be solved in an easy way" . Actually im working on my bachellor senior project, its a six-DOF robotic manipulator, driven by stepper motors. i was looking for an arduino solution but the specs of arduino boards were not good enough (16MHz clock... =S), i think this board will do the job, probably i'll need to do some modifications to the AccelStepper lib, but anyway, i think this board will make my life easier.

What i need to do is to control 6 Baldor DSM stepper motors. These motors have an integrated driver with a 2 pin interface (one for clock and one for direction) and high microstepping resolution (up to 56000 steps/rev) and the manufacturer states that they can hold a clock signal up to 2MHZ (that means 2 million steps in one second i think ºoº).

Actually i do not own a chipKIT board (but i´m planning to get one), so i cannot test the performance of the Max32 + AccelStepper library with my own motors, so, i would like to know what could i get in therms of steps/second, speed and number of motors with the Max32 + AccelStepper library without doing mayor modifications to it (just an opinion, what you people think =D).

Thanks in advance and greetings from Colombia!


EmbeddedMan

Fri, 17 Feb 2012 14:24:34 +0000

That's a great question. I do not know what the top speed is, however, the top speed is somewhat meaningless. That's because you go faster and faster, the 'smoothness' of the acceleration drops and you start getting very large 'jumps' in speed. So even if you could generate 100K steps/s, getting there and back may be so choppy that you'd not ever want to do it.

I can tell you one data point. With the current version of AccelStepper, on a chipKIT board, I can easily generate very smooth step pulses up to the point where my motor generates zero torque (about 29,000 steps/s). When I ran four motors at once, I could run all of them at 29,000 steps/s, but the acceleration/deceleration started to get a little 'choppy' at the high speeds.

If I had to guess, I'd say that with 6 motors running at the same time, you could probably do 20,000 steps/s smoothly.

And you are quite right, a traditional Arduino can't touch that.

If you really need smooth accel/decel at up to 2M steps/s, you'll need to go with an FPGA. (i.e. SmoothStepper)

My suggestion is to try it with a chipKIT first and dial down your microsteps/step value so that you get the speed you need.

*Brian


Adam Donovan

Tue, 18 Sep 2012 12:23:37 +0000

Well now I cant wait to get my Chipkit this Thursday as the speed of the accel stepper lib was holding me way back on the arduino.