Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #20104

Re: encoders measurements in speed control loop

From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.arch.embedded
Subject Re: encoders measurements in speed control loop
Date 2015-02-16 15:21 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <mbt1tb$s22$1@reader1.panix.com> (permalink)
References <ckdr69F3at4U1@mid.individual.net>

Show all headers | View raw


On 2015-02-16, alb <al.basili@gmail.com> wrote:

> In general if the encoder reading is in the same turn as the table
> than everything is fine:
>
> p = 78 deg (position)
> m = 75 deg (measure)
>
> e = p - m = 3 deg
>
> But when I cross the 0 deg (360 deg) I have some stupid issues with signs:
>
> p = 359 deg
> m = 1   deg
>
> e = p - m = 358 deg
>
> while I would like to get -2 deg!
> Even with modulo function I'd not be better off:
>
> e = mod(p - m, 360) = 358 deg!
>
> Should it be dependent on the quadrant I'm in?
>
> I'm missing some basics here. And yes, a pointer to elementary school 
> math is definitely appreciated!

The way this used to be solved "back in the day" when I was writing
code for Navy fire control computers is that you pick a word width for
which your architecture supports both usnigned and 2's compliment
arithmetic (let's say 16-bits).  You encode 0 degrees as binary value
0, and you encode 360 degrees as 2**16 (also represented by binary
varlue 0). [This was referred to as BAM encoded: Binary Angular
Measurement].  Now you do all your arithmatic using normal integer
math.  If your answer is supposed to be a 'relative heading' then you
want the '-2' answer and you cast the value as (int). If the answer is
supposed to be an absolute heading then you want the '358' answer and
you cast the value as (unsigned).

Those computers had single instructions to do trig functions on BAM
values, and also a single instruction that converted a (radius,BAM)
polar tuple [in a register pair] pair into an (easting,northing)
cartesian tuple.  And there was another instruction that did the
converse.

A lot of the protocols and peripherals were specified so that angular
data was represted as BAM encoded words.

-- 
Grant Edwards               grant.b.edwards        Yow! Well, O.K.
                                  at               I'll compromise with my
                              gmail.com            principles because of
                                                   EXISTENTIAL DESPAIR!

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

encoders measurements in speed control loop al.basili@gmail.com (alb) - 2015-02-16 09:22 +0000
  Re: encoders measurements in speed control loop al.basili@gmail.com (alb) - 2015-02-16 10:06 +0000
  Re: encoders measurements in speed control loop Grant Edwards <invalid@invalid.invalid> - 2015-02-16 15:21 +0000
    Re: encoders measurements in speed control loop Tim Wescott <tim@seemywebsite.com> - 2015-02-16 10:30 -0600
      Re: encoders measurements in speed control loop Grant Edwards <invalid@invalid.invalid> - 2015-02-16 17:07 +0000
        Re: encoders measurements in speed control loop Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2015-02-16 20:09 +0200
  Re: encoders measurements in speed control loop langwadt@fonz.dk - 2015-02-16 11:52 -0800
  Re: encoders measurements in speed control loop Bruce Varley - 2015-02-17 20:14 +0800
    Re: encoders measurements in speed control loop Tim Wescott <seemywebsite@myfooter.really> - 2015-02-17 13:03 -0600
      Re: encoders measurements in speed control loop Bruce Varley - 2015-02-18 20:38 +0800
        Re: encoders measurements in speed control loop Tim Wescott <seemywebsite@myfooter.really> - 2015-02-20 12:27 -0600

csiph-web