跳转至

Battery

robodyno.components.can_bus.battery

Battery driver.

The battery driver can be used to get the battery voltage and current.

Examples:

>>> from robodyno.components import Battery
>>> from robodyno.interfaces import CanBus
>>> can = CanBus()
>>> battery = Battery(can)
>>> print(battery)
Battery(id=0x0F, voltage=27.66, current=0.0, error=0, rsoc=0.88, fet=3)

Battery

Bases: CanBusDevice

Battery driver.

Attributes:

Name Type Description
id int

Device id.

type Model

Device type.

fw_ver float

Firmware version.

voltage float

Battery voltage.

current float

Battery current.

error int

Error code.

rsoc float

Relative state of charge.

fet int

FET status.

__init__(can, id_=15)

Initializes the battery driver.

Parameters:

Name Type Description Default
can CanBus

Can bus instance.

required
id_ int

Device id.

15

Raises:

Type Description
ValueError

If the device id is invalid.

__repr__()

Gets the string representation of the battery driver.

Returns:

Name Type Description
str str

String representation of the battery driver.

config_can_bus(new_id, heartbeat=1000, bitrate=1000000)

Configures the CAN bus settings.

Parameters:

Name Type Description Default
new_id int

The new device id.

required
heartbeat int

The heartbeat period in milliseconds.

1000
bitrate int

The bitrate of the CAN bus. Choose from 250000, 500000, 1000000.

1000000

Raises:

Type Description
ValueError

If the new CAN id is not in the range of 0x01-0x3f.

get_voltage(timeout=None)

Reads the voltage of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

the voltage(V). Returns None if times out.

get_current(timeout=None)

Reads the current of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

the current(A). Positive value means charging. Returns None if times out.

get_capacity(timeout=None)

Reads the capacity of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
tuple | None

(remaining capacity(Ah), standard_capacity). Returns None if times out.

get_cycle_count(timeout=None)

Reads the cycle count of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
int | None

the cycle count. Returns None if times out.

get_production_date(timeout=None)

Reads the production date of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
datetime | None

the production date. Returns None if times out.

get_balance_status(timeout=None)

Reads the balance status of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
int | None

the balance status. Returns None if times out.

get_protection_status(timeout=None)

Reads the protection status of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
int | None

the protection status. Returns None if times out.

get_hardware_version(timeout=None)

Reads the hardware version of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
str | None

the hardware version. Returns None if times out.

get_rsoc(timeout=None)

Reads the rsoc of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
float | None

the remaining state of charge. Returns None if times out.

get_fet(timeout=None)

Reads the fet status of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
int | None

the fet status. Returns None if times out.

get_string_count(timeout=None)

Reads the string count of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
int | None

the string count. Returns None if times out.

get_temperature(timeout=None)

Reads the temperature of the battery.

Parameters:

Name Type Description Default
timeout float

The timeout in seconds.

None

Returns:

Type Description
tuple | None

the temperatures. Returns None if times out.