Go Down

### Topic: Stepper Absolute Position ... how to (Read 5521 times)previous topic - next topic

#### Silverdog63

#30
##### Jan 29, 2013, 12:24 pm

Code: [Select]
`NewHeightZ == (HeightZ - LastHeightZ);`
This is an equality test, not an assignment.
Code: [Select]
`LastHeightZ == HeightZ; // this set the current position HeightZ as LastHeighZ`
So is this.

...
Well I cancelled any trace in the previous post

Quote

Your
indenting
is
still
awful!

Ok I will do some homework
http://en.wikipedia.org/wiki/Indent_style

#### Silverdog63

#31
##### Feb 03, 2013, 11:17 pm
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: [Select]
`int HeightZ = 0;                      //ABS Height Variable = mmint ActualHeightZ = 0;int NewHeightZ;`

Code: [Select]
`  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: [Select]
`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); }`

#### PeterH

#32
##### Feb 04, 2013, 12:04 am

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'.
I only provide help via the forum - please do not contact me for private consultancy.

#### Grumpy_Mike

#33
##### Feb 04, 2013, 12:22 am
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.

#### Silverdog63

#34
##### Feb 04, 2013, 12:29 am

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

#### Grumpy_Mike

#35
##### Feb 04, 2013, 12:40 am
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?

#### Silverdog63

#36
##### Feb 04, 2013, 12:54 am
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 ?

#### Nick Gammon

#37
##### Feb 04, 2013, 01:27 am
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.
Please post technical questions on the forum, not by personal message. Thanks!

http://www.gammon.com.au/electronics

#### Silverdog63

#38
##### Feb 04, 2013, 09:13 am
Thanks Nick, understood

Go Up

Please enter a valid email to subscribe