
09-13-2007, 10:36 AM
|
| | | Join Date: Jul 2003 Location: Holmen, WI
Posts: 1,081
| |
EMC2 + Steppers + Encoders = following error detection (so far) :) | | There is this guy - you see - that has encoders hooked up to the back of his stepping motors. He thought 'Hmmm I would like to see if I can set emc2 up so that if I start missing steps, Emc will throw a following error - and estop'. He is reading the encoder back thru the printer port. You can see how flexable emc2 is. I think this is the first time it has been tested. (It has been talked about a lot - there may still be bugs in the theory) But is seems to be working. Here is an edited IRC chat with the emc gurus from here.
Gives an idea of the thought proccess. http://www.linuxcnc.org/irc/irc.free...2007-09-12.txt 18:47:13 alex joni: i have an encoder on my z axis and its hooked up to my breakout board with a and b channel,is there a place on the wiki that deals with adding an encoder
18:47:29 wanting to get ferror
18:48:02 jlmjvm: search the configs for the component encoder
18:48:17 you need to loadrt encoder num_chan=1 (if my memory serves me right)
18:48:32 then add the 2 functions of encoder to base_thread and to servo_thread
18:48:40 you need to get the scale right
18:48:59 and the output from encoder needs to get connected to the axis feedback position
18:51:37 configs?do you mean where the hal and ini file is?dont have encoder component in my configs,
18:52:15 may not be looking in the right place
18:54:31 jlmjvm: look at the etch-servo hal for a starting point for setting up the encoder module
18:54:43 will do
18:57:50 looks like what i need to get started,thanks
19:24:25 heres my hal file,crashes when emc starts
19:24:30 http://pastebin.ca/694392
19:25:33 im only using 1 encoder right now,and the a and b pins are right
19:25:43 uh what's the error?
19:26:03 HAL:20:error message here
19:26:06 (20 is the line number)
19:26:30 want me to paste error msg
19:26:36 encoder.2 is wrong
19:26:42 you need encoder.0
19:26:55 and loadrt encoder num_chan=1 is enough for now
19:27:24 if you want encoder.2.* then you need num_chan=3 (0,1 and 2)
19:27:59 my z axis is number 2
19:28:09 encoder on z axis
19:31:43 jlmjvm: 'Z axis' doesn't mean you automatically put .2. everywhere
19:32:07 jlmjvm: in this case, this is the first and only thing you are hooking up to 'encoder', so you use encoder.0
19:32:34 just tried it with 0
19:33:01 still no go
19:33:13 yeah but the error is almost certainly different now :-P
19:33:27 prolly so
19:33:42 want me to post it
19:34:26 well that's the only way anybody here is going to be able to help you
19:47:37 http://pastebin.ca/694421,thats the changes i made
19:47:59 how do you send an error,cant copy
19:53:59 jlmjvm: start emc from a terminal
19:54:06 then you can select and copy the error
19:54:36 jlmjvm: but the error is probably :
19:54:42 newsig Zpos-fb float
19:54:46 ahhh
19:54:47 that one should already be defined
19:55:04 jlmjvm: the linksp should be enough
19:55:36 adam2: http://groups.yahoo.com/group/CAD_CAM_EDM_DRO/
20:04:51 http://pastebin.ca/694451
20:05:01 finally got the error msg
20:05:31 jlmjvm: don't see the actual error
20:06:22 k,on the way,that was the dmesg
20:09:04 http://pastebin.ca/694459
20:09:15 that should be the error
20:09:46 jlmjvm: I already told you that you need to remove the newsig
20:10:18 gives another error when i did
20:10:39 jlmjvm: what's the error?
20:10:42 already has a writer?
20:11:17 lemme remove the newsig and resend error
20:11:26 jlmjvm: no need
20:11:31 remove the newsig
20:11:38 then open core_stepper.hal in the same dir
20:11:46 and look for the following line 'linksp Zpos-fb <= stepgen.2.position-fb
20:11:53 and comment that line out
20:13:36 k,will give it a try
20:15:06 your going to have to scale the encoder module correctly to work correctly with you input scale
20:16:01 I think I could have squeezed another 'correctly' into that sentence
20:16:40 that worked
20:17:20 emc came on and if i turn the motor the numbers change
20:17:28 Sweet 
20:17:31 motor poer is off
20:17:36 power
20:17:54 where do i set the cpr amount at?
20:18:18 1024cpr quadrature
20:18:27 20480 counts per inch
20:21:33 scale I think
20:22:09 it's up to you actually
20:22:10 setp encoder.0.position-scale
20:22:21 you can stick a line like that in the .hal file
20:22:22 setp encoder.0.position-scale 20480
20:22:40 you can use any name you want in the ini file, and reference that in the .hal file
20:22:44 I ment scale pin on the encoder.
20:22:48 yes
20:23:01 so setp encoder...scale 20480 is one way
20:23:03 SWPadnos: he is doing steppers with encoders.
20:23:08 rigth
20:23:10 right
20:23:19 right
20:23:30 so he has the scale in the ini for the stepper which will be different than his encoder scale.
20:23:42 * skunkworks is thinking out loud
20:23:45 you can add any variables you want to the ini, and reference tem in the HAL file, so it really depends on how you want to set it up
20:23:55 really - cool
20:24:03 so you can add a section called [MY_STEPPER_ENCODER_FEEDBACK]
20:24:04 really? - cool
20:24:29 and a variable in it called THE_NUMBER_OF_COUNTS_PER_INCH_ON_THE_X_AXIS
20:24:45 so add that setp line to my hal file?
20:25:01 and you can set that by using "setp encoder.0.scale [MY_STEPPER_ENCODER_FEEDBACK]THE_NUMBER_OF_COUNTS_PER_INCH_ON_THE_X_AXIS" in the hal file
20:25:08 setp encoder.0.position-scale 20480
20:25:21 that'll work too, of course 
20:30:16 hmm - wasn't there an issue with the stepgen with using encoders as feedback - like it doesn't reset it position to the 'encoders' position after an estop or something like that?
20:30:22 changed the hal file,still have joint error,was i supposed to put something in the ini file also?
20:30:48 what is the error? following error?
20:30:55 yep
20:31:19 encoder is doing its job already
20:32:18 with it off - does the readout count correctly? like 20 turns equal an inch on the readout?
20:32:35 are they going in the same direction?
20:32:39 i can check
20:33:40 SWPadnos: did you read what I wrote above about stepgen?
20:33:58 yes. that could be a problem, I don't know
20:38:34 counting correctly
20:41:26 jlmjvm: so the second you turn the machine on - you get a following error - or is it when you start to move?
20:42:05 when i start to move
20:42:18 so when you start to jog - it will error?
20:42:24 yes
20:42:27 I would negate the scale on the encoder
20:42:51 jlmjvm, you may need to fiddle with the stepgen accel and vel limits
20:43:11 setp encoder.0.position-scale -20480 - or does it count the right direction?
20:43:11 or use halscope to display what is happening with commanded & feedback positions during the short time you try to move -- that will give you a better idea what is going on
20:43:40 jepler: what? systematic aproach? bah
20:43:41 yes
20:43:41 
20:44:40 jlmjvm: yes what?
20:44:57 yes its reading the right way
20:45:25 ah - ok. Jepler really has the correct way to see what is going on. use halscope.
20:45:32 and my rapids are slow right now,60 ipm
20:45:47 try moving much much slower than that
20:45:49 what if you jog slow - like 1ipm or such
20:45:56 same thing
20:46:04 tried that
20:46:13 use MDI to do something like G1X1F10
20:46:46 was doing this same thing yesterday on mach and it could read at 100 ipm
20:46:48 jlmjvm: what is your following errir set to in the ini?
20:46:57 lemmee see
20:47:56 ferror=.050 minferror=.010
20:48:19 I would think that would be more than enough.
20:48:28 ferror that is.
20:48:37 jlmjvm, you have a setup error, and you'll need to use the diagnostic tools to figure out what that error is
20:49:04 halscope is probably the best tool at the moment, because at the moment, nobody knows exactly what's going on
20:49:18 and without knowing what's happening, it's hard to fix it
20:49:58 wasnt i supposed to add something to the ini file to point to the encoder scale?
20:50:07 jlmjvm, not necessary
20:50:20 but you should make sure the scale is correct before going on
20:50:38 it seems by your account - it is working correctly - 20 turns of the leadscrew is 1 inch.
20:50:47 in the display
20:50:59 ie, manually turn the motor shaft/screw to move the table 1 inch, and verify that the display shows 1 inch of movement
20:51:21 its doing that
20:51:29 does it go the right way?
20:51:32 yes
20:51:47 ok, and if you don't use the encoder feedback, but use the stepgen feedback, can you jog?
20:51:57 and when you do that, does it jog in the correct direction?
20:52:19 yes,was moving it yesterday
20:52:20 you can experiment a little by setting ferror very large - like 1 inch
20:53:08 are you sure software counting can keep up with your encoder rate?
20:53:10 will try,but was i supposed to add something to the ini file?
20:53:13 just to be sure, you are exiting from EMC and restarting every time you change anything in the hal or ini files, right?
20:53:25 yes
20:53:33 ok - just had to check 
20:53:38 no prob
20:53:43 jlmjvm: no, you did not need to modify the .ini file if you put the encoder scale explicitly in the .hal file
20:53:53 you have the option of using an ini file setting for the scale (or anything else), but it's not required to use one
20:53:53 k
20:54:10 just wanted to make sure
20:54:23 lemmee open up the ferror setting
20:55:54 open up both of them.
21:01:38 its working
21:01:56 some big dummy had the pins backwards
21:02:16 heh
21:02:32 i swear when the power was off the motors it was reading right
21:02:47 it has to be right, and also it has to match the motor
21:03:00 it's more important for it to match the motor
21:03:11 (as far as following errors go)
21:03:14 swapped the a and b pin # and its working
21:03:30 ok. you could also have negated the scale as skunkworks suggested
21:03:37 jlmjvm: negating the encoder scale I think would have done the same thing..
21:03:38 
21:04:01 * skunkworks thinks now jlmjvm should now play with adaptive feed controll....
21:04:28 lets rock n roll,lol
21:04:34 * SWPadnos thinkd skunkworks needs to take his meds
21:04:41 err - thinks
21:04:43 i really appreciate the help from everyone
21:05:06 any time. just remember to put it on the wiki if you discover anything major about steppers+encoders 
21:05:15 jlmjvm: you really need to post this on cnczone. This is always brought up.
21:05:16 im the only guy on the block with encoders on his steppers
21:05:25 really
21:05:42 So - now if you stall - do you get a following error?
21:05:49 yall can have a copy of my hal and ini if you want
21:06:00 no thanks. I'd rather have you put it on the wiki 
21:06:07 im sure it will
21:06:09 hint hint
21:06:29 lemmee give it a big accel and stall it
21:06:32 brb
21:06:48 me,on the wiki
21:07:04 just set the axis vel limit to 1000IPM and try G1X10F500
21:07:15 but set the ferror back down first 
21:07:49 he should be able to measure the following error - and as it increases slow the feed rate down using adaptive feedrate.. I think it would be a cool experiment..
21:12:55 oh yeah,jacked the acceleratio up from 6 to 60 and it gives an immediate joint following error,doesnt even move
21:13:41 thats gotta be working
21:14:42 plus its showing up when i home out the axis,-.0002,.0001 etc
21:15:21 i think this is gonna really help
21:15:25 cool
21:15:51 im ready to have a keg party now,this was magor to me
21:16:18 what base period are you running?
21:16:22 10000
21:17:17 its reading at 60 ipm no problem
21:17:41 yah - you should be able to do 150ipm no problem
21:17:41 should be able to get 100 ipm like i did in mach yesterday
21:17:58 150 would be awesome
21:18:08 what is your input scale.
21:18:11 ?
21:18:22 remember - you can output at least twice as many steps as you can read
21:18:23 the cool thing is i had these encoders all along
21:18:29 10000
21:18:35 the encoder counting is going to be your real limmit
21:19:01 you probably won't be able to count past ~90 IPM reliably
21:19:03 SWPadnos: explain? you mean doing doublefreQ?
21:19:09 yes,they were higher count than i wanted,but they were on the motors i bought
21:19:13 yes, doublefreq is part of it
21:19:36 but you need some margin for reading quadrature that isn't needed for step generation
21:19:42 and they were 250.00 encoders,wish they had an index
21:19:48 AH - but he should be able to count at 50khz shouldn't he? with base period set to 10000?
21:20:02 at most
21:20:09 atleast 
21:20:16 oh - I think I had an extra factor of two in my head
21:20:18 so that is 146ipm
21:20:21 100 is prolly all i will go
21:20:21 lerneaen_hydra has joined #emc
21:20:52 no, at most. if latency is 0 and the encoder has perfect 90 degree phases, then 50 KHz is doable
21:21:34 and at 60Hz?
21:21:34 if latency isn't zero, then the least time the encoder needs to be at one state is 10000 + latency to guarantee that the software sees it
21:21:52 oh, nm didn't see the K
21:21:53 if the encoder isn't perfect, then that restriction is on the shortest phase
21:23:06 so if it's got a "short pulse" in one quadrature state - say only 75 electrical degrees instead of 90, then that short state needs to be BASE_PERIOD + latency_max long to be noticed
21:23:55 in that example, 75 degrees is ~1/5 of a full cycle, so a cycle of 4 counts = 5 *(base_period+lat_max)
21:24:03 huh
21:24:08 heh
21:24:20 so it works great, until you start looking at the fact that nothing is perfect 
21:24:33 heh
21:24:48 alright lets get started on that adaptive feedrate,lol
21:24:52 heh
21:25:00 just kidding
21:25:03 opk - time for me to get back to paying work! 
21:25:30 thanks for the help
21:25:35 I could have swarn though that I was counting encoders close to base period... but I don't know for sure..
21:25:45 sworn
21:26:04 but that is an argument for another time.. | |