Skip to content

Commit a7097c8

Browse files
authoredSep 9, 2022
Merge pull request #152 from sparkfun/release_candidate
v2.2.14
2 parents 20e265d + e3d27ae commit a7097c8

File tree

9 files changed

+1177
-124
lines changed

9 files changed

+1177
-124
lines changed
 

‎Utils/UBX_RAWX_Aligner.py

+515
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/*
2+
Callback Example: ESF RAW (100Hz!)
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: September 8th, 2022
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example configures the External Sensor Fusion RAW IMU sensor messages on the NEO-M8U / ZED-F9R and
10+
uses callbacks to process and display the ESF data automatically.
11+
12+
Notes:
13+
On the ZED-F9R, each ESF RAW message contains _one_ set of IMU sensor data: seven readings in total (3 x Accel, 3 x Gyro, 1 x Temperature).
14+
However, on the NEO-M8U, each message contains _ten_ sets of IMU sensor data, seventy readings in total.
15+
The NEO-M8U data is all timestamped and it is possible to reconstruct the full data stream, you just need to do it
16+
ten samples at a time...
17+
Also, note that the sensor data is 24-bit signed (two's complement). You need to be careful when converting to int32_t.
18+
Data will arrive at 100Hz! (10Hz x 10 on the NEO-M8U)
19+
400kHz I2C is essential...
20+
Serial printing needs to be kept short and the baud rate needs to be at least 230400.
21+
22+
Please make sure your NEO-M8U is running UDR firmware >= 1.31. Please update using u-center if necessary:
23+
https://www.u-blox.com/en/product/neo-m8u-module#tab-documentation-resources
24+
25+
Feel like supporting open source hardware?
26+
Buy a board from SparkFun!
27+
NEO-M8U: https://www.sparkfun.com/products/16329
28+
29+
Hardware Connections:
30+
Plug a Qwiic cable into the GPS and a Redboard Qwiic
31+
If you don't have a platform with a Qwiic connection use the
32+
SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
33+
Open the serial monitor at 115200 baud to see the output
34+
35+
*/
36+
37+
#include <Wire.h> //Needed for I2C to GPS
38+
39+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
40+
SFE_UBLOX_GNSS myGNSS;
41+
42+
// Callback: printESFRAWdata will be called when new ESF RAW data arrives
43+
// See u-blox_structs.h for the full definition of UBX_ESF_RAW_data_t
44+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoESFRAWcallback
45+
// / _____ This _must_ be UBX_ESF_RAW_data_t
46+
// | / _____ You can use any name you like for the struct
47+
// | | /
48+
// | | |
49+
void printESFRAWdata(UBX_ESF_RAW_data_t *ubxDataStruct)
50+
{
51+
// ubxDataStruct->numEsfRawBlocks indicates how many sensor readings the UBX_ESF_RAW_data_t contains.
52+
// On the ZED-F9R, numEsfRawBlocks will be 7: 3 x Accel, 3 x Gyro, 1 x Temperature.
53+
// On the NEO-M8U, numEsfRawBlocks will be 70: 10 sets of sensor data. The sensor time tag (sTag)
54+
// indicates the timing of each sample.
55+
// Serial output will be approx. 110 bytes depending on how many digits are in the sensor readings.
56+
// To keep up, Serial needs to be running at 100k baud minimum. 230400 is recommended.
57+
58+
uint32_t sTag = 0xFFFFFFFF; // Sensor time tag
59+
60+
// Only print the first seven sensor readings (on the NEO-M8U)
61+
for (uint8_t i = 0; (i < ubxDataStruct->numEsfRawBlocks) && (i < 7); i++)
62+
// For fun, and to prove it works, uncomment use this line instead to get the full 100Hz data on the NEO-M8U
63+
//for (uint8_t i = 0; i < ubxDataStruct->numEsfRawBlocks; i++)
64+
{
65+
// Print sTag the first time - and also if it changes
66+
if (sTag != ubxDataStruct->data[i].sTag)
67+
{
68+
sTag = ubxDataStruct->data[i].sTag;
69+
Serial.print(F("Time:"));
70+
Serial.println(sTag);
71+
}
72+
73+
// Print the sensor data type
74+
// From the M8 interface description:
75+
// 0: None
76+
// 1-4: Reserved
77+
// 5: z-axis gyroscope angular rate deg/s * 2^-12 signed
78+
// 6: front-left wheel ticks: Bits 0-22: unsigned tick value. Bit 23: direction indicator (0=forward, 1=backward)
79+
// 7: front-right wheel ticks: Bits 0-22: unsigned tick value. Bit 23: direction indicator (0=forward, 1=backward)
80+
// 8: rear-left wheel ticks: Bits 0-22: unsigned tick value. Bit 23: direction indicator (0=forward, 1=backward)
81+
// 9: rear-right wheel ticks: Bits 0-22: unsigned tick value. Bit 23: direction indicator (0=forward, 1=backward)
82+
// 10: speed ticks: Bits 0-22: unsigned tick value. Bit 23: direction indicator (0=forward, 1=backward)
83+
// 11: speed m/s * 1e-3 signed
84+
// 12: gyroscope temperature deg Celsius * 1e-2 signed
85+
// 13: y-axis gyroscope angular rate deg/s * 2^-12 signed
86+
// 14: x-axis gyroscope angular rate deg/s * 2^-12 signed
87+
// 16: x-axis accelerometer specific force m/s^2 * 2^-10 signed
88+
// 17: y-axis accelerometer specific force m/s^2 * 2^-10 signed
89+
// 18: z-axis accelerometer specific force m/s^2 * 2^-10 signed
90+
switch (ubxDataStruct->data[i].data.bits.dataType)
91+
{
92+
case 5:
93+
Serial.print(F("Zgyr:"));
94+
break;
95+
case 12:
96+
Serial.print(F("Temp:"));
97+
break;
98+
case 13:
99+
Serial.print(F("Ygyr:"));
100+
break;
101+
case 14:
102+
Serial.print(F("Xgyr:"));
103+
break;
104+
case 16:
105+
Serial.print(F("Xacc:"));
106+
break;
107+
case 17:
108+
Serial.print(F("Yacc:"));
109+
break;
110+
case 18:
111+
Serial.print(F("Zacc:"));
112+
break;
113+
default:
114+
break;
115+
}
116+
117+
// Gyro data
118+
if ((ubxDataStruct->data[i].data.bits.dataType == 5) || (ubxDataStruct->data[i].data.bits.dataType == 13) || (ubxDataStruct->data[i].data.bits.dataType == 14))
119+
{
120+
union
121+
{
122+
int32_t signed32;
123+
uint32_t unsigned32;
124+
} signedUnsigned; // Avoid any ambiguity casting uint32_t to int32_t
125+
// The dataField is 24-bit signed, stored in the 24 LSBs of a uint32_t
126+
signedUnsigned.unsigned32 = ubxDataStruct->data[i].data.bits.dataField << 8; // Shift left by 8 bits to correctly align the data
127+
float rate = signedUnsigned.signed32; // Extract the signed data. Convert to float
128+
rate /= 256.0; // Divide by 256 to undo the shift
129+
rate *= 0.000244140625; // Convert from deg/s * 2^-12 to deg/s
130+
Serial.println(rate);
131+
}
132+
// Accelerometer data
133+
else if ((ubxDataStruct->data[i].data.bits.dataType == 16) || (ubxDataStruct->data[i].data.bits.dataType == 17) || (ubxDataStruct->data[i].data.bits.dataType == 18))
134+
{
135+
union
136+
{
137+
int32_t signed32;
138+
uint32_t unsigned32;
139+
} signedUnsigned; // Avoid any ambiguity casting uint32_t to int32_t
140+
// The dataField is 24-bit signed, stored in the 24 LSBs of a uint32_t
141+
signedUnsigned.unsigned32 = ubxDataStruct->data[i].data.bits.dataField << 8; // Shift left by 8 bits to correctly align the data
142+
float force = signedUnsigned.signed32; // Extract the signed data. Convert to float
143+
force /= 256.0; // Divide by 256 to undo the shift
144+
force *= 0.0009765625; // Convert from m/s^2 * 2^-10 to m/s^2
145+
Serial.println(force);
146+
}
147+
// Gyro Temperature
148+
else if (ubxDataStruct->data[i].data.bits.dataType == 12)
149+
{
150+
union
151+
{
152+
int32_t signed32;
153+
uint32_t unsigned32;
154+
} signedUnsigned; // Avoid any ambiguity casting uint32_t to int32_t
155+
// The dataField is 24-bit signed, stored in the 24 LSBs of a uint32_t
156+
signedUnsigned.unsigned32 = ubxDataStruct->data[i].data.bits.dataField << 8; // Shift left by 8 bits to correctly align the data
157+
float temperature = signedUnsigned.signed32; // Extract the signed data. Convert to float
158+
temperature /= 256.0; // Divide by 256 to undo the shift
159+
temperature *= 0.01; // Convert from C * 1e-2 to C
160+
Serial.println(temperature);
161+
}
162+
}
163+
}
164+
165+
void setup()
166+
{
167+
Serial.begin(230400); // <--- Use >> 100k baud (see notes above)
168+
169+
while (!Serial); //Wait for user to open terminal
170+
Serial.println(F("SparkFun u-blox Example"));
171+
172+
Wire.begin();
173+
Wire.setClock(400000); // <-- Use 400kHz I2C (ESSENTIAL)
174+
175+
//myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial
176+
177+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
178+
{
179+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
180+
while (1);
181+
}
182+
183+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
184+
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
185+
186+
myGNSS.setI2CpollingWait(5); //Allow checkUblox to poll I2C data every 5ms to keep up with the ESF RAW messages
187+
188+
if (myGNSS.setAutoESFRAWcallbackPtr(&printESFRAWdata) == true) // Enable automatic ESF RAW messages with callback to printESFRAWdata
189+
Serial.println(F("setAutoESFRAWcallback successful"));
190+
}
191+
192+
void loop()
193+
{
194+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
195+
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
196+
}

0 commit comments

Comments
 (0)
Please sign in to comment.