16. GNSS
The gnss object is a built-in object that provides GNSS functionality.
Functional overview:
- Provides an interface to acquire positioning information using the Spresense GNSS function.
GNSS Global Object
Methods()/Properties | Summary | Version | Note |
---|---|---|---|
gnss.start() | Starts GNSS positioning. | 02.00.00+ | |
gnss.stop() | Stops GNSS positioning. | 02.00.00+ |
Details
gnss.start(callback[,cycle[,startMode[,satellite]]])
Starts GNSS positioning.
The first GNSS positioning callback is made immediately after the start of positioning, and the callbacks start at the specified cycle based on the timing of the first callback. After that, an immediate callback occurs at the timing when the positioning is fixed for the first time, and thereafter, the callback is made at the specified cycle based on that timing. Once the position is fixed, the timing of the callback is maintained even if the position is lost and re-fixed.
Name | Type | M/O | Summary | Note |
---|---|---|---|---|
callback(pos) | function | mandatory | GNSS positioning callback Executes callback processing at the specified positioning cycle. pos : {Position} GNSS positioning information | |
cycle | number | optional | Positioning cycle [s] Range: 1 - 86400 The default value is 1. | |
startMode | number | optional | Start mode 0: Cold Start 1: Warm Start 2: Hot Start The default value is 0. | If "Warm Start" or "Hot Start" is performed without the recent positioning data, time, or valid satellite orbit information, it will start with a satellite search operation as same as "Cold Start". For more information, refer to here. |
satellite | number | optional | Specifies the satellite systems to be used for positioning in bits. Range: 0 - 255 bit 0: GPS bit 1: GLONASS bit 2: SBAS bit 3: QZSS-L1C/A bit 4: IMES bit 5: QZSS-L1S bit 6: BeiDou bit 7: Galileo The default value is 3 (GPS+GLONASS). If 0 is specified, it will be forced to be the default value. | For more information and restrictions on combinations, refer to here. |
return | boolean | - | true: Success false: Failure |
{Position}
Name | Type | Summary | Note |
---|---|---|---|
.pos_fixmode | number | Fix mode for position 1: Invalid 2: 2D 3: 3D | If fix mode is 2 or more, it indicates that position information is valid. |
.vel_fixmode | number | Fix mode for speed 1: Invalid 2: 2D VZ 3: 2D Offset 4: 3D 5: 1D 6: PRED | If the fix mode is 2 or more, it indicates that the speed information is valid. |
.svtype | number | Satellite systems in use bit 0: GPS bit 1: GLONASS bit 2: SBAS bit 3: QZSS-L1C/A bit 4: IMES bit 5: QZSS-L1S bit 6: BeiDou bit 7: Galileo | |
.numsv | number | Number of visible satellites | |
.numsv_tracking | number | Number of tracking satellites | |
.numsv_calcpos | number | Number of satellites used for position calculation | |
.numsv_calcvel | number | Number of satellites used for speed calculation | |
.datetime | number | GPS time (Unixtime) [ms] | |
.latitude | number | Latitude [degree] | |
.longitude | number | Longitude [degree] | |
.altitude | number | Altitude [m] | |
.geoid | number | Geoid height [m] | |
.velocity | number | Velocity [m/s] | |
.direction | number | Direction [degree] |
gnss.stop([backup])
Stops GNSS positioning.
Note that it is not possible to execute this method from within a GNSS positioning callback.
Even if GNSS positioning is stopped, the final positioning data and satellite orbit information are retained on the SRAM, thus positioning can be resumed with "Hot Start". If the power of the device is turned off, the data on the SRAM is lost and thus the positioning starts as "Cold Start".
The final positioning data and satellite orbit information can be backed up to the flash memory before the device is powered off. The backed up data will be automatically extracted onto SRAM the next time the device is launched and used for "Hot Start". However, if the satellite orbit information has expired or the data has been corrupted, the operation becomes "Cold Start".
Name | Type | M/O | Summary | Note |
---|---|---|---|---|
backup | boolean | optional | Backs up the final positioning data and satellite orbit information to the internal storage (flash memory). true: Enable false: Disable The default value is false. | Frequent writing to flash memory can cause memory failure, therefore it is recommended to back up only at specific times, such as before turning off the device. |
return | boolean | - | true: Success false: Failure |
Object Usage Examples
Sample1
This is a sample that displays GNSS positioning information every 3 seconds.
gnss.start(function(pos) {
print(new Date(pos.datetime).toString()
+ ',' + '0x' + ('00' + pos.svtype.toString(16).toUpperCase()).substr(-2)
+ ',' + pos.numsv
+ ',' + pos.numsv_tracking
+ ',' + pos.numsv_calcpos
+ ',' + pos.numsv_calcvel
+ ',' + pos.pos_fixmode
+ ',' + pos.vel_fixmode
+ ',' + pos.latitude.toFixed(6)
+ ',' + pos.longitude.toFixed(6)
+ ',' + pos.altitude.toFixed(1)
+ ',' + pos.geoid.toFixed(1)
+ ',' + pos.velocity.toFixed(1)
+ ',' + pos.direction.toFixed(1));
}, 3); //3s, cold start, GPS+GLONASS
Sample2
This is a sample that stops GNSS positioning if a valid fix mode is detected consecutively.
var NUM_OF_CONSECUTIVE_FIXES = 10;
var fixCnt = 0;
var cb_pos = function(pos) {
if(pos.pos_fixmode > 1) fixCnt++;
else fixCnt = 0;
print(new Date(pos.datetime).toString()
+ ',' + pos.numsv_tracking
+ ',' + pos.pos_fixmode
+ ',' + pos.latitude.toFixed(6)
+ ',' + pos.longitude.toFixed(6)
+ ',' + fixCnt);
}
gnss.start(cb_pos, 1, 2, 0x2B); //1s, hot start, GPS+GLONASS+QZSS-L1C/A+QZSS-L1S
while(1) {
if(fixCnt >= NUM_OF_CONSECUTIVE_FIXES) break;
};
gnss.stop();
print('finish');