PololuQik2 Class Reference

#include <PololuQik2.h>

List of all members.

Public Member Functions

 PololuQik2 (NewSoftSerial *serial, uint8_t reset, uint8_t errPin, bool EnableCRC, CRC7 *crc)
void begin ()
void motor0Forward (uint8_t speed)
void motor1Forward (uint8_t speed)
void motor0Reverse (uint8_t speed)
void motor1Reverse (uint8_t speed)
void stopBothMotors ()
void stopMotor0 ()
void stopMotor1 ()
void motor0Coast ()
void motor1Coast ()
unsigned int getFirmwareVersion ()
bool hasDataOverrunError ()
bool hasFrameError ()
bool hasCRCError ()
bool hasFormatError ()
bool hasTimeoutError ()

Private Member Functions

void sendMessage (unsigned char message[], unsigned int length)
bool errorBitSet (uint8_t bitToCheck)
uint8_t getError ()
void error ()
void sendByte (uint8_t byte)
uint8_t readByte ()

Private Attributes

NewSoftSerial * _serial
uint8_t _resetPin
uint8_t _errByte
uint8_t _fwVersion
uint8_t _errPin
bool _enCRC
CRC7 * _crc

Detailed Description

This class provides the ability for an arduino to communicate with a pololu Qik2s9v1. It offers both CRC and non-CRC operating modes. Interrupts is partly written in. To use this you will need NewSoftSerial Library and CRC7 library installed.

Definition at line 75 of file PololuQik2.h.


Constructor & Destructor Documentation

PololuQik2::PololuQik2 ( NewSoftSerial *  serial,
uint8_t  reset,
uint8_t  errPin,
bool  EnableCRC,
CRC7 *  crc 
)

Constructor for the class. Requires that a NewSoftSerial and CRC7 Object are passed to it.

This constructor also calls

Parameters:
*serial a NewSoftSerial object provides communication to the module.
reset is the pin the reset on the module is connected to on the arduino.
errPin must be an interrupt pin. This feature is not fully implemented.
EnableCRC is a boolean value as to wheather or not CRC is enabled.
*crc a CRC7 object which can be used for hashing the data. If this is not reqired set to NULL
Todo:
Implement errPin fully.

Definition at line 103 of file PololuQik2.cpp.

References _crc, _enCRC, _errByte, _errPin, _resetPin, and _serial.


Member Function Documentation

void PololuQik2::begin (  ) 

Must be called before the pololu module is used. This resets the module and sets up communication with it.

It is recommended that this command is called in the setup() method.

Definition at line 61 of file PololuQik2.cpp.

References _resetPin, INITIALPACKET, and sendMessage().

void PololuQik2::error (  )  [private]

is the part implementation of interrupts. Ideally this method will be called when an error occurrs. This should happen automatically. This should alert the system/user to the error. The arduino support interrupts however a persistence error prevents this from working.

Note:
You may be able to get this working. My C++ is functional (excuse the pun) but I am no way an expert.

Definition at line 173 of file PololuQik2.cpp.

References getError().

bool PololuQik2::errorBitSet ( uint8_t  bitToCheck  )  [private]

checks if the bitToCheck bit is set. This is used to determine which type of error has occurred.

Parameters:
bitToCheck is a uint8_t. The bit will be tested
Returns:
true if the bit is set.

Definition at line 141 of file PololuQik2.cpp.

References _errByte, and getError().

Referenced by hasCRCError(), hasDataOverrunError(), hasFormatError(), hasFrameError(), and hasTimeoutError().

uint8_t PololuQik2::getError (  )  [private]

Gets and stores the error from the error register on the module. The error is stored in _errByte.

Returns:
uint8_t which details the error that has occurred.
See also:
_errByte

Definition at line 166 of file PololuQik2.cpp.

References _errByte, ERRORPACKET, readByte(), and sendMessage().

Referenced by error(), errorBitSet(), hasCRCError(), hasDataOverrunError(), hasFormatError(), hasFrameError(), and hasTimeoutError().

unsigned int PololuQik2::getFirmwareVersion (  ) 

returns the firmware version

Returns:
unsigned int firmware version

Definition at line 96 of file PololuQik2.cpp.

References FWVERSIONPACKET, readByte(), and sendMessage().

bool PololuQik2::hasCRCError (  ) 

Checks if there is a CRC error occurred.

Returns:
boolean - true if the error has occurred.

Definition at line 136 of file PololuQik2.cpp.

References CRCERRORBIT, errorBitSet(), and getError().

bool PololuQik2::hasDataOverrunError (  ) 

Checks if there is a data overrun error.

Returns:
boolean - true if the error has occurred.

Definition at line 151 of file PololuQik2.cpp.

References DATAOVERRUNERRORBIT, errorBitSet(), and getError().

bool PololuQik2::hasFormatError (  ) 

Checks if there is a Format Error has occurred.

Returns:
boolean - true if the error has occurred.

Definition at line 156 of file PololuQik2.cpp.

References errorBitSet(), FORMATERRORBIT, and getError().

bool PololuQik2::hasFrameError (  ) 

Checks if there is a Frame Error.

Returns:
boolean - true if the error has occurred.

Definition at line 146 of file PololuQik2.cpp.

References errorBitSet(), FRAMEERRORBIT, and getError().

bool PololuQik2::hasTimeoutError (  ) 

Checks if there is a timeout error has occurred.

Returns:
boolean - true if the error has occurred.

Definition at line 161 of file PololuQik2.cpp.

References errorBitSet(), getError(), and TIMEOUTERRORBIT.

void PololuQik2::motor0Coast (  ) 

Allows motor 0 to coast freely.

Definition at line 51 of file PololuQik2.cpp.

References MOTOR0COASTPACKET, and sendMessage().

void PololuQik2::motor0Forward ( uint8_t  speed  ) 

Makes Motor 0 go forwards with a speed of speed.

Parameters:
speed is the speed you wish the motor to move at. Acceptable values are between 0 and 127.

Definition at line 56 of file PololuQik2.cpp.

References MOTOR0FORWARDPACKET, and sendMessage().

void PololuQik2::motor0Reverse ( uint8_t  speed  ) 

Makes Motor 0 reverse with a speed of speed.

Parameters:
speed is the speed you wish the motor to move at. Acceptable values are between 0 and 127.

Definition at line 131 of file PololuQik2.cpp.

References MOTOR0REVERSEPACKET, and sendMessage().

void PololuQik2::motor1Coast (  ) 

Allows motor 1 to coast freely.

Definition at line 121 of file PololuQik2.cpp.

References MOTOR1COASTPACKET, and sendMessage().

void PololuQik2::motor1Forward ( uint8_t  speed  ) 

Makes Motor 1 go forwards with a speed of speed.

Parameters:
speed is the speed you wish the motor to move at. Acceptable values are between 0 and 127.

Definition at line 46 of file PololuQik2.cpp.

References MOTOR1FORWARDPACKET, and sendMessage().

void PololuQik2::motor1Reverse ( uint8_t  speed  ) 

Makes Motor 1 reverse with a speed of speed.

Parameters:
speed is the speed you wish the motor to move at. Acceptable values are between 0 and 127.

Definition at line 41 of file PololuQik2.cpp.

References MOTOR1REVERSEPACKET, and sendMessage().

uint8_t PololuQik2::readByte (  )  [private]

Reads a byte from the NewSoftSerial interface. This is a blocking call. If this is called and no data is being sent then it will halt the execution of the program until it recieves a byte.

Returns:
a byte from the software serial interface

Definition at line 178 of file PololuQik2.cpp.

References _serial.

Referenced by getError(), and getFirmwareVersion().

void PololuQik2::sendByte ( uint8_t  byte  )  [private]

sends a byte out of the NewSoftSerial interface.

Parameters:
byte is the byte to be sent

Definition at line 182 of file PololuQik2.cpp.

References _serial.

Referenced by sendMessage().

void PololuQik2::sendMessage ( unsigned char  message[],
unsigned int  length 
) [private]

formats and sends the packets of data to the controller

Parameters:
message[] an array of bytes to be sent.
length the size of the array.

Definition at line 73 of file PololuQik2.cpp.

References _crc, _enCRC, and sendByte().

Referenced by begin(), getError(), getFirmwareVersion(), motor0Coast(), motor0Forward(), motor0Reverse(), motor1Coast(), motor1Forward(), motor1Reverse(), stopMotor0(), and stopMotor1().

void PololuQik2::stopBothMotors (  ) 

Stops both motors. This method actually calls stopMotor0 and stopMotor1

See also:
stopMotor0
stopMotor1

Definition at line 91 of file PololuQik2.cpp.

References stopMotor0(), and stopMotor1().

void PololuQik2::stopMotor0 (  ) 

Stops Motor 0. This actually called motor0Forward with a speed value of 0.

See also:
motor0Forward

Definition at line 86 of file PololuQik2.cpp.

References MOTOR1REVERSEPACKET, and sendMessage().

Referenced by stopBothMotors().

void PololuQik2::stopMotor1 (  ) 

Stops Motor 1. This acutually called motor1Forward with a speed value of 0.

See also:
motor0Forward

Definition at line 126 of file PololuQik2.cpp.

References MOTOR1REVERSEPACKET, and sendMessage().

Referenced by stopBothMotors().


Member Data Documentation

CRC7* PololuQik2::_crc [private]

a pointer to a CRC7 object. This is used to hash the data being sent to the module. CRC can be used for error detection. And in advanced cases error correction.

Definition at line 297 of file PololuQik2.h.

Referenced by PololuQik2(), and sendMessage().

bool PololuQik2::_enCRC [private]

is true if CRC is enabled.

Definition at line 291 of file PololuQik2.h.

Referenced by PololuQik2(), and sendMessage().

uint8_t PololuQik2::_errByte [private]

Stores the error byte once an error has occurred.

Definition at line 269 of file PololuQik2.h.

Referenced by errorBitSet(), getError(), and PololuQik2().

uint8_t PololuQik2::_errPin [private]

is an interrupt pin on the arduino which is connected to the error pin on the module. This is not currently implemented correctly.

Attention:
This is not fully functional
Todo:
Automated Error Detection needs to be completed.

Definition at line 286 of file PololuQik2.h.

Referenced by PololuQik2().

uint8_t PololuQik2::_fwVersion [private]

stores the firmware version. This is populated with the value onces getFirmwareVersion is called. After that it will simple recall the value from memory. It suppose to save space it could query the module each time. This would increase serial traffic and possibly slow the system down. Its a compromise.

Definition at line 277 of file PololuQik2.h.

uint8_t PololuQik2::_resetPin [private]

is the arduino pin which is connected to the reset pin on the pololu qik2 module.

Definition at line 264 of file PololuQik2.h.

Referenced by begin(), and PololuQik2().

NewSoftSerial* PololuQik2::_serial [private]

This is an instance of NewSoftSerial which the arduino will expect to find a pololu Qik2 connected to.

Definition at line 259 of file PololuQik2.h.

Referenced by PololuQik2(), readByte(), and sendByte().


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines
Generated on Thu Aug 12 09:50:30 2010 for PololuQik2 by  doxygen 1.6.3