// // Filtering example for the Crandun Technologies CTI-HSIF // 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_HSIF.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 CTI 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 = 5000; HSIF_DATA_PT rangeData[MAXSAMPLES]; CTI_HSIF my_Sensor; cout << "Crandun Technologies CTI-HSIF Library data filtering example." << endl << endl; // Set board I/O address and interrupt number (0=don't use interrupts) rc = my_Sensor.setBoardParams("100", 0); if (rc != CTI_SUCCESS) { cerr << "ERROR: setBoardParams returned error: " << rc << endl; cerr << "Enter any character to exit: "; cin >> c; return -1; } // Set calibration data file to use. MUST match the actual sensor used rc = my_Sensor.setCalibrationFile("C:\\lookuphs"); if (rc != CTI_SUCCESS) { cerr << "ERROR: setCalibrationFile returned error: " << rc << endl; cerr << "Enter any character to exit: "; cin >> c; return -1; } // Open communications to the serial port and high-speed interface cout << "Opening the serial port..." << endl; rc = my_Sensor.setCommOpen("COM1:", 9600); if (rc != CTI_SUCCESS) { cerr << "ERROR: setCommOpen returned error: " << rc << endl; cerr << "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; my_Sensor.setDiscardInvalidOn(); // always returns CTI_SUCCESS, so don't need to check return code // Set a slower sample rate (must change max range to do this - see the Acuity HW manual) cout << "Setting sensor max range and sample rate." << endl << endl; rc = my_Sensor.setSensorMaxRange(9950); CHK_RETURN_VALUE(rc, setSensorMaxRange); rc = my_Sensor.setSamplesPerSec(50); CHK_RETURN_VALUE(rc, setSamplesPerSec); 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; my_Sensor.setResetHSIFBoard(); // always returns success 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 at 50 samples/second, so the // number of possible samples over 10 seconds is about 500. // However, some should be filtered by the library, so we // should get somewhat less than 500 returned. rc = my_Sensor.getSamples(rangeData, MAXSAMPLES, 1, 12000); CHK_RETURN_VALUE(rc, getSamples); my_Sensor.setCommClosed(); cout << "Read " << rc << " range samples from the sensor." << endl; cout << "Please enter any character to exit: "; cin >> c; return 0; }