Go Down

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

Silverdog63


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.

...  :smiley-red:
Well I cancelled any trace in the previous post  :)


Quote

Your
indenting
is
still
awful!


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

Silverdog63

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 = mm
int 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


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

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


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

Go Up