Skip to content

Instantly share code, notes, and snippets.

@trecouvr
Created March 5, 2012 04:18
Show Gist options
  • Save trecouvr/1976603 to your computer and use it in GitHub Desktop.
Save trecouvr/1976603 to your computer and use it in GitHub Desktop.
test hokuyo
/*!
\file
\brief データ取得サンプル
\author Satofumi KAMIMURA
$Id: gdScanSample.cpp 1883 2010-08-20 04:12:36Z satofumi $
*/
#include "UrgCtrl.h"
#include <cstdlib>
#include <cstdio>
using namespace qrk;
using namespace std;
//! main
int main(int argc, char *argv[]) {
//const char device[] = "COM3"; /* Windows での例 */
const char device[] = "/dev/ttyACM0";
UrgCtrl urg;
if (! urg.connect(device)) {
printf("UrgCtrl::connect: %s\n", urg.what());
exit(1);
}
// データ取得
vector<long> data;
long timestamp = 0;
int n = urg.capture(data, &timestamp);
printf("n = %d\n", n);
if (n < 0) {
printf("UrgCtrl::capture: %s\n", urg.what());
exit(1);
}
printf("timestamp: %ld\n", timestamp);
for (int i = 0; i < n; ++i) {
printf("%ld, ", data[i]);
}
printf("\n");
return 0;
}
exe: src/main.cpp
g++ -o exe src/main.cpp -Wall -Werror `urg-config --cflags` `sdl-config --cflags` `urg-config --libs` `sdl-config --libs` -lc -lpthread
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment