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


Groups > comp.arch.embedded > #20106

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 17:07 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <mbt84g$ani$1@reader1.panix.com> (permalink)
References <ckdr69F3at4U1@mid.individual.net> <mbt1tb$s22$1@reader1.panix.com> <yOOdnTGH54q4hn_JnZ2dnUU7-R-dnZ2d@giganews.com>

Show all headers | View raw


On 2015-02-16, Tim Wescott <tim@seemywebsite.com> wrote:
> On Mon, 16 Feb 2015 15:21:15 +0000, Grant Edwards wrote:
>> On 2015-02-16, alb <al.basili@gmail.com> wrote:
[...]
>>> 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.
>
> Heh.  I used that back at my last corporate job without ever knowing 
> there was an official name for it.

Turns out there's a nice writeup on Wikepedia about it:

  http://en.wikipedia.org/wiki/Binary_scaling#Binary_angles

> It's convenient as hell, and quite satisfying to be able to use fixed-
> point rollover for gain, instead of having it do horrible things to you.

Yep. There were some very expensive, wildly inefficient, and sometimes
just horribly designed features in some of those shipboard 
mini-computer systems, but I was impressed with the binary angule
stuff and the thought that went into the extra machine instructions to
support it.

-- 
Grant Edwards               grant.b.edwards        Yow! I'll eat ANYTHING
                                  at               that's BRIGHT BLUE!!
                              gmail.com            

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