Skip to content

Sparton AHRS

David Walker-Howell edited this page Dec 20, 2018 · 4 revisions

Sparton AHRS Reference: Sparton AHRS Driver Program - AHRS.py

The Sparton GEDC-6 Attitude Heading Reference Systems(AHRS) provides heading, pitch, and roll data with reliable performance. It contains on-board "adaptive" algorithms to ensure accurate results from the 3-axis magnetometer, accelerometer, and gyroscope. This device communicates over simple 2-wire serial (UART).

Class SpartonAHRSDataPackets

This class implements the getters and setters commands for the Sparton AHRS. It handles the sending values to configure the device and request data specified. data.

AHRS.SpartonAHRSDataPackets(com_port)

Example Usage:

sparton_ahrs = SpartonAHRSDataPackets('COM7')

while(1):
    sparton_ahrs.get_raw_magnetics() #request raw magnetic data
    
    #using serial, read the 9 byte data packet sent by the ahrs

__init__(self, com_port)

Initializes connection with the AHRS device at a baud rate of 115200.
        Sets up the array of location values.

        Parameters:
            com_port: A string value of the serial COM port that the AHRS
                            device is connected to.
        Returns:
            N/A

get_raw_magnetics(self)

Send request to get the raw magnetics from the magnetometers (Mx, My,
        and Mz). These are raw sensor readings and do not yet have any
        calibration. Note that this function is really only used for test purposes.
        NOT PRACTICAL FOR OFFICIAL USE.

        Reference: Software-Interface-Manual page 38

         Send: 3 Byte (0xA4,0x01,0xA0)

        Response: 9 Bytes (0xA4,0x01,<Mx>,<My>,<Mz as 16-bit integers MS
         byte first>,0xA0)

         Parameters:
            N/A
        Returns:
            raw_magnetics: 6-byte list of raw magnetics.      

get_true_heading(self)

Send request to get the true heading. True heading is the magnetic
        heading.

        Reference: Software-Interface-Manual page 38.

        Send: 3 Bytes (0xA4, 0x02, 0xA0)

        Responds: 5 Bytes <0xA4, 0x02, <Heading as a 16-bit signed integer>,
                            0xA0)
        Heading (degrees) = 16-bit Heading value * (360/4096)
        Heading Range = 0.0 to + 359.9

        Returns:
            true_heading: The true heading in degrees from 0.0 to 359.9. If the
                            data could not be received, return an empty list.

get_pitch_roll(self)

        Send request and receive data to get the pitch and roll of the platform.

        Reference: Sofware-Inference-Manual page 42.

        Send: 3 Bytes (0xA4, 0x06, 0xA0)

        Response: 7 Bytes (0xA4, 0x06, Pitch, Roll as 16-bit signed integers, 0xA0)

        Pitch(in degrees) = (Response) * 90/4096
        Pitch Range: -90 to +90

        Roll (in degrees) = (Response) * 180/4096
        Acceleration Vector Roll Range = -180 to 180

        Returns:
            pitch_roll: A list containing the pitch and roll

_unpack(self, data_type)

        Read in the transmission from AHRS and extract all the bytes of the
        packet.

        Parameters:
            datatype: The type of data being read. Note: This should be one of
                    the keys in the locationArray(see constructor)
        Returns:
            ahrs_data_in: The raw data packet of the given data type. If there is
                        an error reading the data, return None. If there are no
                        datapacket to be read, return an empty list of data.

Class AHRS

Communicate with the AHRS module and receive the necessary data need for autonomy. Publish data to sensor hub to be routed to the mission planner and movement control.

AHRS.AHRS(com_port)

Example Usage:

ahrs = AHRS.AHRS("COM7")
ahrs.run() #runs a continuous while loop

__init__(self, com_port)

Initialize communcication path with the Sparton AHRS and MechOS node publisher to transmit data throughout system.

        Parameters:
            com_port: The serial communication port communicating with the AHRS
                        board.

receive_sensor_data(self)


        Receive the AHRS roll, pitch, and yaw data from the sparton ahrs module.

        Parameters:
            N/A

        Returns:
            [yaw, pitch, roll]: List of roll, pitch, yaw data. This is only returned
                    if the data is received properly.

            False: If data is not received properly, return false

run(self)


        Continually request data from the AHRS merger board and publish it to
        MechOS network over topic "AHRS_DATA".

        Parameters:
            N/A

        Returns:
            N/A