Go to the documentation of this file.00001
00010 #include "UrgDevice.h"
00011 #include "Thread.h"
00012 #include "delay.h"
00013 #include <cstdlib>
00014 #include <cstdio>
00015
00016 using namespace qrk;
00017 using namespace std;
00018
00019
00020 static int thread_function(void* args)
00021 {
00022 UrgDevice urg;
00023
00024 const char* device = static_cast<const char*>(args);
00025 if (! urg.connect(device)) {
00026 printf("UrgDevice::connect: %s\n", urg.what());
00027 exit(1);
00028 }
00029
00030 enum { CaptureTimes = 10 };
00031 vector<long> data;
00032 for (int i = 0; i < CaptureTimes; ++i) {
00033 data.clear();
00034 if (urg.capture(data)) {
00035 printf("%s: n = %d\n", device, data.size());
00036 }
00037 delay(1);
00038 }
00039
00040 return 0;
00041 }
00042
00043
00044 int main(int argc, char *argv[])
00045 {
00046 const char *devices[] = {
00047 "/dev/ttyACM0",
00048 "/dev/ttyACM1",
00049 };
00050
00051 Thread *threads[2];
00052 for (int i = 0; i < 2; ++i) {
00053 threads[i] = new Thread(thread_function, const_cast<char *>(devices[i]));
00054 threads[i]->run();
00055 }
00056
00057 for (int i = 0; i < 2; ++i) {
00058 threads[i]->wait();
00059 }
00060
00061 return 0;
00062 }