Difference between revisions of "URG laser"
From ArmadeusWiki
(→Usage) |
(→Code example) |
||
Line 41: | Line 41: | ||
==Code example== | ==Code example== | ||
+ | With your favorite editor/IDE, create the following program: | ||
+ | |||
+ | <source lang="cpp"> | ||
+ | #include <iostream> | ||
+ | #include "UrgCtrl.h" | ||
+ | using namespace std; | ||
+ | using namespace qrk; | ||
+ | |||
+ | int main() { | ||
+ | |||
+ | const char device[] = "/dev/ttyACM0"; | ||
+ | UrgCtrl urg; | ||
+ | if (! urg.connect(device)) { | ||
+ | cout << "UrgCtrl::connect: " << urg.what() << endl; | ||
+ | exit(1); | ||
+ | } | ||
+ | vector<long> data; | ||
+ | long timestamp = 0; | ||
+ | while (1) | ||
+ | { | ||
+ | int n = urg.capture(data, ×tamp); | ||
+ | if (n < 0) { | ||
+ | cout << "UrgCtrl::capture: " << urg.what() << endl; | ||
+ | exit(1); | ||
+ | } | ||
+ | cout << "timestamp: " << timestamp << "\t range at 0 degree : " << data[n/2] << " mm" <<endl; | ||
+ | } | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </source> | ||
+ | Save it as ''hello.cpp'' | ||
==Links== | ==Links== |
Revision as of 20:16, 15 July 2010
How to drive Hoyuko's URG series laser sensors.
Contents
Installation
$ make menuconfig
Package Selection for the target ---> Hardware handling / blockdevices and filesystem maintenance ---> [*] urg library
$ make
- reflash rootfs
Usage
To use Hokoyu URG laser, you need Prolific pl2303 USB to serial adapter ( see here to install pl2303).
Load the module and connect the URG laser to APF27 dev USB port. You should see something like this :
# modprobe pl2303 usbcore: registered new interface driver usbserial usbserial: USB Serial Driver core USB Serial support registered for pl2303 usbcore: registered new interface driver pl2303 pl2303: Prolific PL2303 USB to serial adaptor driver # usb 2-1: new full speed USB device using mxc-ehci and address 3 usb 2-1: device descriptor read/64, error -71 usb 2-1: New USB device found, idVendor=15d1, idProduct=0000 usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0 usb 2-1: Product: URG-Series USB Driver usb 2-1: Manufacturer: Hokuyo Data Flex for USB usb 2-1: configuration #1 chosen from 1 choice cdc_acm 2-1:1.0: ttyACM0: USB ACM device #
Code example
With your favorite editor/IDE, create the following program:
#include <iostream>
#include "UrgCtrl.h"
using namespace std;
using namespace qrk;
int main() {
const char device[] = "/dev/ttyACM0";
UrgCtrl urg;
if (! urg.connect(device)) {
cout << "UrgCtrl::connect: " << urg.what() << endl;
exit(1);
}
vector<long> data;
long timestamp = 0;
while (1)
{
int n = urg.capture(data, ×tamp);
if (n < 0) {
cout << "UrgCtrl::capture: " << urg.what() << endl;
exit(1);
}
cout << "timestamp: " << timestamp << "\t range at 0 degree : " << data[n/2] << " mm" <<endl;
}
return 0;
}
Save it as hello.cpp