tborg package

Subpackages

The ConfigLogger class is used to configure loggers.

by Carl J. Nobile

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class tborg.ConfigLogger(format_str=None)[source]

Bases: object

Setup some basic logging.

config(logger_name=None, file_path=None, level=30)[source]

Config the logger.

class tborg.ThunderBorg(bus_num=1, address=21, logger_name='', log_level=30, auto_set_addr=False, static_init=False)[source]

Bases: object

This module is designed to communicate with the ThunderBorg motor controller board.

COMMAND_ALL_OFF = 14

Switch everything off

COMMAND_ANALOG_MAX = 1023

Maximum value for analog readings

COMMAND_GET_A = 10

Get motor A direction and PWM rate

COMMAND_GET_B = 13

Get motor B direction and PWM rate

COMMAND_GET_BATT_LIMITS = 23

Get the battery monitoring limits

COMMAND_GET_BATT_VOLT = 21

Get the battery voltage reading

COMMAND_GET_DRIVE_A_FAULT = 15

Get the drive fault flag for motor A, indicates faults such as short-circuits and under voltage.

COMMAND_GET_DRIVE_B_FAULT = 16

Get the drive fault flag for motor B, indicates faults such as short-circuits and under voltage

COMMAND_GET_FAILSAFE = 20

Get the failsafe flag

COMMAND_GET_ID = 153

Get the board identifier

COMMAND_GET_LED1 = 2

Get the color of the ThunderBorg LED

COMMAND_GET_LED2 = 4

Get the color of the ThunderBorg Lid LED

COMMAND_GET_LED_BATT_MON = 7

Get the state of showing the current battery level via the LEDs

COMMAND_SET_ALL_FWD = 17

Set all motors PWM rate in a forwards direction

COMMAND_SET_ALL_REV = 18

Set all motors PWM rate in a reverse direction

COMMAND_SET_A_FWD = 8

Set motor A PWM rate in a forwards direction

COMMAND_SET_A_REV = 9

Set motor A PWM rate in a reverse direction

COMMAND_SET_BATT_LIMITS = 22

Set the battery monitoring limits

COMMAND_SET_B_FWD = 11

Set motor B PWM rate in a forwards direction

COMMAND_SET_B_REV = 12

Set motor B PWM rate in a reverse direction

COMMAND_SET_FAILSAFE = 19

Set the failsafe flag, turns the motors off if communication is interrupted.

COMMAND_SET_I2C_ADD = 170

Set a new I²C address

COMMAND_SET_LED1 = 1

Set the color of the ThunderBorg LED

COMMAND_SET_LED2 = 3

Set the color of the ThunderBorg Lid LED

COMMAND_SET_LEDS = 5

Set the color of both the LEDs

COMMAND_SET_LED_BATT_MON = 6

Set the color of both LEDs to show the current battery level

COMMAND_VALUE_FWD = 1

I²C value representing forward

COMMAND_VALUE_OFF = 0

I²C value representing off

COMMAND_VALUE_ON = 1

I²C value representing on

COMMAND_VALUE_REV = 2

I²C value representing reverse

COMMAND_WRITE_EXTERNAL_LED = 24

Write a 32bit pattern out to SK9822 / APA102C

DEFAULT_BUS_NUM = 1

Default I²C bus number.

DEFAULT_I2C_ADDRESS = 21

Default I²C address of the ThunderBorg board.

close_streams()[source]

Close both streams if the ThunderBorg was not found and when we are shutting down. We don’t want memory leaks.

classmethod find_board(bus_num=1, tb=None, close=True, logger_name='')[source]

Scans the I²C bus for ThunderBorg boards and returns a list of all usable addresses.

Note

Rev 1 boards use bus number 0 and rev 2 boards use bus number 1.

Parameters:
  • bus_num (int) – The bus number where the address will be scanned. Default bus number is 1.

  • tb (ThunderBorg instance) – Use a pre-existing ThunderBorg instance. Default is None.

  • close (bool) – Default is True to close the stream before exiting.

Raises:
get_battery_monitoring_limits()[source]

Read the current battery monitoring limits used for setting the LED color.

Note

The colors shown, range from full red at minimum or below, yellow half way, and full green at maximum or higher.

Return type:

Return a tuple of (minimum, maximum). The values are between 0.0 and 36.3 V.

Raises:
get_battery_voltage()[source]

Read the current battery level from the main input.

Return type:

Return a voltage value based on the 3.3 V rail as a reference.

Raises:
get_comms_failsafe()[source]

Get the failsafe state.

Return type:

Return the failsafe state.

Raises:
get_drive_fault_one()[source]

Read the motor drive fault state for motor one.

Note

  1. Faults may indicate power problems, such as under-voltage (not enough power), and may be cleared by setting a lower drive power.

  2. If a fault is persistent (repeatably occurs when trying to control the board) it may indicate a wiring issue such as indicated below.

  1. The supply is not powerful enough for the motors. The board has a bare minimum requirement of 6V to operate correctly. The recommended minimum supply of 7.2V should be sufficient for smaller motors.

  2. The + and - connections for the motor are connected to each other.

  3. Either + or - is connected to ground (GND, also known as 0V or earth).

  4. Either + or - is connected to the power supply (V+, directly to the battery or power pack).

  5. One of the motors may be damaged.

  1. Faults will self-clear, they do not need to be reset, however some faults require both motors to be moving at less than 100% to clear.

  2. The easiest way to run a check is to put both motors at a low power setting that is high enough for them to rotate easily. e.g. 30%

  3. Note that the fault state may be true at power up, this is normal and should clear when both motors have been driven.

Return type:

Return a False if there are no problems else a True if a fault has been detected.

Raises:
get_drive_fault_two()[source]

Read the motor drive fault state for motor two.

Note

  1. Faults may indicate power problems, such as under-voltage (not enough power), and may be cleared by setting a lower drive power.

  2. If a fault is persistent (repeatably occurs when trying to control the board) it may indicate a wiring issue such as indicated below.

  1. The supply is not powerful enough for the motors. The board has a bare minimum requirement of 6V to operate correctly. The recommended minimum supply of 7.2V should be sufficient for smaller motors.

  2. The + and - connections for the motor are connected to each other.

  3. Either + or - is connected to ground (GND, also known as 0V or earth).

  4. Either + or - is connected to the power supply (V+, directly to the battery or power pack).

  5. One of the motors may be damaged.

  1. Faults will self-clear, they do not need to be reset, however some faults require both motors to be moving at less than 100% to clear.

  2. The easiest way to run a check is to put both motors at a low power setting that is high enough for them to rotate easily. e.g. 30%

  3. Note that the fault state may be true at power up, this is normal and should clear when both motors have been driven.

Return type:

Return a False if there are no problems else a True if a fault has been detected.

Raises:
get_led_battery_state()[source]

Get the state of the LEDs between the default and the battery monitoring state.

Return type:

Return False for the default state and True for the battery monitoring state.

Raises:
get_led_one()[source]

Get the current RGB color of the ThunderBorg LED number one.

Note

  1. (0, 0, 0) LED off

  2. (1, 1, 1) LED full white

  3. (1.0, 0.5, 0.0) LED bright orange

  4. (0.2, 0.0, 0.2) LED dull violet

Return type:

Return a tuple of the RGB color for LED number one.

Raises:
get_led_two()[source]

Get the current RGB color of the ThunderBorg LED number two.

Note

  1. (0, 0, 0) LED off

  2. (1, 1, 1) LED full white

  3. (1.0, 0.5, 0.0) LED bright orange

  4. (0.2, 0.0, 0.2) LED dull violet

Return type:

Return a tuple of the RGB color for LED number two.

Raises:
get_motor_one()[source]

Get the drive level of motor one.

Return type:

The motor drive level.

Raises:
get_motor_two()[source]

Get the drive level of motor two.

Return type:

The motor drive level.

Raises:
halt_motors()[source]

Halt both motors. Should be used when ending a program or when needing to come to an abrupt halt. Executing set_both_motors(0) essentially does the same thing.

Raises:
set_battery_monitoring_limits(minimum, maximum)[source]

Set the battery monitoring limits used for setting the LED color.

Note

  1. The colors shown, range from full red at minimum or below, yellow half way, and full green at maximum or higher.

  2. These values are stored in EEPROM and reloaded when the board is powered.

Parameters:
  • minimum (float) – Value between 0.0 and 36.3 Volts.

  • maximum (float) – Value between 0.0 and 36.3 Volts.

Raises:
set_both_leds(r, g, b)[source]

Set the color of both of the ThunderBorg LEDs

Note

  1. (0, 0, 0) LED off

  2. (1, 1, 1) LED full white

  3. (1.0, 0.5, 0.0) LED bright orange

  4. (0.2, 0.0, 0.2) LED dull violet

Parameters:
  • r (float) – Range is between 0.0 and 1.0.

  • g (float) – Range is between 0.0 and 1.0.

  • b (float) – Range is between 0.0 and 1.0.

Raises:
set_both_motors(level)[source]

Set the drive level for motor two.

Parameters:

level (float) – Valid levels are from -1.0 to +1.0. A level of 0.0 is full stop. A level of 0.75 is 75% forward. A level of -0.25 is 25% reverse. A level of 1.0 is 100% forward.

Raises:
set_comms_failsafe(state)[source]

Set the state of the motor failsafe. The default failsafe state of False will cause the motors to continuously run without a keepalive signal. If set to True the motors will shutdown after 1/4 of a second unless it is sent the speed command every 1/4 of a second.

Parameters:

state (bool) – If set to True failsafe is enabled, else if set to False failsafe is disabled. Default is disables when powered on.

Raises:
set_external_led_colors(colors)[source]

Takes a set of RGB values to set multiple LED devices like SK9822 and APA102C.

Note

  1. Each call will set all of the LEDs.

  2. Executing tb.set_external_led_colors([[1.0, 1.0, 0.0]]) will set a single LED to full yellow.

  3. Executing tb.set_external_led_colors([[1.0, 0.0, 0.0], [0.5, 0.0, 0.0], [0.0, 0.0, 0.0]]) will set LED 1 to full red, LED 2 to half red, and LED 3 to off.

Parameters:

colors (list) – The RGB colors for setting the LEDs.

Raises:
classmethod set_i2c_address(new_addr, cur_addr=-1, bus_num=1, logger_name='')[source]

Scans the I²C bus for the first ThunderBorg and sets it to a new I²C address. If cur_addr is supplied it will change the address of the board at that address rather than scanning the bus. The bus_num if supplied determines which I²C bus to scan using 0 for Rev 1 or 1 for Rev 2 boards. If bum_bus is not supplied it defaults to 1. Warning, this new I²C address will still be used after resetting the power on the device.

Parameters:
  • new_addr (int) – New address to set a ThunderBorg board to.

  • cur_addr (int) – The current address of a ThunderBorg board. The default of -1 will scan the entire range.

  • bun_num – The bus number where the address range will be found. Default is set to 1.

Raises:
  • KeyboardInterrupt – Keyboard interrupt.

  • ThunderBorgException – An error happened on a stream or failed to set the new address.

set_led_battery_state(state)[source]

Change from the default LEDs state (set with set_led_one and/or set_led_two) to the battery monitoring state.

Note

If in the battery monitoring state the configured state is disabled. The battery monitoring state sweeps the full range between red (7V) and green (35V).

Parameters:

state (bool) – If True (enabled) LEDs will show the current battery level, else if False (disabled) the LEDs will be controlled with the set_led_* and the set_both_leds methods.

Raises:
set_led_one(r, g, b)[source]

Set the color of the ThunderBorg LED number one.

Note

  1. (0, 0, 0) LED off

  2. (1, 1, 1) LED full white

  3. (1.0, 0.5, 0.0) LED bright orange

  4. (0.2, 0.0, 0.2) LED dull violet

Parameters:
  • r (float) – Range is between 0.0 and 1.0.

  • g (float) – Range is between 0.0 and 1.0.

  • b (float) – Range is between 0.0 and 1.0.

Raises:
set_led_two(r, g, b)[source]

Set the color of the ThunderBorg LED number two.

Note

  1. (0, 0, 0) LED off

  2. (1, 1, 1) LED full white

  3. (1.0, 0.5, 0.0) LED bright orange

  4. (0.2, 0.0, 0.2) LED dull violet

Parameters:
  • r (float) – Range is between 0.0 and 1.0.

  • g (float) – Range is between 0.0 and 1.0.

  • b (float) – Range is between 0.0 and 1.0.

Raises:
set_motor_one(level)[source]

Set the drive level for motor one.

Parameters:

level (float) – Valid levels are from -1.0 to +1.0. A level of 0.0 is full stop. A level of 0.75 is 75% forward. A level of -0.25 is 25% reverse. A level of 1.0 is 100% forward.

Raises:
set_motor_two(level)[source]

Set the drive level for motor two.

Parameters:

level (float) – Valid levels are from -1.0 to +1.0. A level of 0.0 is full stop. A level of 0.75 is 75% forward. A level of -0.25 is 25% reverse. A level of 1.0 is 100% forward.

Raises:
write_external_led_word(b0, b1, b2, b3)[source]

Write low level serial LED 32 bit word to set multiple LED devices like SK9822 and APA102C.

Note

Bytes are written MSB (Most Significant Byte) first, starting at b0. e.g. Executing tb.write_external_led_word(255, 64, 1, 0) would send 11111111 01000000 00000001 00000000 to the LEDs.

Parameters:
  • b0 (int) – Byte zero

  • b1 (int) – Byte one

  • b2 (int) – Byte two

  • b3 (int) – Byte three

Raises:
exception tborg.ThunderBorgException[source]

Bases: Exception

tborg.create_working_dir()[source]

This function creates a borg_cube directory containing a logs and run directories.

  1. The logs directory contains all logs.

  2. The run directory contains all daemon pid/lock files.