Main Content

gpsdev

Connect to a GPS receiver connected to host computer

Description

The gpsdev System object™ connects to a GPS receiver connected to the host computer.

To connect to a GPS receiver:

  1. Create the gpsdev object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?.

Creation

Description

example

gpsObj = gpsdev(port) connects to a GPS Receiver at the specified serial port of host computer.

example

gpsObj = gpsdev(serialobj) connects to a GPS Receiver specified by a serial object.

example

gpsObj = gpsdev(port,___,Name,Value) connects to a GPS Receiver on the specified port or specified through a serial object, using one or more name-value pairs.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

This property is read-only.

The baud rate for serial communication. The baud rate is set at 9600 bits/sec. The GPS receiver must be configured to work at 9600 bits/sec . If your GPS receiver is configured to some other baud rate, reconfigure it to 9600 bits/sec to use gpsdev function.

Specify whether to return the latest or the oldest data samples. The number of samples depends on the SamplesPerRead value. The data read from the GPS receiver is stored in the MATLAB® buffer.

  • latest — Provides the latest data samples available in the buffer. All previous data samples in the buffer are discarded. For example, if SamplesPerRead = 3, the latest three data samples read by the GPS receiver are returned.

  • oldest — Provides the oldest data samples available in the buffer. In this case, no data samples are discarded. For example, if SamplesPerRead = 3, the first three data samples read are returned for the first read, the next three data samples are returned for the second read, and so on.

Tunable: No

Data Types: character vector | string

This property is read-only.

Number of samples read from the GPS receiver using the read function, after the object is locked. The gpsdev object gets locked either at the first call of the read function after the object creation or at the first call of the read function after the execution of the release function.

Data Types: double

This property is read-only.

Samples available in the host buffer. When you release the object, SamplesAvailable is set to 0.

Data Types: double

Samples read from the first read, specified as a positive integer in the range [1 10].

Tunable: No

Data Types: double

Set the output format of the data returned by executing the read function.

When the OutputFormat is set to timetable, the timetable returned has the following fields:

  • LLA (Latitude, Longitude, Altitude)

  • Ground Speed

  • Course over ground

  • Dilution of Precisions(DOPs), VDOP,HDOP,PDOP,

  • GPS Receiver Time

  • Time — System time when the data is read, in datetime or duration format

When the OutputFormat is set to matrix, the data is returned as matrices of Time, LLA, Ground Speed, Course over ground, DOPs, and GPS receiver time. The units for the GPS receiver readings are the same as the timetable format.

Tunable: Yes

Data Types: character vector | string

Set the format of the time displayed when the GPS data is read.

  • datetime — Displays the date and time at which the data is read.

  • duration — Displays the time elapsed in seconds after the GPS object is locked. The gpsdev object gets locked either at the first call of the read function after the object creation or at the first call of the read function after the execution of the release function.

Tunable: Yes

Data Types: character vector | string

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)
flushFlush all GPS data accumulated in the buffers and reset properties
infoRead Update Rate, GPS Lock information and number of satellites in View for the GPS receiver
readRead data from GPS receiver
releaseRelease the GPS object
writeBytesWrite raw commands to the GPS receiver

Examples

Create GPS Connection

Connect to a GPS receiver connected to a specific port.

gpsObj = gpsdev('COM4')
gpsObj = 

  gpsdev with properties: 

                 SerialPort: COM4
                   BaudRate: 9600 (bits/s)

             SamplesPerRead: 1  
                   ReadMode: 'latest'            
                SamplesRead: 0      

Create GPS Connection Using Serial Object

s = serialport('COM4',9600);
gpsObj = gpsdev(s)
gpsObj = 

  gpsdev with properties: 

                 SerialPort: COM4
                   BaudRate: 9600 (bits/s)

             SamplesPerRead: 1  
                   ReadMode: 'latest'            
                SamplesRead: 0       

Connect to a GPS Receiver on the Specified Port with Additional Name-Value options

gpsObj = gpsdev('COM4','SamplesPerRead',2,'ReadMode','oldest');
gpsObj = 

  gpsdev with properties: 

                 SerialPort: COM4
                   BaudRate: 9600 (bits/s)

             SamplesPerRead: 2  
                   ReadMode: 'oldest'            
                SamplesRead: 0      
           SamplesAvailable: 0 

More About

expand all

See Also

Introduced in R2020b