loading

Need Help Arduino controlled Stepper Motor Proportional Control

Need help with a basic code I'm trying to make for a personal project, I'm new to Arduino and  I find an example of this type of coding would be useful for me to learn off. Would like to get better at this programming stuff and move on to other types of coding.
Looked at the basics via the Arduino website but nothing really covered this method of control.

A stepper motors speed can be altered via the use of proportional control. The feedback sensor is a potentiometer, which should tell the stepper motor when to stop. 
Here are the basics of what I know the code must contain 

Kp = 1;// the gain of the proportional control must contain a multiple factor
error = Setpoint -actual position; // provides the error value
output = error*Kp; // this will provide the drive for the stepper

The stepper should stop when the setpoint value equals the actual value. So the stepper should move faster to its target the further away it is.

Using a ULN2004A for the driver and have this setup for the circuit.
https://www.arduino.cc/en/uploads/Tutorial/UnipolarKnob_bblg.png

Any help explaining or showing an example code upon how to accomplish this task would be appreciated. No idea how to make this affect the stepper speed or even do this control feedback. Am in need of some help.




Downunder35m4 months ago

If you go be the number of steps required you won't need an incoder, just a reliable way of powering the motor without loosing steps.
Calculating distance based on the steps and resolution is no problem either.
I think the 3D printer stuff for Arduino should give some useful examples about the speed control.
Acceleration control and other things are normal procedure here, so it should be possible to find some code and libraries in Marlin or other other projects.

Prime01 (author)  Downunder35m4 months ago

Thank you, I appreciate the time you have spent. I was more thinking a simple step by step guide explaining how to create the program, like an introductory to it. This stuff is confusing for me at best.

That is why people usually start with easier projects and work their way up to more complex programming.
And what you want to do is quite complex, even for me if I should start it from scratch.
I am almost certain similar thing already exist in 3D printer or CNC programs for the Arduino in one way or another, just need to find it and adapt it to your needs.
If you take a standard 3D or CNC setup than the axis home to initialise.
From there you can run at any speed you like and the program makes sure the motor won't miss a step.
That is the basic start routine you need.
From there you need to track the distance or use sensors for it.
The speed control can be as easy as a loop checking the distance or steps and limiting the speed with a simple table containing fixed speed values for a certain amount of travelled steps - or read distance from the sensor.
Acceleration control if required could again be borrowed from Marlin, GRBL or Sprinter depending on what suits best.
But I doubt anyone here will take the time to do all this for you unless there is a need for it.

Prime01 (author)  Downunder35m4 months ago

Sorry, I was under the impression the code was an easy to do task. Thank you for your time and advice.