Example #1
0
A future enhancement will be to create an event loop and be able to control the
car via asynchronous calls.
"""

from auto import db
from cio.rpc_client import acquire_component_interface, dispose_component_interface
import time

STORE = db.default_db(same_thread=True)

CAR_THROTTLE_FORWARD_SAFE_SPEED = STORE.get('CAR_THROTTLE_FORWARD_SAFE_SPEED',
                                            25)
CAR_THROTTLE_REVERSE_SAFE_SPEED = STORE.get('CAR_THROTTLE_REVERSE_SAFE_SPEED',
                                            -25)

MOTORS = acquire_component_interface('CarMotors')
MOTORS.on()

PID_STEERING = acquire_component_interface('PID_steering')

GYRO_ACCUM = acquire_component_interface('Gyroscope_accum')


def forward(duration):
    """
    Drive the car forward for `duration` seconds.

    This function is synchronous, thus it will not return for
    approximately `duration` seconds.
    """
    straight(CAR_THROTTLE_FORWARD_SAFE_SPEED, duration, invert_output=False)
Example #2
0
def _calibrate_microcontroller():
    calibrator = cio_rpc_client.acquire_component_interface('Calibrator')
    cio_rpc_client.redirect_stdio(stdout=sys.stdout)
    calibrator.calibrate()
    cio_rpc_client.restore_stdio()
    cio_rpc_client.dispose_component_interface(calibrator)
Example #3
0
###############################################################################
#
# Copyright (c) 2017-2018 AutoAuto, LLC
# ALL RIGHTS RESERVED
#
# Use of this library, in source or binary form, is prohibited without written
# approval from AutoAuto, LLC.
#
###############################################################################
"""
This module provides a simple helper to use the buzzer.
"""

from cio.rpc_client import acquire_component_interface

BUZZER = acquire_component_interface('Buzzer')


def buzz(notes):
    """
    Play the given `notes` on the device's buzzer.
    """
    BUZZER.play(notes)
    BUZZER.wait()


def honk():
    """
    Make a car horn ("HONK") sound.
    """
    buzz('!T95 O4 G#16 R16 G#4')
Example #4
0
from auto import logger
log = logger.init('battery_monitor', terminal=True)

log.info("Starting battery monitoring process...")

if STORE.get('BATTERY_MONITOR_DISABLED', False):
    log.info("Battery monitor is disabled on this device... exiting.")
    sys.exit()

BATTERY_HIGH_MILLIVOLTS = STORE.get('BATTERY_HIGH_MILLIVOLTS', 8400)
BATTERY_LOW_MILLIVOLTS = STORE.get('BATTERY_LOW_MILLIVOLTS', 6500)

log.info("Battery high millivolts: {}".format(BATTERY_HIGH_MILLIVOLTS))
log.info("Battery low millivolts:  {}".format(BATTERY_LOW_MILLIVOLTS))

buzz = acquire_component_interface("Buzzer")
batt = acquire_component_interface("BatteryVoltageReader")


def batt_voltage_to_pct(millivolts):
    """
    Take in millivolts (an integer) and
    return percentage (an integer in [0, 100]).

    See: https://github.com/AutoAutoAI/libauto/issues/7
    """
    high = BATTERY_HIGH_MILLIVOLTS
    low = BATTERY_LOW_MILLIVOLTS
    if millivolts > high * 1.05:
        return None  # Something is wrong... the battery can't be this high.
    if millivolts > high: