Package pololu :: Package motors :: Module qik2s9v1 :: Class Qik2s9v1
[hide private]
[frames] | no frames]

Class Qik2s9v1

source code


Implementation of the Pololu motor controller interface for the Qik 2s9v1 board.
Instance Methods [hide private]
 
__init__(self, device, baud=38400, readTimeout=None, writeTimeout=None, log=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_deviceCallback(self, device, config) source code
 
getFirmwareVersion(self, device=9)
Get the firmware version of the Qik 2s9v1 hardware.
source code
 
getError(self, device=9, message=True)
Get the error message or value stored in the Qik 2s9v1 hardware.
source code
 
getDeviceID(self, device=9)
Get the device ID.
source code
 
getPWMFrequency(self, device=9, message=True)
Get the motor shutdown on error status stored on the hardware device.
source code
 
getMotorShutdown(self, device=9)
Get the motor shutdown on error status stored on the hardware device.
source code
 
getSerialTimeout(self, device=9)
Get the serial timeout stored on the hardware device.
source code
 
setDeviceID(self, value, device=9, message=True)
Set the hardware device number. This is only needed if more that one device is on the same serial buss.
source code
 
setPWMFrequency(self, pwm, device=9, message=True)
Set the PWM frequency.
source code
 
setMotorShutdown(self, value, device=9, message=True)
Set the motor shutdown on error status stored on the hardware device.
source code
 
setSerialTimeout(self, timeout, device=9, message=True)
Set the serial timeout on the hardware device.
source code
 
setM0Coast(self, device=9)
Set motor 0 to coast.
source code
 
setM1Coast(self, device=9)
Set motor 1 to coast.
source code
 
setM0Speed(self, speed, device=9)
Set motor 0 speed.
source code
 
setM1Speed(self, speed, device=9)
Set motor 1 speed.
source code

Inherited from qik.Qik: close, findConnectedDevices, getConfigForDevice, isCRC, isCompactProtocol, isOpen, isPololuProtocol, setCRC, setCompactProtocol, setPololuProtocol

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  DEFAULT_DEVICE_ID = 9
  DEFAULT_SERIAL_TIMEOUT = 0.262
  _COMMAND = {'get-config': 3, 'get-error': 2, 'get-fw-version':...
  _ERRORS = {0: 'OK', 1: 'Bit 0 Unused', 2: 'Bit 1 Unused', 4: '...
  DEVICE_ID = 0
  PWM_PARAM = 1
  MOTOR_ERR_SHUTDOWN = 2
  SERIAL_TIMEOUT = 3
  _CONFIG_NUM = {0: 'Device ID', 1: 'PWM Parameter', 2: 'Shutdow...
  _CONFIG_PWM = {0: (31500, '7-Bit, PWM Frequency 31.5kHz'), 1: ...
  _CONFIG_PWM_TO_VALUE = {3900: 3, 7800: 2, 15700: 1, 31500: 0}

Inherited from qik.Qik (private): _BAUD_DETECT, _BOOL_TO_INT, _CONFIG_RETURN

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, device, baud=38400, readTimeout=None, writeTimeout=None, log=None)
(Constructor)

source code 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__
(inherited documentation)

_deviceCallback(self, device, config)

source code 
Overrides: qik.Qik._deviceCallback

getFirmwareVersion(self, device=9)

source code 
Get the firmware version of the Qik 2s9v1 hardware.
Parameters:
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
Returns:
An integer indicating the version number.

getError(self, device=9, message=True)

source code 
Get the error message or value stored in the Qik 2s9v1 hardware.
Parameters:
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
  • message (bool) - If set to True a text message will be returned, if set to False the integer stored in the Qik will be returned.
Returns:
A list of text messages, integers, or and empty list. See the message parameter above.

getDeviceID(self, device=9)

source code 
Get the device ID.
Parameters:
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
Returns:
An integer number of the hardware device ID.

getPWMFrequency(self, device=9, message=True)

source code 
Get the motor shutdown on error status stored on the hardware device.
Parameters:
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
  • message (bool) - If set to True a text message will be returned, if set to False the integer stored in the Qik will be returned.
Returns:
A text message or an int. See the message parameter above.

getMotorShutdown(self, device=9)

source code 
Get the motor shutdown on error status stored on the hardware device.
Parameters:
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
Returns:
Returns True when morot will shutdown on and error, else False.

getSerialTimeout(self, device=9)

source code 

Get the serial timeout stored on the hardware device.

Caution, more that one value returned from the Qik can have the same actual timeout value according the the formula below. I have verified this as an idiosyncrasy of the Qik itself. There are only a total of 72 unique values that the Qik can logically use the remaining 56 values are repeats of the 72.

Parameters:
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
Returns:
The timeout value in seconds.

setDeviceID(self, value, device=9, message=True)

source code 
Set the hardware device number. This is only needed if more that one device is on the same serial buss.
Parameters:
  • value (int) - The device ID to set in the range of 0 - 127.
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
  • message (bool) - If set to True a text message will be returned, if set to False the integer stored in the Qik will be returned.
Returns:
A text message or an int. See the message parameter above. If value and device are the same OK or 0 will be returned depending on the value of message.
Raises:
  • SerialException - IO error indicating there was a problem reading from the serial connection.

setPWMFrequency(self, pwm, device=9, message=True)

source code 
Set the PWM frequency.
Parameters:
  • pwm (int) - The PWN frequency to set in hertz.
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
  • message (bool) - If set to True a text message will be returned, if set to False the integer stored in the Qik will be returned.
Returns:
A text message or an int. See the message parameter above.
Raises:
  • SerialException - IO error indicating there was a problem reading from the serial connection.

setMotorShutdown(self, value, device=9, message=True)

source code 
Set the motor shutdown on error status stored on the hardware device.
Parameters:
  • value (int) - An integer indicating the effect on the motors when an error occurs. A 1 will cause the cause the motors to stop on an error and a 0 will ignore errors keeping the motors running.
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
  • message (bool) - If set to True a text message will be returned, if set to False the integer stored in the Qik will be returned.
Returns:
Text message indicating the status of the shutdown error. A text message or an int. See the message parameter above.
Raises:
  • SerialException - IO error indicating there was a problem reading from the serial connection.

setSerialTimeout(self, timeout, device=9, message=True)

source code 

Set the serial timeout on the hardware device.

Setting the serial timeout to anything other than zero will cause an error if the serial line is inactive for the time set. This may not be a good thing as leaving the Qik idle may be a required event. Why would you want the Qik to report an error when none actually occurred and your Qik was just idle? This happens with or without the motors running.

This also explains why, when the Qik is set at a very low timeout that the red LED will come on almost immediately. You will not even get a chance to send it a command before the timeout. This would be like temporarily bricking your Qik. Not a good thing, though it's easy to fix by just setting the timeout to 0 again.

OK, so how do we actually use the serial timeout. Good question, the best way I can think of is to send the Qik a keep alive signal. One way of doing this is to execute the getError() method at a little less than half the timeout period. So if the timeout was set to 200ms you would get the error status every 90ms. The Qik will stay alive unless the keep alive signal is not seen. This should solve the problem. However, if the keep alive is sent in a different process or thread you could get a format error if the keep alive command collides with any other command.

Parameters:
  • timeout (float or int) - The timeout value between 0 - 503.04 seconds, however, any number can be passed to the argument, the code will find the nearest allowed value from the 72 that are available.
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
  • message (bool) - If set to True a text message will be returned, if set to False the integer stored in the Qik will be returned.
Returns:
Text message indicating the status of the shutdown error.
Raises:
  • SerialException - IO error indicating there was a problem reading from the serial connection.

setM0Coast(self, device=9)

source code 
Set motor 0 to coast.
Parameters:
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
Raises:
  • SerialTimeoutException - If the low level serial package times out.
  • SerialException - IO error when the port is not open.

setM1Coast(self, device=9)

source code 
Set motor 1 to coast.
Parameters:
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
Raises:
  • SerialTimeoutException - If the low level serial package times out.
  • SerialException - IO error when the port is not open.

setM0Speed(self, speed, device=9)

source code 
Set motor 0 speed.
Parameters:
  • speed (int) - Motor speed as an integer. Negative numbers indicate reverse speeds.
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
Raises:
  • SerialTimeoutException - If the low level serial package times out.
  • SerialException - IO error when the port is not open.

setM1Speed(self, speed, device=9)

source code 
Set motor 1 speed.
Parameters:
  • speed (int) - Motor speed as an integer. Negative numbers indicate reverse speeds.
  • device (int) - The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. Defaults to the hardware's default value.
Raises:
  • SerialTimeoutException - If the low level serial package times out.
  • SerialException - IO error when the port is not open.

Class Variable Details [hide private]

_COMMAND

Value:
{'get-config': 3,
 'get-error': 2,
 'get-fw-version': 1,
 'm0-coast': 6,
 'm0-forward-7bit': 8,
 'm0-forward-8bit': 9,
 'm0-reverse-7bit': 10,
 'm0-reverse-8bit': 11,
...

_ERRORS

Value:
{0: 'OK',
 1: 'Bit 0 Unused',
 2: 'Bit 1 Unused',
 4: 'Bit 2 Unused',
 8: 'Data Overrun Error',
 16: 'Frame Error',
 32: 'CRC Error',
 64: 'Format Error',
...

_CONFIG_NUM

Value:
{0: 'Device ID',
 1: 'PWM Parameter',
 2: 'Shutdown Motors on Error',
 3: 'Serial Error'}

_CONFIG_PWM

Value:
{0: (31500, '7-Bit, PWM Frequency 31.5kHz'),
 1: (15700, '8-Bit, PWM Frequency 15.7 kHz'),
 2: (7800, '7-Bit, PWM Frequency 7.8 kHz'),
 3: (3900, '8-Bit, PWM Frequency 3.9 kHz')}