I had a project in the works which seemed like it could help. About a year previously, I had picked up a 45A AttoPilot current and voltage sensor from Sparkfun. This simple sensor runs off the input power and has a three pin header for current, voltage and ground which can be sent to a microprocessor.
One of 2856's team members soldered anderson connectors for the input and output lines so that we could put the sensor between the battery and the robot. I also purchased an SD card shield for Arduino, wired the current, voltage and ground pins to the Arduino, and wrote a program to log data on the SD card.
The final steps were to hack a simple 3D printed box from Thingiverse (http://www.thingiverse.com/thing:18095) to include slots for the Anderson connectors, a hole for a switch, and a slot for the SD card (since my shield had it on the opposite side as this print). Finally, I made a small PCB with four diagnostic LEDs which tell us if a problem has occurred.
The pictures below show the finished product.
As you can see in the last picture, the four diagnostic LEDs include a power button, a toggling LED which shows when data is written to the SD card, an error light which illuminates if the program failed to detect the SD card, and an error light which illuminates if there is an error writing to the SD card. These LEDs are very useful, because without them it's impossible to tell whether you have successfully collected data before the SD card is plugged into a laptop.
Data is exported in CSV format in the form shown below.
dataString = String(millis());A data set is collected every second. The program is found here.
dataString += ", ";
dataString += String(VFinal);
dataString += ", ";
dataString += String(IFinal);
2856 made great use of the datalogger by designing a series of experiments which isolated specific systems on the robot and tested them for current draw. They found that the tank treads were the culprit, pulling upwards of 15Amps at times. This was sucking our 3000mA-hr battery dry very quickly. They reduced the friction in the tank treads and lowered the current draw.
In general, when we graph the data, we see that current and voltage are inversely related. Hence knowing having both is somewhat redundant, although its nice to see how much the voltage sags under load and to see how much current is being consumed. A little test robot pulled 3-5 A maximum, yet the voltage sometimes sagged from 12V all the way down to 6V. Probably a pretty old battery!
While having the data itself can be very powerful, I thought it would be interesting to go one step further and see if I could visualize the current and voltage in real time. I wrote a python program which plotted the data in real time on my computer screen. Script is here. The program uses matplotlib pyplot and animation. We read in a csv file stripped of time, with voltage in the first column and current in the second. Each column is saved as a different array (data[:,0] and data[:,1]). A new array is setup which is a hack to get the data to be shown at the correct rate. The total time which passed (found using timestamps from the Arduino data) is divided by the number of samples to find the sampling period. The new array is a simple arithmetic sequence with the same number of entries as the current data. Finally, some black magic plots current versus time. I borrowed widely from the internet and don't 100% understand how the script work.
The video linked below showed a recording on my computer screen as it plots the data. The quality sucks, but this was just a proof of concept.