try changing line 38 from:

out = (int)(rtapi_s64)(value * scale);

to 

out = (int)(rtapi_s64)((value * scale)+0.5);


This looks like a case where the floating point 'value' might be 3.9999999, but 
the conversion to integer results in 3
Adding 0.5 makes it round to the nearest integer.

Although I bet that will make it worse, not better, for negative input values.

There is an "all integer" way do to the lowpass filter that is immune to the 
rounding problem, but first step is to confirm that it is indeed a rounding 
problem.

John


On Fri, Mar 31, 2017, at 02:48 PM, Stuart Stevenson wrote:
> Gentlemen,
>  Having the problem on 4 mpg's (three single and on diff) I am relatively
> sure the problem isn't hardware.
> 
> Halshow (watch) shows the encoder counts accurate and ilowpass counts are
> incorrect I suspect ilowpass.
> ilowpass is so simple it is almost impossible to see how it could be
> incorrect also it has run correctly on the same machine for years without
> problems.
> 
> I blame the change that was made and that is the new operating system and
> the new LinuxCNC version.
> 
> The hal file shows everything running on the servo thread. It is the same
> hal file as before.
> 
> I moved the ilowpass down the list to right in front of the write statement.
> 
> I have the same result.
> 
> The initial direction loses a count.
> 
> ppmc encoder count moves 4 each detent.
> ilowpass moves 3 for the first move and 4 thereafter
> motion reversal resyncs the counts until zero is reached
> reversing again loses a count again as long as zero has not been passed
> 
> results as follows
> 
> start machine
>       encoder count = 0
>       ilowpass in = 0
>       ilowpass out = 0
> 
> move positive one click
>       encoder count = 4
>       ilowpass in = 4
>       ilowpass out = 3
> 
> this relationship is maintained while moving in the same direction for as
> far as I moved
> 
> upon motion reversal encoder count, ilowpass in, and ilowpass out are the
> same until I pass 0
> 
>       the next click past 0 the count then becomes
>       encoder count = -4
>       ilowpass in = -4
>       ilowpass out = -3
> 
> and it maintains this relationship until motion reversal
>       upon motion reversal the counts are the same again until I go past
> zero.
> 
> The same but opposite behavior depending on counts being positive or
> negative.
> 
> all comments/suggestions welcome
> 
> thanks
> Stuart
> 
> -- 
> Addressee is the intended audience.
> If you are not the addressee then my consent is not given for you to read
> this email furthermore it is my wish you would close this without saving or
> reading, and cease and desist from saving or opening my private
> correspondence.
> Thank you for honoring my wish.
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Emc-developers mailing list
> Emc-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/emc-developers


-- 
  John Kasunich
  jmkasun...@fastmail.fm

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to