background image

Advanced

Serial Protocol

Advanced

Serial Protocol

In order to communicate sensor data to a client (e.g., a RoboRio robot controller) the navX-sensor
software uses a custom protocol. This protocol defines messages sent between the navX-sensor and the
client over a serial interface, and includes an error detection capability to ensure corrupted data is not
used by the client.

The navX-sensor Serial protocol uses two message types, the legacy ASCII messages initially introduced
in the nav6 sensor, and the modern binary messages introduced in the navX-sensor.

Source code that implements the navX-sensor ASCII and binary protocols in 

Java

 and 

C++

 are provided

to simplify adding support for the navX-sensor protocol to a software project.

Message Structure

ASCII Protocol Messages

Each navX-sensor Serial ASCII protocol message has the following structure:

Start of Message

Message ID

Message Body

Message Termination

1 byte

1 byte

length is message-type
dependent

4 bytes

Binary Protocol Messages

Each navX-sensor Serial Binary protocol message has the following structure:

Start of Message Binary Message

Indicator

Binary Message
Length

Message ID

Message Body

Message
Termination

1 byte

1 byte

1 byte

1 byte

length is message-
type dependent

4 bytes

Data Type Encoding (ASCII)

Base16 encoding is used for ASCII message elements, as follows:

Data Type

Encoding

Example

Float

(Sign)(100s)(10s)(1s).(10ths)(100t
hs)

‘-132.96’. ‘ 257.38’

8-bit Integer

(HighNibble)(LowNibble)

‘E9’

16-bit Integer

(HighByte,HighNibble)(HighByte,
LowNibble)(LowByte,HighNibble

‘1A0F’

 80

Summary of Contents for navX2-MXP

Page 1: ...navX2 MXP Robotics Navigation Sensor User Guide Kauai Labs Creative Commons BY 2020...

Page 2: ...RIO Libraries 30 Android Library FTC 31 Linux Library 33 Arduino Library 33 navXUI 34 Tools 37 Examples 38 Examples 38 Field Oriented Drive FRC 38 Rotate to Angle FRC 42 Automatic Balancing FRC 45 Col...

Page 3: ...Serial Protocol 81 Register Protocol 86 Open source Hardware Software 90 Classic navX MXP Firmware Customization 90 navXUI Customization 95 Technical References 96...

Page 4: ...xpansion Generation 2 navX2 MXP is a drop in replacement for Classic navX2 MXP See the Frequently Asked Questions FAQ for more information about navX2 MXP improvements navX2 MXP is a must have add on...

Page 5: ...eading 9 Axis absolute heading w Magnetic disturbance detection Configurable Update Rate from 4 to 200Hz Easy to Use Plug n Play Installation via RoboRIO MXP Interface USB TTL UART I2C and SPI communi...

Page 6: ...Current Consumption 60 millamps Communications Interfaces USB TTL UART SPI I2C Power Connector USB and or 5VDC GND Pins on MXP Connector Power Source Fail over Automatic switch between USB MXP Power w...

Page 7: ...ng and Control has six chapters that focus on CAD modeling traditional machining CNC mills and lathes CNC cutting 3D printing and sensors control Each chapter profiles five FRC teams to illustrate how...

Page 8: ...16G accelerometer data As a result of these enhancements Startup time is reduced to only 5 seconds Pitch Roll accuracy is increased to 0 5 degrees Errors due to Extreme inertial events are minimized T...

Page 9: ...he RoboRIO Please see the instructions for installing navX2 MXP onto a FIRST FRC robot for more details as there are several installation options Will navX2 MXP work with the Android based FTC Control...

Page 10: ...w Drift page Can the navX2 MXP Displacement estimates be used for tracking a FRC or FTC robot s change in position dead reckoning during autonomous Accelerometer data from the navX MXP s onboard MPU 9...

Page 11: ...available at low cost will likely occur in the next decade but technology has not advanced to this point yet KauaiLabs plans to develop a product which can be used for accurate accelerometer based dea...

Page 12: ...2 MXP also provides analog and digital I O expansion on a RoboRIO Flexibility To allow flexible customization navX2 MXP also supports several alternative installation options as well as several commun...

Page 13: ...Installation RoboRIO Installation 10...

Page 14: ...oard in an area of the chassis that might be flexible as this could introduce vibration to the inertial sensors that does not represent the chassis inertial properties The navX2 MXP circuit board shou...

Page 15: ...pins to the corresponding pins on the navX2 MXP External I2C Port Connector NOTE The I2C to JST PH Cable linked to above has a different pin out on the 1 Molex black plastic header side than found on...

Page 16: ...X2 MXP Physical Installation on the Robot The navX2 MXP circuit board should be mounted such that it is firmly attached to the robot chassis The quality of this mounting will be directly reflected in...

Page 17: ...ordinate system In order to effectively use the values reported by navX2 MXP a few key concepts must be understood in order to correctly install navX2 MXP on a robot 3 D Coordinate System When control...

Page 18: ...Front Head of Field Robot Body Frame Side of Robot Front Head of Robot navX2 MXP Board Frame See diagram Below See diagram below Joysticks and Reference Frames Since a three axis joystick is typicall...

Page 19: ...directly up and down with respect to the earth When installing navX2 MXP on a robot the navX MXP yaw Z axis and the gravity axis must be aligned Default navX2 MXP Board Orientation The default navX2 M...

Page 20: ...Installation Orientation 17...

Page 21: ...e down In certain cases the navX2 MXP axes Board Frame may not be oriented exactly as that of the Robot Body Frame For instance if the navX2 MXP circuit board is plugged directly into the RoboRIO MXP...

Page 22: ...similar to how a modern smart phone will rotate the display based upon the phone s orientation However unlike a smart phone the OmniMount detection of orientation does not happen all the time since th...

Page 23: ...libration During this auto calibration period the orange CAL LED will flash repeatedly This process takes approximately 15 seconds and requires two things 1 During auto calibration one of the navX2 MX...

Page 24: ...Installation I O Expansion 21...

Page 25: ...and Signal The orientation of the Ground Power and Signal pins for each of the Digital I O Analog Input and Analog Output pins is as follows Digital I Os Each of the 10 Digital I O pins may be config...

Page 26: ...se Analog Inputs Each of the 4 Analog Input pins on the MXP connector has a corresponding 3 pin connector DC Voltage Ground and Signal On the RoboRIO these signals are routed to the internal Analog to...

Page 27: ...p switch is set to the ON position Thus the SPI Enable dip switch should be set to the OFF position if you wish to communicate with an external device via the SPI connector TTL UART The navX2 MXP TTL...

Page 28: ...ference so high quality shielded cabling and shorter distances may be called for These extension cables are available online at AndyMark Image not found One wire Connect via USB cable By using a USB M...

Page 29: ...a pull up resistor on each line The RoboRIO internally pulls these lines high The I2C pins are 5V tolerant so the host computer can use either 5V or 3 3V DC levels on these pins SPI To use the SPI int...

Page 30: ...TL format is available in the enclosure directory of the Those who prefer to purchase the enclosure can order it from Shapeways which takes approximately 2 weeks to deliver or at the Kauai Labs store...

Page 31: ...extension Finally these exported STL format files can be opened and 3d printed using netfabb Securing the Enclosure The Lid Enclosure can be secured to the RoboRIO by two 4 40 1 2 screws This will sec...

Page 32: ...so available Note For developers on Linux and Mac OS platforms the latest non Windows RoboRIO FRC Android FTC libraries build is also available Please note that this build does not contain any of the...

Page 33: ...g Started Before getting started ensure you have installed Android Studio and the indicated Android Studio Project components linked to on the FIRST Tech Challenge Programming Resources page Several s...

Page 34: ...es flatDir dirs libs C Users Robot navx mxp android libs Again in the same build release gradle file add the navx_ftc library to the list of libraries the ftc_app will link to by adding this line near...

Page 35: ...e navX sensor Linux Library is useful for integrating with video processors such as the Raspberry PI and the Jetson TK1 and TX1 To use the library you can checkout the source code with Git Online help...

Page 36: ...To use the library you can checkout the source code with Git Getting Started After checking out the source code with Git into a directory on your computer compile using the Arduino IDE The file navXT...

Page 37: ...see the Gyro Accelerometer Calibration page Motion Indicators The navX sensor provides dynamic motion indicators a the Moving indicator and b the Rotating indicator The Moving indicator is present wh...

Page 38: ...turbance is indicated Yaw Angle The Yaw Angle is displayed in grey text if Gyro Calibration has not yet been completed Once Gyro Calibration is complete the Yaw Angle text color will change to white P...

Page 39: ...e program which will install the navXUI as well as all necessary device drivers for communicating over USB with the navX sensor as well as some additional tools Start the navXUI From your Start Menu s...

Page 40: ...he setup program contained in the latest build Java C examples will be installed to subdirectories underneath navx mxp examples vscode e g C Users Robot navx mxp cpp examples vscode These examples are...

Page 41: ...lar transformation mentally This skill can take quite awhile to develop meaning that rookie drivers face an uphill climb before they can be productive team contributors Additionally the mental energy...

Page 42: ...lent post on Chief Delphi by Ether which provides a wealth of helpful well written information on implementing field centric drive on various types of drive systems FRC C Example Full C source code on...

Page 43: ...eading to the Holonomic Drive VI which rotates the joystick X Y coordinates by the gyro angle and thus implements FieldCentric drive control Additionally if a driver joystick button is pressed the nav...

Page 44: ...te to preset angle button is pressed This rotation can occur not only when the robot is still but also when the robot is driving When using field oriented control this will cause the robot to drive in...

Page 45: ...abView Example The navX sensor Rotate to Angle LabView example shows how to make small modifications to the LabView FRC RoboRIO Robot Project using the Mecanum Robot configuration to rotate the robot...

Page 46: ...dinates by the gyro angle and thus implements FieldCentric drive control Additionally if a driver joystick button is pressed the navX sensor Yaw angle is reset to zero This example also includes a Rot...

Page 47: ...he X axis and Roll rotation about the Y axis angles When these angles exceed the off balance threshold and until these angles fall below the on balance threshold the drive system is automatically driv...

Page 48: ...how to make small modifications to the LabView FRC RoboRIO Robot Project using the Mecanum Robot configuration to implement high accuracy Automatic Balancing RobotMain vi Place the NavX main vi on th...

Page 49: ...FieldCentric drive control Additionally if a driver joystick button is pressed the navX sensor Yaw angle is reset to zero Finally the navX sensor Pitch X axis and Roll Y axis angles are continuously...

Page 50: ...es during an accident A similar technique can be used on a robot to detect when it has collided with another object The principle used within the Collision Detection example is the calculation of Jerk...

Page 51: ...l be dependent upon the robot mass and expected maximum velocity of either the robot or any object which may strike the robot FRC C Example Full C Source Code FRC Java Example Full Java Source Code FR...

Page 52: ...y need to process faster for your situation For the SPI I2C and USB connections the max sample rate is 200Hz Teleop vi The Teleop vi is modified to feed the Linear Acceleration to a threshold detector...

Page 53: ...ecting motion with raw acceleration data is to use a high pass filter which lets quickly changing information through but blocks information that doesn t change frequently However a more comprehensive...

Page 54: ...small modifications to the LabView FRC RoboRIO Robot Project using the Mecanum Robot configuration to detect when your robot is moving RobotMain vi Place the NavX main vi on the block diagram and set...

Page 55: ...Data Monitor example code demonstrates how to perform navX MXP initialization and display all sensor values on a FIRST FRC robotics dashboard The output data values include Yaw Pitch and Roll angles...

Page 56: ...C source code on GitHub FRC Java Example Full Java Source code on GitHub FRC LabVIEW Example The navX sensor Test_Window vi example shows all of the outputs from the navX sensor through FRC RoboRIO R...

Page 57: ...Data Monitor FRC Test Window vi Place the Test Window vi inside of a loop in any VI for instance in your Teleop vi loop and the values will automatically update Test Window vi is in the navX AE Get f...

Page 58: ...g Motor Control Digital Inputs e g Contact Switch closure Digital Outputs e g Relay control Quadrature Encoders e g Wheel Encoder ANALOG I O Analog Inputs e g Ultrasonic Sensor Analog Input Trigger e...

Page 59: ...View example shows how to make small modifications to the LabView FRC RoboRIO Robot Project using the Mecanum Robot configuration to access MXP Expansion IO Capabilities RobotMain vi The RobotMain vi...

Page 60: ...onto the navX MXP Expansion IO Pins GetChannelFromNavX MXPPin vi The GetChannelFromNavX MXPPin vi performs the translation from the navX2 MXP navX MXP Digital or Analog Pin number to the correspondin...

Page 61: ...ck inputs and programs the output pins accordingly PWM to motor controllers Digital Outputs and Analog Outputs As well values from the input pins Digital Inputs Encoders and Analog Inputs is retrieved...

Page 62: ...or restarts is very important if your robot software uses the yaw angle To avoid a navX sensor restart when stage 2 brownouts occur a secondary power supply for the navX sensor circuit board should be...

Page 63: ...y electronic component can fail or become disconnected accidentally To ensure that your robot can still function during a FRC match even if such a failure does occur your robot software should handle...

Page 64: ...ot mounted horizontally By default the navX sensor s motion processing requires the unit be mounted horizontally parallel to the earth s surface the yaw Z axis should be perpendicular to the earths su...

Page 65: ...navX sensor Pitch and Roll angles are referenced to earth s gravity so when a navX sensor is flat Pitch and Roll angles should be very close to 0 The Yaw angle is different Yaw is not referenced to a...

Page 66: ...orth and thus Compass Heading does not drift over time Important Note 1 Compass Heading relies upon being able to measure the earth s magnetic field Since the earth s magnetic field is weak Compass He...

Page 67: ...used to uniquely determine the position of a point within a space measured by that system The origin of a 3 D coordinate system has a value of 0 0 0 navX sensors feature gyroscopes accelerometers and...

Page 68: ...otation similarly Fused Heading Given the gravity referenced orientation provided by the Yaw angle as well as the absolute compass heading angle which has been aligned to the navX sensor 3 D coordinat...

Page 69: ...lacement estimation can be several feet per second As MEMS sensors improve in the coming years and accelerometer noise is reduced this technique will become more useful for robotics navigation If you...

Page 70: ...ns internally and also provide the 4 quaternion values for use by those who might need them Selecting an Interface The navX2 MXP navX MXP sensors provide several methods for communicating with robotic...

Page 71: ...away from motors This configuration is also useful when accessing navX sensor data from a separate processor such as a PC or a separate video processor However please note that in certain cases when...

Page 72: ...Guidance Gyro Accelerometer Calibration The navX sensor Calibration Process is comprised of three calibration phases Factory Calibration Startup Calibration On the fly Calibration 69...

Page 73: ...ation Factory Calibration Before navX sensors are shipped the accelerometers and gyroscopes are initially calibrated at the factory this calibration data is stored in flash memory and applied automati...

Page 74: ...that yaw accuracy will be diminished until the next On the fly Gyro Calibration completes Second Generation navX sensor Factory Calibration Time if still 2 seconds Classic navX sensor Factory Calibrat...

Page 75: ...on So once again it s important to keep the sensor still during Startup Calibration Runtime Yaw Zeroing Your robot software can optionally provide the robot operator a way to reset the yaw angle to Ze...

Page 76: ...etometer Calibration tool This tool is designed to run on a Windows computer and communicate to the navX sensor circuit board via a USB cable Yaw Drift A gyroscope measures the amount of angular rotat...

Page 77: ...e the accelerometer values in this axis are the same no matter how much yaw rotation exists To deal with this several different data fusion algorithms have been developed including Complementary filte...

Page 78: ...long practice matches the drift may become noticeable and can be dealt with using the following approaches 1 The simplest approach which is supported by the navX sensor libraries is to periodically r...

Page 79: ...motors are energized If the sensor is placed far enough away from motors it may be possible to also get an undisturbed magnetometer during a match Finally note that the resulting angle is only as accu...

Page 80: ...Please visit navX Sensor Support to access the firmware archive Factory Test Procedure The Factory Test Procedure verifies correct operation of the circuit board and it s key components Please visit...

Page 81: ...va Added VSCode specific software examples 2019 FRC Season Release Version Number 3 1 339 Change Summary Firmware Changed default serial protocol to the most commonly used protocol reducing startup ti...

Page 82: ...g 2016 FRC Season Release Version Number 3 0 263 The cross platform build is also available for non Windows platforms Change Summary Firmware Added new Omnimount capabilities Firmware Added new onboar...

Page 83: ...adding support for the navX sensor protocol to a software project Message Structure ASCII Protocol Messages Each navX sensor Serial ASCII protocol message has the following structure Start of Message...

Page 84: ...ed Hundredths original value 100 rounded to nearest integer Signed Hundredths original value 100 rounded to nearest integer Signed Thousandths original value 1000 rounded to nearest integer Signed Pi...

Page 85: ...feed character Checksum The checksum is calculated by adding each byte of the message except the bytes within the Message Termination itself The checksum is accumulated within an 8 bit unsigned byte N...

Page 86: ...Integer 4 Gyro Y 15 bits signed 16 bit Integer 8 Gyro Z 15 bits signed 16 bit Integer 12 Acceleration X 16 bits signed 16 bit Integer 16 Acceleration Y 16 bits signed 16 bit Integer 20 Acceleration Z...

Page 87: ...he Stream Configuration Command is sent in order to change the type of navX sensor Streaming Update transmitted to the client Byte Offset Element Data Type 0 Stream Type 8 bit ASCII Character 1 Update...

Page 88: ...r based protocol This page documents the register based protocol used on both the I2C and SPI bus Register based protocol overview Unlike the streaming Serial protocol which periodically sends out upd...

Page 89: ...ead from the navX sensor The I2C bus master next sends the starting register address it intends to write to or read from The I2C bus master next initiates I2C bus transactions The navX sensor supports...

Page 90: ...registers it wishes to read from This count must be at least 1 and must be not exceed the maximum register address less the requested register address If the SPI bus master is writing it transmits the...

Page 91: ...code to calculate the CRC value please see Line 445 of the IMURegisters h source code navX sensor Register Data Types All multi byte registers are in little endian format All registers with signed da...

Page 92: ...e Hardware Software Classic navX MXP The navX MXP project is completely open source including schematics firmware and design files for an enclosure These sources are available online at the navX MXP G...

Page 93: ...or 64 bit Windows it is installed into C Program Files x86 CodeSourcery Sourcery G Lite Add the path to the bin director underneath the Code Sourcery G Lite installation directory so that the compiler...

Page 94: ...e unfamiliar with installingn Eclipse plugins please visit this URL for more information on the process https wiki eclipse org FAQ_How_do_I_install_new_plug ins 3F Zylin Plugin Update URL http opensou...

Page 95: ...digikey com among others for approximately 40 Additional utilities for the ST LINK V2 for windows are available on the STM website Connecting the ST LINK V2 to the navX MXP Circuit Board You will nee...

Page 96: ...nformation on how to proceed Configure Eclipse to run OpenOCD Run External Tools External Tools Configuration Add a new configuration name it OpenOCD In the main tab under Location provide the path to...

Page 97: ...0 script file to reference your particular directory path to the navx mxp distribution directory you unpacked the navx mxp distribution zip into Once the debug configuration is created and the open oc...

Page 98: ...play Technical References The references on this page are provided to help students gain a deeper understanding of the algorithms technologies and tools used within the navX sensor and other Inertial...

Reviews: