Roma
Offline
Jr. Member
Karma: 0
Posts: 76
Mechmate #70
|
 |
« on: January 27, 2013, 05:59:02 pm » |
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
Online
Brattain Member
Karma: 336
Posts: 36482
Seattle, WA USA
|
 |
« Reply #1 on: January 27, 2013, 06:01:18 pm » |
Do I have to declare also NewHeightZ and LastHeightZ ? Yes, you do. And value them appropriately (and at appropriate times). can somebody help ? You're doing fine, so far.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #2 on: January 27, 2013, 06:02:36 pm » |
Stepper Absolute Position ... how to With a position sensor - encoder or a pot.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
|
 |
« Reply #3 on: January 27, 2013, 06:03:58 pm » |
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
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
|
 |
« Reply #4 on: January 27, 2013, 06:05:38 pm » |
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
Jr. Member
Karma: 0
Posts: 76
Mechmate #70
|
 |
« Reply #5 on: January 27, 2013, 06:18:06 pm » |
You're doing fine, so far. Really ? Thanks Paul, I'll see what I can do with your advice. 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
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14121
Lua rocks!
|
 |
« Reply #6 on: January 27, 2013, 06:27:33 pm » |
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
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
|
 |
« Reply #7 on: January 27, 2013, 06:28:27 pm » |
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
Jr. Member
Karma: 0
Posts: 76
Mechmate #70
|
 |
« Reply #8 on: January 27, 2013, 07:05:05 pm » |
Humm ... so far ? 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
Online
Brattain Member
Karma: 336
Posts: 36482
Seattle, WA USA
|
 |
« Reply #9 on: January 27, 2013, 07:44:10 pm » |
HeightZ = 0; if (HeightZ > 0) HeightZ = LastHeightZ; What do you suppose the chances of this statement evaluating to true?
|
|
|
|
|
Logged
|
|
|
|
|
Roma
Offline
Jr. Member
Karma: 0
Posts: 76
Mechmate #70
|
 |
« Reply #10 on: January 27, 2013, 07:56:05 pm » |
only at the beginning after the zero is setted
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 336
Posts: 36482
Seattle, WA USA
|
 |
« Reply #11 on: January 27, 2013, 07:56:53 pm » |
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
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #12 on: January 27, 2013, 08:05:38 pm » |
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
Jr. Member
Karma: 0
Posts: 76
Mechmate #70
|
 |
« Reply #13 on: January 28, 2013, 09:38:29 am » |
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
Jr. Member
Karma: 0
Posts: 76
Mechmate #70
|
 |
« Reply #14 on: January 28, 2013, 02:18:44 pm » |
... 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. 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
|
|
|
|
|
|