Source code for pyupm_grovemd

# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.8
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.





from sys import version_info
if version_info >= (2, 6, 0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            fp, pathname, description = imp.find_module('_pyupm_grovemd', [dirname(__file__)])
        except ImportError:
            import _pyupm_grovemd
            return _pyupm_grovemd
        if fp is not None:
            try:
                _mod = imp.load_module('_pyupm_grovemd', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _pyupm_grovemd = swig_import_helper()
    del swig_import_helper
else:
    import _pyupm_grovemd
del version_info
try:
    _swig_property = property
except NameError:
    pass  # Python < 2.2 doesn't have 'property'.


def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
    if (name == "thisown"):
        return self.this.own(value)
    if (name == "this"):
        if type(value).__name__ == 'SwigPyObject':
            self.__dict__[name] = value
            return
    method = class_type.__swig_setmethods__.get(name, None)
    if method:
        return method(self, value)
    if (not static):
        if _newclass:
            object.__setattr__(self, name, value)
        else:
            self.__dict__[name] = value
    else:
        raise AttributeError("You cannot add attributes to %s" % self)


def _swig_setattr(self, class_type, name, value):
    return _swig_setattr_nondynamic(self, class_type, name, value, 0)


def _swig_getattr_nondynamic(self, class_type, name, static=1):
    if (name == "thisown"):
        return self.this.own()
    method = class_type.__swig_getmethods__.get(name, None)
    if method:
        return method(self)
    if (not static):
        return object.__getattr__(self, name)
    else:
        raise AttributeError(name)

def _swig_getattr(self, class_type, name):
    return _swig_getattr_nondynamic(self, class_type, name, 0)


def _swig_repr(self):
    try:
        strthis = "proxy of " + self.this.__repr__()
    except Exception:
        strthis = ""
    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
    _object = object
    _newclass = 1
except AttributeError:
    class _object:
        pass
    _newclass = 0



def getVersion():
    return _pyupm_grovemd.getVersion()
getVersion = _pyupm_grovemd.getVersion

_pyupm_grovemd.GROVEMD_I2C_BUS_swigconstant(_pyupm_grovemd)
GROVEMD_I2C_BUS = _pyupm_grovemd.GROVEMD_I2C_BUS

_pyupm_grovemd.GROVEMD_DEFAULT_I2C_ADDR_swigconstant(_pyupm_grovemd)
GROVEMD_DEFAULT_I2C_ADDR = _pyupm_grovemd.GROVEMD_DEFAULT_I2C_ADDR
[docs]class GroveMD(_object): """ API for the Grove I2C Motor Driver. Deprecated This class is being replaced by MD ID: grovemd Name: I2C Motor Driver Category: motor Manufacturer: seeed Connection: i2c Kit: robok This class implements support for the Grove I2C Motor Driver. This device can support a single 4-wire stepper motor, or two 2-wire DC motors. The device contains an Atmel* ATmega8L microcontroller that manages an L298N H-bridge driver chip. This device supports an I2C bus speed of 100Khz only. The module does not provide any telemetry or status - it only accepts I2C commands for its various operations. This module was tested with version 1.3 of the Grove I2C Motor Driver. For stepper operation, this driver can run in one of two modes - Mode 1, where this driver handles the stepping operation, and Mode 2, where this driver simply sends commands to the Grove Motor Driver, and it handles the stepping operation. Mode2 requires updated (and working) firmware to be loaded onto the device. The default stepper operation mode is Mode1, which is generally more flexible and is supported on all firmware revisions. An example showing the use of a DC motorAn example showing the use of a 4-wire stepper C++ includes: grovemd.hpp """ __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, GroveMD, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, GroveMD, name) __repr__ = _swig_repr SET_SPEED = _pyupm_grovemd.GroveMD_SET_SPEED SET_PWM_FREQ = _pyupm_grovemd.GroveMD_SET_PWM_FREQ SET_DIRECTION = _pyupm_grovemd.GroveMD_SET_DIRECTION SET_MOTOR_A = _pyupm_grovemd.GroveMD_SET_MOTOR_A SET_MOTOR_B = _pyupm_grovemd.GroveMD_SET_MOTOR_B STEPPER_ENABLE = _pyupm_grovemd.GroveMD_STEPPER_ENABLE STEPPER_DISABLE = _pyupm_grovemd.GroveMD_STEPPER_DISABLE STEPPER_NUM_STEPS = _pyupm_grovemd.GroveMD_STEPPER_NUM_STEPS STEP_DIR_CCW = _pyupm_grovemd.GroveMD_STEP_DIR_CCW STEP_DIR_CW = _pyupm_grovemd.GroveMD_STEP_DIR_CW DIR_CCW = _pyupm_grovemd.GroveMD_DIR_CCW DIR_CW = _pyupm_grovemd.GroveMD_DIR_CW STEP_MODE1 = _pyupm_grovemd.GroveMD_STEP_MODE1 STEP_MODE2 = _pyupm_grovemd.GroveMD_STEP_MODE2 def __init__(self, bus=0, address=0x0f): """ GroveMD(int bus=GROVEMD_I2C_BUS, uint8_t address=GROVEMD_DEFAULT_I2C_ADDR) GroveMD constructor Parameters: ----------- bus: I2C bus to use address: I2C address to use """ this = _pyupm_grovemd.new_GroveMD(bus, address) try: self.this.append(this) except Exception: self.this = this __swig_destroy__ = _pyupm_grovemd.delete_GroveMD __del__ = lambda self: None
[docs] def writePacket(self, reg, data1, data2): """ bool writePacket(REG_T reg, uint8_t data1, uint8_t data2) Composes and writes a 3-byte packet to the controller Parameters: ----------- reg: Register location data1: First byte of data data2: Second byte of data True if successful """ return _pyupm_grovemd.GroveMD_writePacket(self, reg, data1, data2)
[docs] def setMotorSpeeds(self, speedA, speedB): """ bool setMotorSpeeds(uint8_t speedA, uint8_t speedB) To control DC motors, sets the speed of motors A & B. Valid values are 0-255. Parameters: ----------- speedA: Speed of motor A speedB: Speed of motor B True if successful """ return _pyupm_grovemd.GroveMD_setMotorSpeeds(self, speedA, speedB)
[docs] def setPWMFrequencyPrescale(self, freq=0x03): """ bool setPWMFrequencyPrescale(uint8_t freq=0x03) To control DC motors, sets the PWM frequency prescale factor. Note: this register is not ducumented other than to say the default value is 0x03. Presumably, this is the timer prescale factor used on the ATMega MCU timer driving the PWM. Parameters: ----------- freq: PWM prescale frequency; default is 0x03 True if successful """ return _pyupm_grovemd.GroveMD_setPWMFrequencyPrescale(self, freq)
[docs] def setMotorDirections(self, dirA, dirB): """ bool setMotorDirections(DC_DIRECTION_T dirA, DC_DIRECTION_T dirB) To control DC motors, sets the directions of motors A & B Parameters: ----------- dirA: Direction for motor A, DIR_CW or DIR_CCW dirB: Direction for motor B, DIR_CW or DIR_CCW True if successful """ return _pyupm_grovemd.GroveMD_setMotorDirections(self, dirA, dirB)
[docs] def enableStepper(self, dir, speed): """ bool enableStepper(STEP_DIRECTION_T dir, uint8_t speed) To control a stepper motor, sets its direction and speed, and then starts operation. For Mode2, this method will return immediately. For Mode1 (the default) this method returns when the number of steps specified by setStepperSteps() has completed. Parameters: ----------- dir: Direction, STEP_DIR_CW or STEP_DIR_CCW speed: Motor speed. Valid range is 1-255. For Mode 1 (default), this specifies the speed in RPM's. For Mode 2, speed is multiplied by 4ms by the board, so higher numbers will mean a slower speed. True if successful """ return _pyupm_grovemd.GroveMD_enableStepper(self, dir, speed)
[docs] def disableStepper(self): """ bool disableStepper() To control a stepper motor, stops the stepper motor. True if successful """ return _pyupm_grovemd.GroveMD_disableStepper(self)
[docs] def setStepperSteps(self, steps): """ bool setStepperSteps(unsigned int steps) To control a stepper motor, specifies the number of steps to execute. For Mode2, valid values are between 1-255, 255 means continuous rotation. For Mode1 (the default) steps can be any positive integer. Parameters: ----------- steps: Number of steps to execute. 255 (only in Mode2) means continuous rotation. True if successful """ return _pyupm_grovemd.GroveMD_setStepperSteps(self, steps)
[docs] def configStepper(self, *args): """ void configStepper(unsigned int stepsPerRev, STEP_MODE_T mode=STEP_MODE1) Configure the initial Stepper parameters. This should be called before any other stepper method. Parameters: ----------- stepsPerRev: The number of steps required to complete one full revolution. mode: The stepper operating mode, default STEP_MODE1 Elapsed milliseconds """ return _pyupm_grovemd.GroveMD_configStepper(self, *args)
GroveMD_swigregister = _pyupm_grovemd.GroveMD_swigregister GroveMD_swigregister(GroveMD) # This file is compatible with both classic and new-style classes.