NEWS
LinuxCNC 2.5.2 Release
There are no translations available.

LinuxCNC 2.5.2 Update Released (changelog).
 
LinuxCNC 2.5.1 Release
There are no translations available.

LinuxCNC 2.5.1 Update Released (changelog). If the Package Manager does not prompt you to upgrade see this page.

 
LinuxCNC 2.5.0 Release
There are no translations available.

New major release (changelog). See the instructions to update your system from EMC 2.4 to LinuxCNC 2.5.
 
Home Forum General General LinuxCNC Questions Two encoders on one Axis

Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Two encoders on one Axis

Two encoders on one Axis 03 Ago 2012 04:20 #22712

  • mariusl
  • mariusl's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 0
Hi all,
I am new here and already have some questions
.
This is my scenario, any help will be appreciated

I use Mesa cards with servo and io cards (7i33, 7i37)

I have a long section of metal that is fed through the machine. The machine is 2m wide with a multiple tool head in the center. The section is pulled into the machine and I have an encoder that counts the travel of the material (X axis). The encoder is located at the edge of the machine. As the material is pulled through, the encoder on the other side will start to count when the section starts to exit the machine. When the end of the section is in the middle of the machine, the first encoder is not counting but the second one is. This enables us to machine the section to the very end. In essence, both the encoders report the same position of the axis. I just need to decide when to couple which one to the loop. Being new to LinuxCnc ..... not so easy.
The administrator has disabled public write access.

Re:Two encoders on one Axis 03 Ago 2012 05:42 #22718

  • andypugh
  • andypugh's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4139
  • Thank you received: 141
  • Karma: 130
mariusl wrote:
As the material is pulled through, the encoder on the other side will start to count when the section starts to exit the machine. When the end of the section is in the middle of the machine, the first encoder is not counting but the second one is

This was recently discussed on the mailing list in a slightly different scenario. (a sectional linear motor).

In that scenario there was a risk of cumulative errors on the switch-over, but assuming that with your machine the part only travels once through the machine, this is not a problem for you.

You can probably switch to the exit encoder as soon as the X-position > the distance between the encoders.

One way (not the neatest, but good enough) would be to use encoder1 while X < critical_length and encoder2 + critical_length for X > critical_length.
It is very important to reset both encoders before loading a new workpiece with this approach. You also need to zero encoder 2 on switchover.

Use "comp" www.linuxcnc.org/docs/html/man/man9/comp.9.html to set a flag based on length
use "mux2" www.linuxcnc.org/docs/html/man/man9/mux2.9.html controlled by that flag to switch between the encoder positions
use "sum2" www.linuxcnc.org/docs/html/man/man9/sum2.9.html to add the fixed offset to the second encoder position.
use "edge" www.linuxcnc.org/docs/html/man/man9/edge.9.html to generate a reset pulse for encoder 2 on changeover.

Is this enough. or do you need a sample HAL file?

I think this is the simplest solution, though it would be better to work in encoder counts, latching values and summing deltas.
A custom HAL component might be worth considering.
The administrator has disabled public write access.

Re:Two encoders on one Axis 03 Ago 2012 05:55 #22719

  • mariusl
  • mariusl's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 0
Thanks for the reply. I am very new to this so a sample HAL file will help a lot.

I my case there are no offset between the encoders as they both represent the same material position in the x axis. It is just a matter of which one to use. I am not sure how to select the encoder and how to go about that in EMC. The logic is easy. I will read the links that you gave first and then try again to understand
The administrator has disabled public write access.

Re:Two encoders on one Axis 03 Ago 2012 06:19 #22721

  • andypugh
  • andypugh's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4139
  • Thank you received: 141
  • Karma: 130
Actually, forget the edge and resetting Encoder2, I confused myself halfway through.

Consider the case where the two encoders are 666mm apart.

They are both reset when a new workpiece is selected. As the work moves through the machine encoder1 counts the length and encoder2 stays at zero.
The material touches encoder2 at X = 666. Now encoder 1 counts up, and so does encoder2, but encoder 2 is reading low by 666mm. At this point we can use either encoder, as long as we add 666 to encoder2.
At some later point we can switch to encoder 2.

After some thought, a better scheme:

Reset both encoders.
Wait until encoder2 reads> 25mm (for example).
Store the length measured by encoder 1 at that instance (d1). Store the exact length measured by encoder 2 at that instant. (d2)
Switch to using Encoder2 + d1 - d2 as the length measurement.
This way you don't need to know the distance between the encoders, and a "bumpless" changeover is certain.

I need access to a LinuxCNC machine to set up the HAL for this, though.
The administrator has disabled public write access.

Re:Two encoders on one Axis 03 Ago 2012 06:54 #22723

  • mariusl
  • mariusl's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 0
You summed up exactly what I need. Now unless you are a masochist, you will have to give me some example stuff man. It will torture me if you know how to do it and I don't have a clue at all.
The administrator has disabled public write access.

Re:Two encoders on one Axis 04 Ago 2012 11:15 #22786

  • andypugh
  • andypugh's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4139
  • Thank you received: 141
  • Karma: 130
mariusl wrote:
t will torture me if you know how to do it and I don't have a clue at all.

OK, this should be close, but I can't really test it without your config. You will need to splice it in, and deal with the problems one-by-one.
loadrt comp count=1
loadrt sum2 count=2
loadrt mux2 count=3 #sample-hold is what is needed, but that is the wrong datatype

addf comp.0 			servo-thread
addf mux2.0 			servo-thread
addf mux2.1 			servo-thread
addf mux2.1 			servo-thread
addf sum2.0 			servo-thread
addf sum2.1 			servo-thread

setp hm2_5i23.0.encoder.00.scale [AXIS_0]ENCODER_SCALE
setp hm2_5i23.0.encoder.01.scale [AXIS_0]ENCODER_SCALE #not right if encoders differ

#net new-part to a PyVCP or physical button to load a new part. 
net new_part hm2_5i23.0.encoder.00.reset

#sample holds
net pos0 hm2_5i23.0.encoder.00.position mux2.0.in0
net latched0 mux2.0.in1 mux2.0.out 
net pos1 hm2_5i23.0.encoder.01.position mux2.1.in0
net latched1 mux2.1.in1 mux2.1.out 

#switch-over trigger
setp comp.0.in0 25 #this is the reading on the second encoder when it takes over
net pos1 comp.0.in1 
net trigger comp.0.out mux2.0.sel mux2.1.sel

#offset calculation
setp sum2.0.gain1 -1 #subtraction
net latched0 sum2.0.in0
net latched1 sum2.0.in1
net offset sum2.0.out sum2.1.in0
net pos1 sum2.1.in1
net pos1-mod sum2.1.out

#arbitrate between the encoders
net pos0 mux2.2.in0
net pos1-mod mux2.1.in1
net trigger mux2.2.sel 
net actual-position mux2.2.out

#actual-position is the signal you would use for the feedback to the PID. For example:
#net actual-position pid.0.feedback axis.0.position-fb
Last Edit: 04 Ago 2012 11:17 by andypugh.
The administrator has disabled public write access.

Re:Two encoders on one Axis 04 Ago 2012 11:50 #22788

  • mariusl
  • mariusl's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 0
Thanks Andy
Your code helps a lot. I also went to see a friend today that has more experience at this that what I have. We concluded that I should write a component but I think your way might be better As it looks like I can use the built-in stock components to achieve the correct result.

Thanks you have been very helpful thus far. I will probably have to ask a whole lot more questions though.:unsure:
Last Edit: 04 Ago 2012 11:51 by mariusl.
The administrator has disabled public write access.

Re:Two encoders on one Axis 04 Ago 2012 12:07 #22791

  • andypugh
  • andypugh's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4139
  • Thank you received: 141
  • Karma: 130
mariusl wrote:
We concluded that I should write a component but I think your way might be better As it looks like I can use the built-in stock components
It is very much at the sort of level of complexity where a component makes sense.
Put it this way, if it was _my_ machine I would have written a component. However that requires compiling and installing some tools.
The administrator has disabled public write access.

Re:Two encoders on one Axis 04 Ago 2012 12:12 #22793

  • mariusl
  • mariusl's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 147
  • Karma: 0
I might still have to do that as this is just the first problem. The machine has several other abnormal operations that I will have to cater for. A lot of safety interlocks that I want to integrate with the control. Oh and a couple of special buttons that are used to prepare the machine for the job. Maybe a component is not that bad an idea still. I will have to install the development stuff anyway.
The administrator has disabled public write access.

Re:Two encoders on one Axis 04 Ago 2012 12:21 #22795

  • andypugh
  • andypugh's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4139
  • Thank you received: 141
  • Karma: 130
mariusl wrote:
Maybe a component is not that bad an idea still.
The only reason not to might be if you want it to be easy for someone else to maintain in the future.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 1.365 seconds
Powered by Kunena Forum
© 2013 LinuxCNC.org
Joomla! is Free Software released under the GNU General Public License.