Skip to main content

Speed, Encoders and homing

Matt's picture
Posted in

Hi,

I have a couple of ideas that I would like to dicuss with you.

First of all, I think what is needed is a possibility to manipulate the motor speed or the speed ramp while moving during an interval . For long intervals, one could then set a very slow motor speed, which would prevent the motor from missing steps (and the rig from jittering) and allows for real time motion control.

For "real" motion control, the engine should be able to process input from encoders. I'm not sure if there are any pins left on the Arduino 2009, but maybe it'll be worth it to upgrade to an Arduino Mega to have more input pins available, since encoder support would definetly be a very professional feature to have.

If the engine sends the motors home, it does this at full speed. On my rig, this usually means the motors loose steps. With ramping or speed control of the homing, this could be prevented.

If you like to add the stereoscopic stuff, that would be great. I just came across this idea after having seen Avatar ;-).

I had a look into 0.82 and I am very impressed with the features you added. Keep up the good work !

Matthias

Matthias, You shouldn't ever

Matthias,

You shouldn't ever have any missed steps - no matter the distance moved. What stepper driver are you using? The primary causes of missed steps are not waiting long enough between step requests, too much/too little power going to the motor, and, of course, simply not sending the step request.

Have you tried making MIN_STEP_DELAY longer? I say this, because if you're missing steps on long runs, you're just as likely to miss them on short runs too. (So, if you miss 1 out of every 1000 steps on a long run, you run a similar chance, not exact, but similar, on shorter runs.)

The basic formula I've used to prevent missed steps is the same used on my stepper CNC machine (both with EMC2, and with Mach3), which is to set a maximum step speed (the value of MIN_STEP_DELAY, by default of 500 uS = 2,000 steps/second), and given velocity. Normally, missed steps (or overshoot!) will happen at the beginning or end due to poor velocity setting, and steps in the middle due to too high of a step rate. The velocity also reduces the jitter, in that it will slow down as it reaches the end of the move, and speed into the start of the move - preventing jittery starts and stops.

The velocity ramping is hard-coded at the moment, but I can make that adjustable. That is, velocity is determined by (MAX_STEP_DELAY - MIN_STEP_DELAY) / ( steps_requested / 3), the division by 3 is automatically reduced by 10% (continuously) until the difference between each step speed change is at least 1uS. So on the longer moves, the first 500 steps (using default values) will each be 1uS faster than the previous step, until the speed reaches 500uS between steps.

Can you try increasing MIN_STEP_DELAY and MAX_STEP_DELAY (doubling them would be a good place to start), and see if the causes the missed steps to go away? I suspect the issue lies there, and using variable speeds may mask the issue that could occur in shorter moves as well.

I doubt it would be in the velocity adjustment, but just in case - if adjusting the min/max step delay settings _together_ doesn't do the trick, can adjust the velocity by _only_ increasing the MAX_STEP_DELAY. That is to say, anything else done in the code won't fix the problem, because the minimum speed change between steps will always be 1uS. The algorithm will always move you back to this point if you try to extend the velocity amount - as not doing so will result in error, much worse than you have now. =) By increasing the MAX_STEP_DELAY, but not adding a subsequent increase to MIN_STEP_DELAY, you will increase the difference between them, and thereby add more steps to the velocity ramp. (Doubling the different between MAX and MIN will double the steps it takes to speed up to full speed on longer runs. It may, however, have a negative impact on shorter runs as with fewer steps, the increase in speed between steps will be much higher.)

We definitely have the pins available for encoders. I think I have four already available - especially since but I want to kill the ALT IN/OUT, so I can use i2c anyhow. If I keep the alt in/out, and also keep i2c, we'll definitely be short pins, and all channels would have to share the same encoder line, which could create serious issues. I have largely ignored the feedback stuff at this point, as it was going to drive the cost up for the small DIY guy, but I don't see any reason why the support can't be there for the people who can afford it! I'll look and see, but I'm presuming it would be fairly simple, if we limit to particular kinds of encoders (i.e., pulse encoders would be easy, but quadrature would probably be a nightmare). Of course, even with pulse encoders, it's going to be tough to find enough interrupts available on the existing board to read more than one. (And blocking while reading will not be an option, as it will kill the motor control functions.) So, that may still mean one shared encoder line for all axes.

Let me know if you can try adjusting the step delay, and see if that eliminates the problem. Your dolly should be able to move at a given max speed, no matter the distance - its just that other factors may be coming into play (friction, etc.) and you may have to slow it down. For example, my CNC will do jogs and rapids easily at 100 IPM, but when I add arcs or am cutting in material, my "real" max speed is 60IPM - anything faster and I miss steps.

!c

Chris, thanks for the

Matt's picture

Chris,

thanks for the elaborate answer.
I have changed the MINSTEP/MAXSTEP setting (doubled the values) and that seems to have helped. But I also have installed more powerful motor drivers (L297/298)...
If the MINSTEP/MAXSTEP setting would be adjustable, I think that will be sufficient for real time motion control, it just needs to be (re-)set all the time. But it might be good to have a upper and lower threshold value anyway so step loss can be prevented when adjusting motor speed.

Pulse encoders will be perfectly fine I believe. If no steps are lost the encoder input is the same as the moved steps, so basically they would be for checking wether or not steps have been lost. I would consider this as a request with little priortiy ;-).
I personally like the ALT IN/OUT feature, especially for timelapse. I would keep it. (For switching on lights or raindeflectors, capping shutters etc...)

One strange thing occured, while I was testing the homing function.
I set home for a motor, moved it for a couple of steps (maybe 200) and then sent the SEND HOME ($01 $02 $07 $MotorNumber) command. Strangely the motor did not move to it's origin but exactly the other way for what it seems the exact number of steps it would have taken to go home. If I set home and move the motor in the other direction, SEND HOME works exactly as it is supposed to. It seem like the SEND HOME command does not care for the direction. You might want to take a look into that.

Matthias

Uh oh! Thanks for finding

Uh oh! Thanks for finding that. I'm having a little trouble tracing down the issue though, could you provide me a little more info to help re-create the problem? Namely, when the motor moved away from home, what direction (0 or 1) were you going previously, and when the motor moved towards home, what direction had you been going then?

I'll make min/max step delay adjustable in the near future, it's no big deal to do that. Still working on the stereoscopic shooting function.

For continuous motion, I'll definitely have to re-write large portions of code (is that what you meant by real-time?) - I just need to see what interrupts I can steal for that, it may end up having to be a choice between alt in/out and real time w/ the current implementation. (Or, even, a choice between i2c and alt/in out =)

Someone else has asked me to keep the ALT in/out, so I guess I'm just getting ahead of myself there. There are a few issues that Milapse and astronomerroyal reported, namely in that in the latest NewSoftSerial, it's obfuscated the pin change interrupt assignments, so I have to re-think which ones I'm going to use, and how to adapt to his new code and avoid impact.

!c

I think the only thing you

Matt's picture

I think the only thing you have to rewrite for continous motion (or what I call real time moco) is changing the minimum interval time from seconds to microseconds, anything else yould be handled by the interval then (for example a 40 Microseconds Interval equals 25 fps). The interval pulse can then be used as a sync pulse to drive the video/film camera.
Or better, make the minimum interval selectable by the user (or as a constant in the code), so we don't end up with rather short interval times when shooting timelapse.

Actually I have no idea how big the impact on the code is, but to me it sounds like a simple thing to do, probably I'm wrong ;-

I will try to create a log file for the homing issues..

Matthias

I checked the homing issue.

Matt's picture

I checked the homing issue. It only occurs when the direction byte of the movements prior to sending the home command is 0x01. I could send you a log file if you want, but it will probably be hard to read. If the direction byte is 0x00, it seems to be fine. I checked this for motor0 and motor1, same behavior on both axis.

I hope you can find the error. Good luck!
Matthias

I've been able to replicate

I've been able to replicate the problem. Just spent a couple of hours tracing down a different bug in 0.82 (and boy did it make me feel dumb =) - so I should be able to attack it very soon.

Doing a test w/ the new pan+tilt prototype running 0.82. Looking pretty good so far. Will post some pics up tomorrow, but this weekend's work really paid off!

!c

Matt, The homing issue is

Matt,

The homing issue is fixed in last night's checkin to subversion. Also fixed is a focus tap issue. I'm still looking into how to better handle velocity changes, I expect that to take some more time.

!c

Using PS2 for linear

Using PS2 for linear encoder?

I have also been pondering the encoder question since I started examining this fantastic project. Rotary encoders of any value are comparatively expensive to some of the alternatives for measuring linear travel. On the cheaper end of the scale are things like utlizing the Ping))) sensor that seemingly every Arduino book covers. Then there are a number of home made optical solutions that can relatively easily do quadrature encoding by shooting a laser-printed target affixed to one of the drive components with multiple optical sensors.

However, I am currently infatuated with the concept of utilizing the PS2 library and one of the many optical mice that are commonly laying around most geek's benches. It seems as though this could be a nearly ideal solution as it really communicates via serial and includes a multitude of information. Imagine extending the mouse buttons as a homing/limit input on either side of a dolly. The resolution of the average optical mouse is easily better than a tenth of a mm, use a laser mouse and it is into the thousandths.

I haven't done any experimenting yet, nor do I know that I ever will; but I just couldn't let the idea go without being said. It certainly gives the economy of dc gear-motors one more reason for existing!