Arduino Library for Qik 2s9v1

I have been working with Arduino’s for a couple of year now and find them a fascinating, intuitive platform to work on.
I have been working on a couple of autonomous robot type project recently and a seamless interface between the micro-controller and peripheral modules is vital. A motor controller is a common modules on most robotic systems as a majority of micro controllers will not supply enough current to run motors.

The Pololu Qik 2s9v1 is an excellent product with many feature including built in Error detection and CRC checksums. Interfacing with the module is extremely simple through a serial connection at varying baud rate. There are a number of packages available on the web to control this module the most notable I have found is qik2s9v1arduino (code.google.com/p/qik2s9v1arduino/). It is an excellent library which is extremely simple to use and understand. However it does not make use of the module more advanced features such as the CRC error detection. The CRC feature is useful for those who wish to increase the reliability of there system by introducing error detection.

CRC is a cyclic redundancy check, it work by taking calculating a checksum on the data being sent to the module. This checksum is added to end of the data packet. When the module receives the data it hashes the packet and compares the checksum it created to the checksum you sent to it. If they match up then the integrity of the packet is complete and the packet and then be interpreted. If the checksums don’t match the packet has not been transmitted correctly and the module will signal the micro-controller with an error. Packet corruption can be can be caused by a number causes including but not limited to:

  • Noisy signal lines
  • Loose connections
  • Unstable power supply
  • Software error

This library is based on the work in the before mentioned project however it has CRC features embedded and is ready for interrupt based error detection to be included. The CRC is added by an additional Class. There are reasons for not building the CRC into the controller class. That is that there are many algorithms to compute CRC (in this case CRC7). Some of these methods will do the arithmetics long hand each time and others will pre-hash all the values. There are advantages to both however that is beyond the scope of this. The method that the end user decides to use to generate the checksum is up to them as long as their CRC7 class implements the same interface as the one used in this system. The interface to the CRC7 Class can be found in the documentation (generated by dOxygen) which is enclosed in the attached file.

The CRC feature can be turned on or off at will (however the module will require the jumper to be removed and a reset for this to function correctly). The library makes use of the NewSoftSerial library written by Mikal Hart (available from arduiniana.org/libraries/newsoftserial/). As with the CRC7 object the NewSoftSerial object is passed by pointer and not hardwired into the class. This allows for other classes which exhibit an identical external interface to replace it at will.

The documentation for this system is quite complete and comprehensive however if you feel anything has been overlook please email edwilson1989 [AT] gmail [dot] com.

Note that this library is released as free software. It comes without warranty or being fit for purpose. You use this library entirely at your own risk.
PololuQik2_CRC.tar.gz (144 KB)

Hello Ed, thanks for sharing this useful library!

One suggestion though: you should package your files as a zip file rather than .tar.gz so that windows users can easily access them. Also, it is unusual to put .tar files inside of other .tar files. The structure of your .tar.gz file makes it quite hard to unpack it in a reasonable way. This is the sequence of commands I had to run to unpack it:

$ mkdir PololuQik2_CRC
$ cd PololuQik2_CRC/
$ mv ../PololuQik2_CRC.tar.gz .
$ tar -xzf PololuQik2_CRC.tar.gz
$ mkdir CRC7 example PololuQik2
$ cd CRC7
$ mv ../CRC7.tar .
$ tar -xf CRC7.tar 
$ cd ../example
$ mv ../example.tar .
$ tar -xf example.tar 
$ cd ../PololuQik2
$ mv ../PololuQik2.tar .
$ tar -xf PololuQik2.tar
$ cd ..
$ rm *.tar.gz **/*.tar

Is there some easier way to unpack it that I’m not aware of? Anyway, I have attached a nicely repackaged .zip file in case anyone wants it.

Also, I doubt this claim:

I like this idea a lot, but I doubt that it is as simple as you claim. Wouldn’t you need to make all the functions in NewSoftSerial be virtual so they can be overridden by subclasses (which I’ve heard decreases performance) and then you would need to make your alternative class be a subclass of NewSoftSerial? How does your Qik library know which subroutine to call at runtime when you try to send some serial bytes?

–David
PololuQik2_CRC.zip (218 KB)

I do apologise about the structure of my tar.gz file however that is how I saw the structure of the project. The CRC7 class was written separately to the actual controller class so I thought it made sense to put them in separate folders/tar files. I feel that this may also help emphasise the second point you made about being able to swap class in and out for each other. The CRC7 class is another class that is would be possible to swap out to select an algorithm that is suited to your application.

On the above point, it does appear a little more difficult to do. I do not come from a C++ background. I was taught C and then Java. And it java classes implementing the same interface can simple be swapped out for each other. This is however a principle of OO programming. It appears that to implement this, as Ben suggested, the methods in the NewSoftSerial class would have to be virtual so that they can be overwritten. This would make a template (as I understand it). This template can then be extended/implemented in the NewSoftSerial and other libraries to make it swappable. Looking at it now there might be a few other classes in the arduino structure which may benefit from templates.

NewSoftSerial offers a similar interface to the arduino serial library it would be nice to see both of this derive from the same template. This may also be a nice feature for the ethernet shields. There we go… it appears I have just found something to work on over my summer break.

Many thanks for your comments David.

Here is another version. A little temperamental possibly. This one allows for CRCbase to be extended allowing for different implementations of the CRC algorithm.
PololuQik2_CRC_V02.zip (225 KB)