跳转至

GpsSensor

robodyno.components.can_bus.gps_sensor

GPS sensor driver.

This module provides a class to get the GPS data from the GPS sensor which is based on a GT-U12 module.

Examples:

>>> from robodyno.components import GpsSensor
>>> from robodyno.interfaces import CanBus
>>> can = CanBus()
>>> gps = GpsSensor(can)
>>> gps.get_position()
{'timestamp': datetime.time(0, 0, 0, 0), 'longitude': 0.0, 'latitude': 0.0}
>>> can.disconnect()

GpsSensor

Bases: CanBusDevice

GPS sensor driver.

Attributes:

Name Type Description
id int

Device id.

type Model

Device type.

fw_ver float

Firmware version.

timestamp float

Timestamp of the last received data.

__init__(can, id_=50)

Initialize the GPS sensor driver.

Parameters:

Name Type Description Default
can CanBus

CanBus object.

required
id_ int

Device id. Defaults to 0x32.

50

Raises:

Type Description
ValueError

If the device type is not GPS sensor.

get_position(timeout=None)

Get the position of the GPS sensor.

Parameters:

Name Type Description Default
timeout float

Timeout. Defaults to None.

None

Returns:

Type Description
Optional[dict]

Optional[dict]: Timestamp, longitude and latitude.

get_position_str(timeout=None)

Get the position of the GPS sensor in string format.

Parameters:

Name Type Description Default
timeout float

Timeout. Defaults to None.

None

Returns:

Type Description
Optional[str]

Optional[str]: Position (timestamp, longitude, latitude) in string format.

config_can_bus(new_id=None, bitrate=1000000)

Configures the can bus.

Parameters:

Name Type Description Default
new_id int

New device id.

None
bitrate int

Can bus bitrate.

1000000

Raises:

Type Description
ValueError

If the new id is invalid.