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:
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 ...
int HeightZ = 0; //ABS Height Variable = mm
int ActualHeightZ = 0;
int NewHeightZ;
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:
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);
}