tborg.examples package

tborg.examples.mborg_approxeng

class tborg.examples.mborg_approxeng.JoyStickControl(bus_num=1, address=21, borg=True, log_level=20, voltage_in=12, debug=False)[source]

Bases: Daemon

The ApproxEng.input library is used to control the Thunder Borg.

_BASE_LOGGER_NAME = 'examples'
_LOGGER_NAME = 'examples.mborg-approxeng'
_LOG_PATH = '/home/docs/borg_cube/logs/mborg_approxeng.log'
_MAX_VOLTAGE_MULT = 1.145
_PIDFILE = '/home/docs/borg_cube/run/mborg_approxeng.pid'
_ROTATE_TURN_SPEED = 0.5
_SLOW_SPEED = 0.5
_TBORG_LOGGER_NAME = 'examples.tborg'
_VOLTAGE_IN = 12
_VOLTAGE_OUT = 11.399999999999999
_check_axes(joystick)[source]
_check_presses(joystick)[source]
_process_motion(joystick, fr, tn)[source]
property fwd_rev_invert
init_mborg()[source]

Initialize motor controller.

listen()[source]
log_battery_monitoring()[source]

Dump to the log the initial battery values.

property max_power
property quit
property quit_hold_time
run()[source]

Start the controller listening process.

set_battery_limits()[source]
property turn_invert

tborg.examples.mborg_pygame

class tborg.examples.mborg_pygame.JoyStickControl(bus_num=1, address=21, log_level=20, debug=False)[source]

Bases: PYGameController, Daemon

This class allows control of the MonsterBorg by a PS3/4 controller.

_BASE_LOGGER_NAME = 'examples'
_CTRL_LOGGER_NAME = 'examples.controller'
_LOGGER_NAME = 'examples.mborg-pygame'
_LOG_PATH = '/home/docs/borg_cube/logs/mborg_pygame.log'
_MAX_POWER = 0.9499999999999998
_PIDFILE = '/home/docs/borg_cube/run/mborg_pygame.pid'
_PROCESS_INTERVAL = 0.0
_ROTATE_TURN_SPEED = 0.5
_SLOW_SPEED = 0.5
_TBORG_LOGGER_NAME = 'examples.tborg'
_VOLTAGE_IN = 12.0
_VOLTAGE_OUT = 11.399999999999999
init_mborg()[source]

Initialize the MonsterBorg joystick controller.

log_battery_monitoring()[source]

Dump to the log the initial battery values.

process_event()[source]

Process the current events (overrides the base class method).

run()[source]

Start the controller listening process.

set_defaults(**kwargs)[source]

Set some default values. This method can be set while running. For example if the robot flips over which could be determined with a sensor the axis invert values can be changed.

Parameters:
  • axis_y_invert (bool) – If set to True the up/down control is inverted. Default is False. Can be used if the robot flips over.

  • axis_x_invert (bool) – If set to True the left/right control is inverted. Default is False. Can be used if the robot flips over.

  • rotate_turn_button (int) – Choose the button for rotation. The default is R1 (5).

  • rotate_turn_speed (float) – Choose the speed for rotation. The default is 0.5.

  • drive_slow_button – Choose the button for driving slow. The default is R2 (6).

  • drive_slow_speed (bool) – Choose the speed to decrease to when the drive-slow button is held.

class tborg.examples.mborg_pygame.PYGameController(logger_name='', log_level=20, debug=False)[source]

Bases: object

Initializes the attached controller.

_DEFAULT_CTRL_WAIT = 0.1
_DEFAULT_EVENT_WAIT = 0.0
__METHODS = {256: <function PYGameController.set_quit>, 1536: <function PYGameController.__set_axis>, 1537: <function PYGameController.__set_ball>, 1538: <function PYGameController.__set_hat>, 1539: <function PYGameController.__set_button_down>, 1540: <function PYGameController.__set_button_up>}
__set_axis(event)
__set_ball(event)
__set_button_down(event)
__set_button_up(event)
__set_hat(event)
_initialize_variables()[source]
_quit_sleep()[source]
property ctrl_wait_time

Property that gets or sets the controller wait time. This wait time is used when looping during the controller detection period.

Parameters:

sleep (float) – The period of time to sleep between checks. Defaults to 0.1 seconds.

property event_wait_time

Property that gets or sets the event wait time. This wait time is used when looping during the event processing period.

Parameters:

sleep (float) – The period of time to sleep between event processing. Defaults to 0.0 seconds.

init_controller()[source]

Wait until the controller is connected then initialize pygame.

property is_ctrl_init

A property that returns True or False if the controller is initialized.

is_ps4()[source]

Is a PS4 controller attached?

Note

The current way this is determined may not be reliable, but as of now, it’s the best way I have found.

listen()[source]

Listen to controller events.

process_event()[source]

Process the current events. This method needs to be overridden.

set_quit(event=None)[source]

tborg.examples.web

class tborg.examples.web.monster_web.ImageCapture(camera, processor, running, log_name, *args, **kwargs)[source]

Bases: Thread

Image capture thread

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class tborg.examples.web.monster_web.MonsterWeb(options, port=9000, address=21, log_level=20, *args, **kwargs)[source]

Bases: Daemon

FLIPPED_CAMERA = True

bool: Swap between True and False if the camera image is rotated by 180.

FRAME_RATE = 20

int: Number of images to capture per second

IMAGE_HEIGHT = 192

int: Height of the captured image in pixels

IMAGE_WIDTH = 240

int: Width of the captured image in pixels

JPEG_QUALITY = 80

int: JPEG quality level, smaller is faster, higher looks better (0 to 100)

LAST_FRAME = None
LOCK_FRAME = <unlocked _thread.lock object>
MAX_POWER = 0
_BASE_LOGGER_NAME = 'examples'
_LOGGER_NAME = 'examples.monster_web'
_LOG_PATH = '/home/docs/borg_cube/logs/monster_web.log'
_PIDFILE = '/home/docs/borg_cube/run/monster_web.pid'
_TBORG_LOGGER_NAME = 'examples.tborg'
create_image_buffer_frame()[source]

Create the image buffer frame.

run()[source]

You should override this method when you subclass Daemon. It will be called after the process has been daemonized by start() or restart().

Parameters:
  • args (tuple) – Any positional arguments to pass to the user’s run method.

  • kwargs (dict) – Any keyword arguments to pass to the user’s run method.

class tborg.examples.web.monster_web.StreamProcessor(global_data, *args, **kwargs)[source]

Bases: Thread

Image stream processing thread

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class tborg.examples.web.monster_web.ThreadingTCPServer(server_address, RequestHandlerClass, bind_and_activate=True)[source]

Bases: ThreadingMixIn, TCPServer

allow_reuse_address = True
daemon_threads = True
class tborg.examples.web.monster_web.Watchdog(tb, log_name, *args, **kwargs)[source]

Bases: Thread

Timeout thread

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class tborg.examples.web.monster_web.WebServer(request, client_address, server)[source]

Bases: BaseRequestHandler

Class used to implement the web server

GLOBAL_DATA = None
_render_template(name, **context)[source]
_send(status, reason, content_type, body: bytes)[source]
_serve_mjpeg_stream()[source]
_serve_static(filename)[source]
handle()[source]
parse_request(request)[source]

Create a file-like object from the socket where ‘r’ mode reads text (bytes are decoded using default encoding, usually utf-8). You can specify encoding explicitly if needed: encoding=’utf-8’

tborg.examples.web.monster_web.is_raspberry_pi()[source]