Log in

View Full Version : Encoder Issues



Support (Admin)
04-24-1999, 04:03 PM
THREAD FROM ARCHIVE
================================================== =
From: Robert Beal 05 Dec 1998

How do I check to see if my encoders are working? I really don't think they are. I was cutting a train track file for my boy for Christmas on a four by eight MDF, and the further I got away from the origin the farther out each pass got. (+/-1/2" on the X axis and +/- 1/4" on the X) This happens in either direction of the previous pass, so it is not a calibration problem.

My machine won't stall. When it hits its travel limits, it will just sit there and grind away, never giving me a stall message.

-----------------------------------------------------
From: Ted Hall

Hi Robert,

I'm going to provide some encoder background here, and then some info on testing out the encoder aspects of your system. But with respect to your last question, something is not working right if your tool is stalling and the encoders are not sensing it. We'll go over what that could be at the end of this little discussion.

**Note that this message applies only to Cable-Drive ShopBots**

How the encoders work:
-----------------------------
First some data on what the encoders are doing ... they are what are called incremental quadrature optical encoders. Each encoder can send output pulses on 2 channels. The pulses are produced by a little wheel with slits turning between two LEDs and two photo sensors. Each channel can be either ON or OFF as the light to it is either blocked or not blocked (the sensors have circuitry that makes their output pulse all or none, digital). There are 128 of these slit transitions for each of the channels in a revolution of the encoder shaft. The interesting thing is that the two channels are offset from each other by 1/2 of a phase (technically, 90 degrees). So this means we can have: both channels off, the first channel on with the second off, both channels on, the first channel off with the second on ... then the whole thing starts over again. This offset signaling increases the number of states and thus the resolution of the encoder, and more importantly, it allows detection of which way the thing is going. For each revolution of the encoder, if we are looking at both channels, there are thus 512 transitions. Depending on the diameter of the encoder sprocket, this means there are about 120 to 150 transitions per inch of travel of your tool.

Because each channel is ON or OFF, we treat it as a binary signal and give the first channel a value of 1 when it is on and the second a value of 2 (this is actually thought of by software people as 2^0 and 2^1, for how the value of the first bit #0 and the second bit #1 are coded). That means, as the encoder rotates it generates the sequence (++=ON; OO=OFF):

Outputs |
Encoder | Value of| Computed Total
Channel | Outputs | Encoder Value
1......2|
--------
O......
O.....O | 0.....0 | 0 (channel 2 offset)
+.....O | 1.....0 | 1
+.....+ | 1.....2 | 3
O.....+ | 0.....2 | 2
O.....O | 0.....0 | 0
+.....O | 1.....O | 1
+.....+ | 1.....2 | 3
and so on ... (sorry not to have a better picture)

So reading the output from the encoder in this fashion, if it is rotating one direction you see the values 0 - 1 - 3 - 2 and going the other direction 0 - 2 - 3 - 1. Thus the software keeps up with where your ShopBot is by studying the output pattern from the encoder in terms of the change from one value to another. The encoder does not provide an absolute location value, only a continuous update of the encoder transitions and their direction that have been made since the software was started or since the location reset or zeroed. For example, if we get a transition from 1 to 3, we know we moved UP ONE location. If we get a transition from 2 to 3, we know we moved DOWN ONE location (and locations can be translated into inches).

The most important thing here is that the reliability of the translation of the encoder input depends on the reliability of our the encoder output and our reading of it. If for some reason, the encoder were to skip a number/location (e.g. going from 0 to 3) we would not know whether those two steps were in the up direction or in the down direction. We call this an encoder 'skip'. It creates an error situation that is difficult to resolve. (There could be even bigger skips and worse errors, but we would never know they happened since the numbers would look like they were in sequence.) So, to increase the redundancy of the system and prevent 'skips' we arrange things such that a number of reading will be made at each encoder location condition so that we can be very confident that no transitions will be missed. In practice, ShopBot reads the encoders each time the tool makes a step. Thus we set things up to take about 4 steps for every encoder transition. This means, the step resolution of the cable drive tool is about 500 steps per inch and the encoder resolution is about 125 transitions per inch. The result is, we have about 4 readings to make sure we do not miss an encoder step. (As an aside FYI, ShopBot uses the encoder information to update where it 'knows' the tool is, and uses the step count to interpolate where it is between the encoder locations. Thus an encoder ShopBot has a theoretical accuracy of about 1/500th, but the stretchiness of the chain and cable make 1/50th closer to the achieved resolution.)

In the best of all worlds, the encoder redundancy we've built into the system would take care of all of our problems. But we have two significant additional concerns that have to be considered: electrical noise; and , variability in the phase relationships in the encoders. With respect to electrical noise, spikes on the encoder data lines can create both false ONs and false OFFs. To deal with this, we filter the data lines electrically. Then we filter the lines in the software again, using the redundancy described above to rule out transitions that appear transient. We believe these hardware and software solutions handle all the noise conditions that are likely to encountered ... but you never know. See below for diagnostics.

The encoders are relatively expensive at about $40 each. None-the-less, the specs on the phase relationships between the two data lines in these devices is +/- 45 degrees. This means the overlap between channels can be off by half !, and this could reduce the redundancy on a channel down to only a couple of readings -- combined with electrical noise, this would create problems. Worse, in our experience, the 45 degree specs may be optimistic and the encoders may get more out of phase with vibration. So what we do is pre-screen the encoders for proper phase relationships before we put them on a tool to try and make sure you won't have a problem with phase. In addition, I'll describe a diagnostic approach below that allows you to have a look at what's happening with your encoders.

As well as the filters described above, the software includes algorithms for resolving encoder skips and other discrepancies. If your encoders are functioning relatively normally these algorithms will solve most occasional glitches. What we have to watch out for, is a situation where consistent errors (particularly skips) are being generated for one reason or another ... and often, if there is a problem, we usually discover it results from a combination of things.

Checking encoder function:
--------------------------------
We have built into your software several functions for testing your encoders and adjusting how they interact with your tool. But the first thing we should do is make sure that your encoders are, in fact, turned on in the software. Use the [UV] Command to look at the line labeled 'Backlash'. The last two number will be -1 and -1 if your encoders are enabled and 0 and 0 if they are off. Because the software runs both encoder and encoder-less ShopBots, there is a software switch to change the encoder mode of operation. So if you have 0's at the end of the Backlash line, turn the encoders on using the [VK] Command. The encoder setting are the 8th and 9th parameter. After entering VK you would enter 7 commas then -1, -1. Use [UV] to check your change. [An encoder tool will run with the encoders turned off, but it will gradually accumulate location error because of the imprecision of the drive-cable-to-step relationship. However, turning the encoders off can sometimes be a useful diagnostic technique in identifying whether a power problem is a result of something the encoders are doing.]

Your first check for encoder problems is to use the [UD] display. Run your tool around. Have it do some of the moves or cutting that you think may be generating a problem. Then look the Encoder status line in [UD]. In Version 1.8 software you will see a single set of brackets with 2 numbers, in Version 2 software you will see two sets of brackets and numbers. These numbers indicate the number of encoder 'skip' errors encountered since the software started running. In 1.8 the first number is the X axis encoder the second number the Y. In Version two, the first set of numbers are for the X axis, the second set for the Y. The Version 2 software is more sensitive and more informative, so I'll discuss it from here. The first number in the Version 2 bracket is the total number of skips for the encoder on the axis, the second number is the number of errors that were -not- confidently resolved by the software. Ideally, all the numbers should be zeros. In practice, your tool and software will handle a few errors without a problem. So if after running the tool for awhile, you have no more than a couple of errors on either channel (say 3 or less), you are OK. If you see a larger number, and in particular if the second number in the set is not reduced to 0, 1 or 2, then we have a problem. As well, while you have the [UD] display up, make sure there are no communications problems reported.

If you have a problem, or if you just want a better look at what your encoder is doing, let's move deeper. At the bottom of the [UD] display you'll notice the option to access the ShopBot Test routine by hitting the letter 'T'. Go ahead and do it. You will be disconnecting your tool from the normal software and hooking it up to a system for testing individual functions. There is an initial screen describing this system. Skim through it and then hit any key to continue to the test routine. It will be a black and white display.

The Test Routine directly runs the motors without any interaction with the encoders. However it provides displays of the encoder output so we can see what is going on with their output. First, check out how this all works. If you hit an 'x' the X axis will start moving. If you hit a 'y' the Y axis will now move ... and so on. Hitting a Capital 'X' or 'Y' will change the direction of the axis. Hitting an 'o' (letter o) will stop things. This direct control of the motors provides an easy way to make sure that a motor is working correctly, independent of the operation of its encoder.

Now though, we're more interested in the encoders. So slow things down a bit by hitting 'd' then typing in 1000 and hitting Enter. This will increase the delays between steps so that the tool will move more slowly. Now hit an 'x' to start the X axis moving. It will be going slower, and you will be able to study the Encoder Values that are displayed under the X-Encoder and the Y-Encoder label towards the top of the display. The X value should now be changing. It should be going 0 1 3 2 over and over again, as we discussed above. Hit a 'y' and the Y encoder should also display this numeric pattern. Changing direction will reverse the order of the numbers. The first issue here is whether all 4 of the numbers are displaying. If you are just seeing 2 numbers over and over again, then one channel on that encoder is not working. The encoder may not be working because the encoder channel itself is bad, or there may be a break in the wiring.

If your encoders pass this first test, let's take a closer look at their output. Get the X axis going again and hit the number '1'. The display will change and start filling the screen with numbers. This screen is continuously streaming the output of the X encoder. What you will see are the changing numbers. However, now there will be 3-8 of them repeated before the change to the next number. Watch as things move along. An occasional set with only 2 repeats is probably OK, but not ideal. We really want 3 or more in each batch to make sure we get reliable samples. If you have sets with just one of a number, then we have a weak encoder phase and it is probably causing problems for you. Run the X axis both directions because the phase relationships can change with direction. Switch to a display of the Y encoder output by hitting a '2' and then set the Y axis moving and check it out. You can use '0' (number zero) to return to the original display.

There is a second test for phase relationships in the encoder output. Start the X axis moving again and hit the number '3'. You will get a new display (you may need to let it recycle once to be accurate). This display looks like a horse race. It is a running count of the proportional output of each phase of the encoder -- the number of 1's 2's etc... A rough rule of thumb here is that if all four numbers are at least half-way across the screen when the first number reaches the far right, then things are OK. If however, there is a number that lags by more than half a screen, we have a weak phase that is a potential problem. Again, run the motor both directions here. You can test out the Y axis by hitting the number '4'. A '0' will return you to the original screen.

The two tests above will let us know whether your encoder is functioning correctly. We are also interested in its susceptibility to electrical noise. To test for noise effects, hit a '1' to start the display of the X encoder, then run the Y motor and the Z motor, switching back and forth between them frequently. You should see a single number repeated continuously on the X encoder output. Any change from that number (just a single instance) would indicate that the encoder has picked up electrical noise from the other encoders. Move the X axis a bit so that it is outputting another number (different phases activated) and then do the test again. Add to this test, turning off and on lights, motors, compressors, tools or anything else in your shop that could conceivably generate electrical spikes. Then try these things again with the Y axis. Watch several pages worth of displays, a single glitch indicates a significant problem with electrical noise since electrically generated errors are difficult to resolve. The Y axis is usually the most susceptible to electrical noise because it has a longer wire (antenna) ... so check this one out well. If we can identify what is causing the noise, we may be able to deal with it.

These evaluations will complete the analysis of the operation of your encoders. If they check out, then you are unlikely to be experiencing electrical difficulties with the operation of your encoders. Therefore, if you are still having problems with distances or locations, the problem is likely to be mechanical. The chain may have stretched too much, it may be drooping too much, or the sprocket may be slipping on the encoder. Also make sure the encoder is mounted tightly and is not itself rotating or wiggling. Have a look at each of these possibilities.

In addition, you can consider altering the tolerance settings that define the encoders interaction with the software. This is particularly appropriate for tools that are longer than the normal 8'. Check the current tolerances with [UV]. You will see 3 values listed 'Steps to Stall', 'Steps to Slip', 'Steps to Start' in the listing. The first value, 'Steps to Stall' is the how many steps without an encoder change (beyond the expected number of about 4) that the software will take before alerting you to a 'Stall' condition and stopping the tool. The default setting of 1000 means the tool will try to go about 2" before stopping and alerting you. The 'Steps to Slip' is the number of steps without an encoder change that will be taken before compensating the movement of the other axis. The default of 20 means an axis will go about 1/25 inch before compensating the other axis. The 'Steps to Start' value reduces the compensation of the other axis to a lower value at the start of a move to insure that all backlash in the chain and cable are taken up before the axes move off together. If these latter 2 numbers are too low your tool may overcompensate and hunt back and forth between X and Y, particularly in short diagonal moves. Increasing the numbers reduces sensitivity to slipping. If you are having location problems, particularly at the end of groups of back and forth moves, you could decrease the sensitivity by doubling the 20 and 10 to 40 and 20 and see if this corrects the problem.

In order to interpolate the correct distance of steps in determining location, and so that the initial vector for a move can be accurately computed, the software keeps a running average of the relation between steps and encoder locations. Slipping and stalling of the tool can disrupt this averaging. After a slip or stall, make sure the tool has the opportunity to move several inches to re-establish these running values before doing any precision moves or calibrations.

Finally, if you ever experience a problem with locations or movement distances and you are unable to locate a specific problem, you should delete the configuration file (Shopbot.cfg in 1.8 software and Shopbot.ini in Ver 2 software), run the tool several feet in both axes, then re-assess the situation. Before deleting the configuration file, copy down your Unit Values (display with [UV]) so you can re-enter them with [VU].