View Single Post
  #4   Spotlight this post!  
Unread 20-02-2012, 22:18
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Camera Tracking Delay

Cutting the resolution to 320x240 should cut the processing time by at least 75%.

Printfs generally aren't so much a bottleneck, as the output is buffered. What'll cause a much bigger slowdown are memory allocations. Make sure you're not copying around gigantic vectors of particle reports (use a const reference/pointer) or a bunch of separate copies of the image.

A FLOP (Floating Point Operation) is also pretty slow on the cRIO, which makes triginometric or exponential calculations pretty slow. So if you find yourself calling std::sin or std:ow a lot, you might see a slowdown.

Most of the speedup you can get though is by decreasing the resolution and making sure your thresholds don't generate a lot of false positives though.

If you want to get rid of the printfs though, one of the best things to do is to make a macro:

Code:
//in "someglobalincludefile.h"
#define DEBUG_FLAG
//change to whatever you like/already have -- comment out to disable
#define STRINGIFY(sym) #sym
//puts quotes around sym

//in a .h file
#include "someglobalincludefile.h"
void print_debug_impl(const char*, const char*);

#ifdef DEBUG_FLAG
#define print_debug(str) print_debug_impl("DEBUG>" __FILE__ "@" STRINGIFY(__LINE__) ": ", str)
#else
//will be disabled
#define print_debug(str) static_cast<void>(0)
#endif

//in a .cpp file
#include <cstdio>
void print_debug_impl(const char * location, const char * message) {
   std::puts(location);
   std::puts(message);
   //or, if you have many threads and don't want them separated, replace with:
   //std::printf("%s%s", location, message);
   //but may be slower
}

//then anywhere else
print_debug_info("Error finding XYZ\n");
Output looks like:
DEBUG>somefile.cpp@123: Error finding XYZ

Might be a small error; don't have the compiler in front of me right now
Reply With Quote