|
| 1 | +/* |
| 2 | + Display the relative position of a NEO-M8P-2 rover |
| 3 | + By: Paul Clark |
| 4 | + SparkFun Electronics |
| 5 | + Date: March 20th, 2023 |
| 6 | + License: MIT. See license file for more information. |
| 7 | +
|
| 8 | + This example shows how to query the module for RELPOS information in the NED frame. |
| 9 | + It assumes you already have RTCM correction data being fed to the receiver on UART1. |
| 10 | + Connect UART1 TX on the base to UART1 RX on the rover. Also connect GND to GND. |
| 11 | +
|
| 12 | + Feel like supporting open source hardware? |
| 13 | + Buy a board from SparkFun! |
| 14 | + NEO-M8P RTK: https://www.sparkfun.com/products/15005 |
| 15 | +
|
| 16 | + Hardware Connections: |
| 17 | + Plug a Qwiic cable into the GNSS and a RedBoard Qwiic or BlackBoard |
| 18 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 19 | + Connect UART1 TX on the base to UART1 RX on the rover. Also connect GND to GND. |
| 20 | + Open the serial monitor at 115200 baud to see the output |
| 21 | +*/ |
| 22 | + |
| 23 | +#include <Wire.h> //Needed for I2C to GNSS |
| 24 | + |
| 25 | +#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS |
| 26 | +SFE_UBLOX_GNSS myGNSS; |
| 27 | + |
| 28 | +void setup() |
| 29 | +{ |
| 30 | + delay(1000); |
| 31 | + |
| 32 | + Serial.begin(115200); |
| 33 | + while (!Serial); //Wait for user to open terminal |
| 34 | + Serial.println("u-blox NEO-M8P Rover Example"); |
| 35 | + |
| 36 | + Wire.begin(); |
| 37 | + |
| 38 | + while (myGNSS.begin() == false) //Connect to the u-blox module using Wire port |
| 39 | + { |
| 40 | + Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring.")); |
| 41 | + } |
| 42 | + |
| 43 | + // Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate |
| 44 | + //myGNSS.factoryDefault(); delay(5000); |
| 45 | + |
| 46 | + // By default, UART1 Protocol In is set to NMEA + UBX + RTCM3. No changes are necessary. But we can manually configure the port if required. |
| 47 | + Serial.print(myGNSS.setPortInput(COM_PORT_UART1, COM_TYPE_UBX | COM_TYPE_RTCM3)); //Enable UBX and RTCM3 input on UART1 |
| 48 | + myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save the communications port settings to flash and BBR |
| 49 | +} |
| 50 | + |
| 51 | +void loop() |
| 52 | +{ |
| 53 | + // The data from getRELPOSNED (UBX-NAV-RELPOSNED) is returned in UBX_NAV_RELPOSNED_t packetUBXNAVRELPOSNED |
| 54 | + // Please see u-blox_structs.h for the full definition of UBX_NAV_RELPOSNED_t |
| 55 | + // You can either read the data from packetUBXNAVRELPOSNED directly |
| 56 | + // or can use the helper functions: getRelPosN/E/D; getRelPosAccN/E/D |
| 57 | + // Note that NEO-M8P RELPOSNED is different to ZED-F9P. It does not contain the relative length and heading. |
| 58 | + if (myGNSS.getRELPOSNED() == true) |
| 59 | + { |
| 60 | + Serial.print("relPosN: "); |
| 61 | + Serial.println(myGNSS.getRelPosN(), 4); // Use the helper functions to get the rel. pos. as m |
| 62 | + Serial.print("relPosE: "); |
| 63 | + Serial.println(myGNSS.getRelPosE(), 4); |
| 64 | + Serial.print("relPosD: "); |
| 65 | + Serial.println(myGNSS.getRelPosD(), 4); |
| 66 | + |
| 67 | + Serial.print("relPosHPN: "); |
| 68 | + Serial.println((float)myGNSS.packetUBXNAVRELPOSNED->data.relPosHPN / 10, 1); //High-precision component. Convert to mm |
| 69 | + Serial.print("relPosHPE: "); |
| 70 | + Serial.println((float)myGNSS.packetUBXNAVRELPOSNED->data.relPosHPE / 10, 1); |
| 71 | + Serial.print("relPosHPD: "); |
| 72 | + Serial.println((float)myGNSS.packetUBXNAVRELPOSNED->data.relPosHPD / 10, 1); |
| 73 | + |
| 74 | + Serial.print("accN: "); |
| 75 | + Serial.println(myGNSS.getRelPosAccN(), 4); // Use the helper functions to get the rel. pos. accuracy as m |
| 76 | + Serial.print("accE: "); |
| 77 | + Serial.println(myGNSS.getRelPosAccE(), 4); |
| 78 | + Serial.print("accD: "); |
| 79 | + Serial.println(myGNSS.getRelPosAccD(), 4); |
| 80 | + |
| 81 | + Serial.print("gnssFixOk: "); |
| 82 | + if (myGNSS.packetUBXNAVRELPOSNED->data.flags.bits.gnssFixOK == true) |
| 83 | + Serial.println("x"); |
| 84 | + else |
| 85 | + Serial.println(""); |
| 86 | + |
| 87 | + Serial.print("diffSolution: "); |
| 88 | + if (myGNSS.packetUBXNAVRELPOSNED->data.flags.bits.diffSoln == true) |
| 89 | + Serial.println("x"); |
| 90 | + else |
| 91 | + Serial.println(""); |
| 92 | + |
| 93 | + Serial.print("relPosValid: "); |
| 94 | + if (myGNSS.packetUBXNAVRELPOSNED->data.flags.bits.relPosValid == true) |
| 95 | + Serial.println("x"); |
| 96 | + else |
| 97 | + Serial.println(""); |
| 98 | + |
| 99 | + Serial.print("carrier Solution Type: "); |
| 100 | + if (myGNSS.packetUBXNAVRELPOSNED->data.flags.bits.carrSoln == 0) |
| 101 | + Serial.println("None"); |
| 102 | + else if (myGNSS.packetUBXNAVRELPOSNED->data.flags.bits.carrSoln == 1) |
| 103 | + Serial.println("Float"); |
| 104 | + else if (myGNSS.packetUBXNAVRELPOSNED->data.flags.bits.carrSoln == 2) |
| 105 | + Serial.println("Fixed"); |
| 106 | + |
| 107 | + Serial.print("isMoving: "); |
| 108 | + if (myGNSS.packetUBXNAVRELPOSNED->data.flags.bits.isMoving == true) |
| 109 | + Serial.println("x"); |
| 110 | + else |
| 111 | + Serial.println(""); |
| 112 | + } |
| 113 | + else |
| 114 | + Serial.println("RELPOS request failed"); |
| 115 | + |
| 116 | + Serial.println(""); |
| 117 | +} |
0 commit comments