Pages: [1] 2 3   Go Down
Author Topic: Stepper Absolute Position ... how to  (Read 1697 times)
0 Members and 1 Guest are viewing this topic.
Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
Mechmate #70
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am bulding an actuator with a stepper motor, to control the height of a router /shaper.
I need to choose and execute two tipe of movement: Absolute and Relative.
Relative is easy for me (beginner):

stepper1.moveTo(MoveX * 50); // move Height1 mm's
where MoveX is the variable I set (es. 30mm) 50 is the number of step to make 1mm
Each time I set the MoveX variable I move of X mm.
Pretty straightforward.
 But with the absolute height I am in trouble.
The first thing to do is to set the Zero point each time the sistem start (that will be done with a limit switch)
So I have my starting point, then I set my variable that I call HeightZ, the fist step is easy, if I set HeightZ=20mm the stepper will go there with 20*50=1000 steps. From now all the new movement have to consider as a starting point the last HeightZ. So if I want to set my Absolute height at 75mm I have to do (New.HeightZ - Last.HeightZ)*50steps .... (75-20)*50 ... 2750 steps.
I suppose that the fist thing is to  declare var HeightZ:
Int HeightZ = 0;
Do I have to declare also NewHeightZ and LastHeightZ ?
can somebody help ?
or can somebody point me on a similar sketch ?
thanks

 


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do I have to declare also NewHeightZ and LastHeightZ ?
Yes, you do. And value them appropriately (and at appropriate times).

Quote
can somebody help ?
You're doing fine, so far.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Stepper Absolute Position ... how to

With a position sensor - encoder or a pot.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31369
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Int HeightZ = 0;
Are you dealing in units of mm?
That is quite coarse for a miller, your motors are capable of finer control. If you use ints then you have to use some arbitrary units like 1/1000 th of a mm so you can cope with fractional movement.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31369
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Stepper Absolute Position ... how to

With a position sensor - encoder or a pot.


This might come as a surprise to you dear henry but there is some text in the post as well as the title. That needs to be read before a sensible answer can be given.
Logged

Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
Mechmate #70
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You're doing fine, so far.
Really ?
Thanks Paul, I'll see what I can do with your advice.

Quote
With a position sensor - encoder or a pot.
none of the above,I don't need a feedback, I just need to set the Zero (starting Point) then I just have to know where I am and where I want to go.

yes Mike, you are right I would much better use float (am I right? ) :-)
but at the moment I was just thinking to understand how to manage the code.
thanks
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I find it easier to write code than to try to describe it.

Try putting your thoughts into a small sketch. See if it compiles. With luck you can fix any compile errors yourself. If you get that far, test it.

If the results are not what you expect, or if you get stuck on some point, post what you have and describe the problem.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 508
Posts: 31369
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No using floats brings rounding errors, you need to use int to keep it accurate. Just let the int stand for a small value.
Logged

Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
Mechmate #70
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Humm ... so far ?

Code:
int HeightZ = 0;
int LastHeightZ = 0;
//int NewHeightZ = 0;


void ABSheight(){
HeightZ = 0;
if (HeightZ > 0) HeightZ = LastHeightZ;
stepper1.moveTo((LastHeightZ - HeightZ) * 50); // move Height1 mm's
lcd.print ("Height mm ");
lcd.print (HeightZ);
delay (5000);
}
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
HeightZ = 0;
if (HeightZ > 0) HeightZ = LastHeightZ;
What do you suppose the chances of this statement evaluating to true?
Logged

Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
Mechmate #70
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

only at the beginning after the zero is setted
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
only at the beginning after the zero is setted
You set HeightZ at the start of that function, every time it is called.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I just need to set the Zero (starting Point) then I just have to know where I am and where I want to go.

Without a position sensor, you wouldn't know where you are: all you know is where you have told the stepper to go. Whether the motor is there or not is an unknown, unless you have a position sensor.
Logged

Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
Mechmate #70
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Paul, there is somthing I don't catch sorry, I have to do a better research on other project to see something similar at work.

Henry, with all respect, but a position sensor is not needed. It's the code that know where the stepper is. With the steppers the position is calculeted by the software, and they work perfecly this way, most of the CNC work like that.

Logged

Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
Mechmate #70
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

... well I spent some hours trying understand, but I cannot clear my idea on how I can store the previous HeightZ value to LastHeightZ
This code is obviously not working, I miss the way to store my variable HeightZ and convert to LastHeightZ before changing the value.

Code:
int HeightZ = 0;
int LastHeightZ;
int NewHeightZ;


void ABSheight(){
LastHeightZ = HeightZ;  // previous?? HeightZ variable setted in the menu is stored in LastHeightZ

NewHeightZ = (HeightZ - LastHeightZ); //should be actual HeightZ difference value with previous in the menu
stepper1.moveTo(NewHeightZ * 50); // move Height1 mm's
lcd.print ("Height mm ");
lcd.print (HeightZ);
delay (5000);
}
« Last Edit: January 28, 2013, 04:28:13 pm by Silverdog63 » Logged

Pages: [1] 2 3   Go Up
Jump to: