Friday, April 22, 2016

In-Situ Datalogger for Robots

FTC Team 2856, Tesseract, is one of the robotics teams that I mentor.  As they were preparing for Superregionals this past March, they noticed that they were draining batteries extremely quickly.  The would run maybe two matches on a single battery and then notice that the robot could barely function.

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 ( 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());
dataString += ", ";
dataString += String(VFinal);
dataString += ", ";
dataString += String(IFinal);
 A data set is collected every second.  The program is found here.

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.

Finally, a friend and coworker made a movie showing the robot moving at the same time as the data is being plotted.  The two are close to, but not exactly lined up.  Still, it's obvious that as the robot executes certain motions, the current spikes.  When the robot stops, current drops to zero.  Current jumps drastically as the robot starts from a stop. It stays at a medium value when the robot is stuck (eg running into the wall at 0.42 or stuck on a ball at 0.27).  By the ending the plot is delayed by at least a couple seconds compared with the robot motion.  So as a real tool, it would require much better syncing.

No comments:

Post a Comment