Hi,

This is my first post - I'm not sure this is the right part of forum, but here goes.

I'm hoping someone with stepper CNC control experience can help me with this one.

I have Duemilanove with Adafruit motor shield controlling two stepper motors and and a small servo for a simple CNC type setup. Like a plotter, the motors run the x and y axis and the servo lifts a pen/cutter up or down for the z axis. G code is sent to arduino via serial a line at a time and arduino calculates the speed or stepper motors and servo etc. The G-code is only sending straight line commands, so the steppers do not change speed, they run at the same speed between co-ordinates.

The way I have calculated the speeds for the steppers for each move is like this -

I know the distance needed to travel for both the X motor and the Y motor to reach the co-ordinate, lets say X needs to travel 100 steps and Y needs to travel 50 steps simultaneously.

So I set the X motor (running the longest distance) to a set speed, say 100 steps a second. Then I calculate the speed of Y motor (running the shorter distance) to Y.distance(50) / X.distance(100) * X.speed(100). So Y should be running at 50 steps a second, stopping at the same time as X.

So I figure both motors should arrive at their co-ordinates at the same time using this method. But they don't! There seems to be a difference, so that although they are changing their speeds accordingly, they don't arrive at their destination at the correct time. One of the motors seems to carry on running a bit longer than the other. I can't seem to find out why this is.

All the values I'm using are floats so I don't think anything is lost by converting integers to floats.

Here's the code described above:

(delta_steps is just the number of steps that the each motor needs to make)

if (delta_steps.x !=0 && delta_steps.y !=0){ //if both motors are moving

if (abs(delta_steps.x) > abs(delta_steps.y)) //if x distance is longer than y distance

{

stepperx.setMaxSpeed(max_speed);

stepperx.setAcceleration(max_speed);

steppery.setMaxSpeed((abs(delta_steps.y)/abs(delta_steps.x))*max_speed);

steppery.setAcceleration((abs(delta_steps.y)/abs(delta_steps.x))*max_speed); }

else

{

steppery.setMaxSpeed(max_speed);

steppery.setAcceleration(max_speed);

stepperx.setMaxSpeed((abs(delta_steps.x)/abs(delta_steps.y))*max_speed);

stepperx.setAcceleration((abs(delta_steps.x)/abs(delta_steps.y))*max_speed);

}

}

else {

stepperx.setMaxSpeed(max_speed);

steppery.setMaxSpeed(max_speed);

stepperx.setAcceleration(max_speed);

steppery.setAcceleration(max_speed);

}You will notice the acceleration variable is there too. This doesn't seem to have any effect on the problem if I change this,for example if I set maximum acceleration to the steppers so they both move full speed immediately, one of the motors is still delayed.

Any help greatly appreciated. I am using both the Adafruit library and Accelstepper library to run the motors. All the code etc can be found here

http://www.maxlivesey.co.uk/maxtest/arduino/gcoder.zip