Saturday, September 30, 2017

What are BAMs?

BAMs stands for Binary Angular Measurements.  A BAM is an unsigned short data type which can store a value between 0 and 65,535.  BAMs are used to represent an angular measure; there are 65,535 BAMs per 360°.  An angle provided in BAMs can be converted to degrees by the following relationship:
Angle (Degrees) = (360 / 65,535) * Angle (BAMs)
I got this definition from this website:  
https://ssreng.com/what-are-bams/
However, you can change this a bit to get a floating point number:
Angle (Degrees) = (360.0 / 65,535) * Angle (BAMs)
Just make it 360.0 or in C cast the 360 to a float.

The reason for BAMs, in my opinion, is to store an angle as an unsigned integer.  You can store the angle in a C struct, you can write the struct to a file on disk or tape, or you can send the data through TCP/IP.  Do not think about storing data as floating point or sending floating point through the network.

Consider how you send data through TCP/IP:  you use functions to set the numbers to network byte-order (big endian). Look at this webpage:  https://linux.die.net/man/3/htobe32.  Functions are used to convert from host (computer) to network byte order. See these functions in /usr/include/endian.h
uint32_t htobe32(uint32_t host_32bits);
uint32_t htole32(uint32_t host_32bits);
uint32_t be32toh(uint32_t big_endian_32bits);
uint32_t le32toh(uint32_t little_endian_32bits);

All of these functions work on unsigned integers.  These functions will not work with floating point numbers.  You definitely use unsigned integers for BAMs, and you can actually do your calculations with scaled integers.  Some people think the calculations are faster with integer operations instead of floating point operations, as mentioned in this article on binary scaling:  https://en.wikipedia.org/wiki/Binary_scaling

The point I am stressing is the need to store and transmit data as integers.  BAMs are a way to scale an angle in the range 0 to 360 degrees to an integer.  You can always display an angle as a floating point like 24.8 degrees, but you do not store or transmit it as 24.8.

Robert

List of Articles on Software Maintenance and Maintainability

Here is a list of articles on Software Maintenance and Maintainability within this blog:

Software Maintenance and Variables  March 16, 2014
Software Maintenance and Message IDs  April 2, 2014
Unique Method Names for SW Maintainability  August 26, 2017
Avoid Bit Fields  October 1, 2017