1
+ /*
2
+ By: Nathan Seidle
3
+ SparkFun Electronics
4
+ Date: August, 2021
5
+ License: MIT. See license file for more information but you can
6
+ basically do whatever you want with this code.
7
+
8
+ This example configures the AutoAlignment option for the IMU.
9
+ The ZED-F9R Integration guide recommends enabling Auto Alignment once
10
+ the device has been attached to the vehicle's frame.
11
+ Enabling auto-alignment will cause the the sensor fusion status
12
+ to begin initialization. After driving around a few turns, the sensors
13
+ should enter 'Calibrated' state. See example 1 for fusion state or
14
+ monitor UBX-ESF-STATUS.
15
+
16
+ As of writing the ZED-F9R is using HPS v1.2 firmware. Please update using u-center if necessary.
17
+
18
+ Feel like supporting open source hardware?
19
+ Buy a board from SparkFun!
20
+ ZED-F9R: https://www.sparkfun.com/products/16344
21
+ ZED-F9R pHat: https://www.sparkfun.com/products/16475
22
+ NEO-M8U: https://www.sparkfun.com/products/16329
23
+
24
+ Hardware Connections:
25
+ Plug a Qwiic cable into the GPS and a Redboard Qwiic
26
+ If you don't have a platform with a Qwiic connection use the
27
+ SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/17912)
28
+ Open the serial monitor at 115200 baud to see the output
29
+
30
+ */
31
+
32
+ #include < Wire.h> // Needed for I2C to GPS
33
+
34
+ #include < SparkFun_u-blox_GNSS_Arduino_Library.h> // http://librarymanager/All#SparkFun_u-blox_GNSS
35
+ SFE_UBLOX_GNSS myGNSS;
36
+
37
+ void setup ()
38
+ {
39
+ Serial.begin (115200 );
40
+ while (!Serial); // Wait for user to open terminal
41
+ Serial.println (F (" SparkFun u-blox Example" ));
42
+
43
+ Wire.begin ();
44
+
45
+ // myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial
46
+
47
+ if (myGNSS.begin () == false ) // Connect to the u-blox module using Wire port
48
+ {
49
+ Serial.println (F (" Warning! u-blox GPS did not begin correctly." ));
50
+ Serial.println (F (" (This may be because the I2C port is busy with HNR messages.)" ));
51
+ }
52
+
53
+ bool esfAutoAlignment = myGNSS.getESFAutoAlignment ();
54
+ Serial.print (F (" esfAutoAlignment: " ));
55
+ if (esfAutoAlignment == true )
56
+ Serial.println (F (" True" ));
57
+ else
58
+ Serial.println (F (" False" ));
59
+
60
+ myGNSS.setESFAutoAlignment (true ); // Enable UBX-CFG-ESFALG Automatic IMU-mount Alignment
61
+
62
+ myGNSS.setAutoHNRATT (false ); // Make sure auto HNR attitude messages are disabled
63
+ myGNSS.setAutoHNRINS (false ); // Make sure auto HNR vehicle dynamics messages are disabled
64
+ myGNSS.setAutoHNRPVT (false ); // Make sure auto HNR PVT messages are disabled
65
+
66
+ myGNSS.setI2COutput (COM_TYPE_UBX); // Set the I2C port to output UBX only (turn off NMEA noise)
67
+ myGNSS.saveConfigSelective (VAL_CFG_SUBSEC_IOPORT); // Save (only) the communications port settings to flash and BBR
68
+ }
69
+
70
+ void loop ()
71
+ {
72
+ // ESF data is produced at the navigation rate, so by default we'll get fresh data once per second
73
+ if (myGNSS.getEsfInfo ()) // Poll new ESF STATUS data
74
+ {
75
+ Serial.print (F (" Fusion Mode: " ));
76
+ Serial.print (myGNSS.packetUBXESFSTATUS ->data .fusionMode );
77
+ if (myGNSS.packetUBXESFSTATUS ->data .fusionMode == 0 )
78
+ Serial.println (F (" Sensor is initializing..." ));
79
+ else if (myGNSS.packetUBXESFSTATUS ->data .fusionMode == 1 )
80
+ Serial.println (F (" Sensor is calibrated!" ));
81
+ else if (myGNSS.packetUBXESFSTATUS ->data .fusionMode == 2 )
82
+ Serial.println (F (" Sensor fusion is suspended!" ));
83
+ else if (myGNSS.packetUBXESFSTATUS ->data .fusionMode == 3 )
84
+ Serial.println (F (" Sensor fusion is disabled!" ));
85
+ }
86
+
87
+ // Poll and print selected HNR data
88
+ if (myGNSS.getHNRAtt (125 ) == true ) // Request HNR Att data using a 125ms timeout
89
+ {
90
+ Serial.print (F (" Roll: " ));
91
+ Serial.print (myGNSS.getHNRroll (), 2 ); // Use the helper function to get the roll in degrees
92
+ Serial.print (F (" Pitch: " ));
93
+ Serial.print (myGNSS.getHNRpitch (), 2 ); // Use the helper function to get the pitch in degrees
94
+ Serial.print (F (" Heading: " ));
95
+ Serial.println (myGNSS.getHNRheading (), 2 ); // Use the helper function to get the heading in degrees
96
+ }
97
+ if (myGNSS.getHNRDyn (125 ) == true ) // Request HNR Dyn data using a 125ms timeout
98
+ {
99
+ Serial.print (F (" xAccel: " ));
100
+ Serial.print (myGNSS.packetUBXHNRINS ->data .xAccel );
101
+ Serial.print (F (" yAccel: " ));
102
+ Serial.print (myGNSS.packetUBXHNRINS ->data .yAccel );
103
+ Serial.print (F (" zAccel: " ));
104
+ Serial.println (myGNSS.packetUBXHNRINS ->data .zAccel );
105
+ }
106
+ if (myGNSS.getHNRPVT (125 ) == true ) // Request HNR PVT data using a 125ms timeout
107
+ {
108
+ Serial.print (F (" ns: " ));
109
+ Serial.print (myGNSS.packetUBXHNRPVT ->data .nano );
110
+ Serial.print (F (" Lat: " ));
111
+ Serial.print (myGNSS.packetUBXHNRPVT ->data .lat );
112
+ Serial.print (F (" Lon: " ));
113
+ Serial.println (myGNSS.packetUBXHNRPVT ->data .lon );
114
+ }
115
+
116
+ }
0 commit comments