Pages: 1 2 [3]   Go Down
Author Topic: Stepper Absolute Position ... how to  (Read 1984 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

Code:
NewHeightZ == (HeightZ - LastHeightZ);
This is an equality test, not an assignment.
Code:
LastHeightZ == HeightZ; // this set the current position HeightZ as LastHeighZ
So is this.
...  smiley-red
Well I cancelled any trace in the previous post  smiley


Quote
Your
indenting
is
still
awful!

 smiley-red
Ok I will do some homework
http://en.wikipedia.org/wiki/Indent_style
Logged

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

A few post ago Mike asked:
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.
.... and I answered "maybe I should use float" .... then Mike:
Quote
No using floats brings rounding errors, you need to use int to keep it accurate. Just let the int stand for a small value.
Well, if I want to use decimal numbers how do I have to do ? I would like to set my height from 0 to 100 in 0.1 mm steps.


Here a part of my sketch ...
Code:
int HeightZ = 0;                      //ABS Height Variable = mm
int ActualHeightZ = 0;
int NewHeightZ;

Code:
  s1=menu.addMenu(MW_SUBMENU,r,F("SAW"));               // add a submenu node 2 to the root menu (control the heigh of my Saw)
   s2=menu.addMenu(MW_SUBMENU,s1,F("Saw Height"));      // (Move AT a certain mm height)
    s3=menu.addMenu(MW_VAR,s2,F("Absolute Height"));    // add a terminal node in the menu tree (that is "variable")
     s3->addVar(MW_AUTO_INT,&HeightZ,0,100,1);

oh, just for the record ...This is my solution, I had to change also the relative movement to have it working together with the absolute move:
Code:
void ABS_Height()                   // Absolute Height Function
 {
  NewHeightZ = (HeightZ - ActualHeightZ);
  stepper1.moveTo(NewHeightZ* 50);  // move Height1 mm's
   lcd.print ("Height mm ");
   lcd.print (HeightZ);
   delay (5000);
  ActualHeightZ = HeightZ;
 }


void MoveSAW()                      // This is the Relative Movement of the SAW
 {
  stepper1.moveTo(MoveREL * 50);    // move the SAW X mm's
   lcd.print ("Move ");
   lcd.print (MoveREL);
   lcd.print (" mm");
   delay (5000);
  ActualHeightZ = (HeightZ+MoveREL);
   lcd.print ("Height ");
   lcd.print (ActualHeightZ);
   lcd.print (" mm");
   delay (5000);
 }
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12524
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, if I want to use decimal numbers how do I have to do ? I would like to set my height from 0 to 100 in 0.1 mm steps.

If you want a resolution of 0.1mm then make your units 0.1mm. This is known as 'fixed point' as distinct from 'floating point'.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

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

Quote
If you want a resolution of 0.1mm then make your units 0.1mm.
Well I would say if you want 0.1mm resolution then make your units equal to 0.01mm or even 0.001 so that you don't get bitten by rounding errors.
Logged

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

Well I would say if you want 0.1mm resolution then make your units equal to 0.01mm or even 0.001 so that you don't get bitten by rounding errors.

No, not that much! I am working with wood so 0.1 it's enough, I just want to make my movment in 0.1 step, ex move the height of 40.5 mm changing the variable from INT to FLOAt is ok ?or there is some other solution ?
thanks
Logged

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

Quote
changing the variable from INT to FLOAt is ok ?
Sorry I dnon't know how many times you need telling
 DO NOT USE A FLOAT!!!!!
You will suffer from rounding errors. Mathematical operations will not be commutative.   
What do you not understand about using an int with the numbers greater than your resolution?
Logged

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

Quote
What do you not understand about using an int with the numbers greater than your resolution?
What I don't understand maybe is the nature of INT ... I consider integer number the number with no decimals so 1, 2, 3 ..... but 0.5 is a decimal number ...
so my question is: can I define my function as INT and have decimal values ? like 10.5 10.8 ecc. ecc ?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Think of it like this. A millimeter is 0.001 of a meter. So in a sense it is a fractional meter. But if you deal in integral millimeters (store them in an int) then you won't get any rounding problems.

But you can define your own unit. Eg. a micrometer being 0.000001 of a meter. Of course, since an int only goes up to 32767 you might need to be cautious about how big your values might get, but you could always store them in a long, which goes up to 2147483647.

So if you use micrometers, then 1000000 micrometers represents a meter.

Quote
can I define my function as INT and have decimal values ? like 10.5 10.8 ecc. ecc ?

In my example of micrometers, if you want 1.5 meters then you would use 1500000 micrometers.
Logged

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

Thanks Nick, understood
Logged

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