// // Filtering example for the Crandun Technologies CTI-AR4000 // software library. // Copyright (c) 2001, Crandun Technologies Inc. // // This example demonstrates how to use the library's filtering // functions to exclude samples that are not of interest. // In this particular example, filtering is done based on the sample's // range (distance). However, samples may also be filtered based // on numerous other criteria. (Please see the Programmers Guide.) // #include "CTI_AR4000.h" // required header #include // needed for cout, cerr, cin #include // needed for Sleep function using namespace std; // we use cout, cerr and cin using namespace Crandun; // all library symbols are in this namespace // A helper macro for checking return codes #define CHK_RETURN_VALUE(retCode, fnName) \ if (retCode < 0) { \ cerr << "ERROR: " #fnName " returned error code: " << rc << endl; \ my_Sensor.setCommClosed(); \ cerr << "Please enter any character to exit: "; \ cin >> c; \ return (-1); \ } int main() { char c; long rc; const int MAXSAMPLES = 100; float rangeData[MAXSAMPLES]; CTI_AR4000 my_Sensor; cout << "Crandun Technologies CTI-AR4000 Library data filtering example." << endl << endl; rc = my_Sensor.setCommOpen("COM1:", 9600); if (rc != CTI_SUCCESS) { cerr << "ERROR: setCommParams returned error: " << rc << endl; cerr << "Please enter any character to exit: "; cin >> c; return -1; } cout << "Successfully opened the serial port!" << endl; cout << "Setting maximum valid range to 4 feet." << endl; rc = my_Sensor.setMaxValidRange(48.0); CHK_RETURN_VALUE(rc, setMaxValidRange); cout << "Setting minimum valid range to 2 feet." << endl; rc = my_Sensor.setMinValidRange(24.0); CHK_RETURN_VALUE(rc, setMinValidRange); cout << "Telling library to discard invalid samples." << endl << endl; rc = my_Sensor.setDiscardInvalidOn(); // always returns CTI_SUCCESS, so don't need to check return code cout << "Approximately 10 seconds of data will now be captured." << endl; cout << "Please move the sensor slowly, so that it reflects off a wide range of" << endl; cout << "targets, from less than 2 feet in distance to more than 4 feet in distance." << endl; cout << endl; cout << "Please enter any character to continue: "; cin >> c; rc = my_Sensor.setClearBuffer(); // purge anything currently in buffer (always returns success) cout << "Sleeping for 10 seconds - please slowly move the sensor." << endl; Sleep(10000); // Sensor sample rate is factory default of 5 samples/second, so the // number of possible samples is about 50. // However, some should be filtered by the library, so we should get somewhat // less than 50 returned. rc = my_Sensor.getSamples(rangeData, MAXSAMPLES, 1); CHK_RETURN_VALUE(rc, getSamples); cout << "Read " << rc << " range samples from the sensor." << endl; for (int i = 0; i < rc; i++) cout << "Range " << i << " is " << rangeData[i] << endl; cout << my_Sensor.getNumBytesSkipped() << " bytes of data were skipped." << endl; my_Sensor.setCommClosed(); cout << "Please enter any character to exit: "; cin >> c; return 0; }