Difference between revisions of "URG laser"
(→Usage) |
(→Running) |
||
(One intermediate revision by the same user not shown) | |||
Line 39: | Line 39: | ||
# | # | ||
</pre> | </pre> | ||
− | The URG laser is known as the /dev/ttyACM0 device. | + | The URG laser is known as the /dev/ttyACM0 serial device. |
==Code example== | ==Code example== | ||
Line 112: | Line 112: | ||
Copy your ''laser'' executable on your board through TFTP (for example) | Copy your ''laser'' executable on your board through TFTP (for example) | ||
− | * Be sure to have TFTP server installed, [[Connection_with_U-Boot_on_Linux#TFTP_server| if not it's explained here]]. Copy '' | + | * Be sure to have TFTP server installed, [[Connection_with_U-Boot_on_Linux#TFTP_server| if not it's explained here]]. Copy ''laser'' to your TFTP directory: |
<pre class="host"> | <pre class="host"> | ||
[demos]$ cp laser /tftpboot/ | [demos]$ cp laser /tftpboot/ |
Latest revision as of 20:27, 15 July 2010
How to drive Hoyuko's URG series laser sensors.
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 #
The URG laser is known as the /dev/ttyACM0 serial 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 laser.cpp.
Compilation
You can put your program compilation and installation in a Makefile to make things cleaner:
CXX=arm-linux-g++
EXEC=laser
SRC= $(wildcard *.cpp)
OBJ= $(SRC:.c=.o)
ARM_LIBS=$(ARMADEUS_STAGING_DIR)/usr/lib
URG_INCLUDE=$(ARMADEUS_STAGING_DIR)/usr/include/urg
LD_URG=-lurg_monitor -lurg -lurg_coordinate -lurg_geometry -lurg_connection -lurg_connection_sdl -lurg_common -lurg_system
SDL_INCLUDE=$(ARMADEUS_STAGING_DIR)/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
LD_SDL=-lSDL
LD_PTHREAD=-lpthread
LDFLAGS=
CXXFLAGS=-g -W -Wall -DNO_DETECT_OS_H
all: $(EXEC)
laser: laser.cpp
$(CXX) $(CXXFLAGS) -I$(URG_INCLUDE) -I$(SDL_INCLUDE) -o $@ $^ $(LDFLAGS) -L$(ARM_LIBS) $(LD_URG) $(LD_SDL) $(LD_PTHREAD)
.PHONY: clean install
clean:
rm -rf *.o
rm -f $(EXEC)
install: all
cp -f $(EXEC) /tftpboot/
!! If you do a cut & paste with previous commands, don't forget to check TABS for each target (Makefiles are using TABS and not SPACES) !! In that case make will complains about a missing separator line 11
Then, on host, just do:
[host ]$ make clean install
Running
Copy your laser executable on your board through TFTP (for example)
- Be sure to have TFTP server installed, if not it's explained here. Copy laser to your TFTP directory:
[demos]$ cp laser /tftpboot/
- Load your executable on the target (here my host IP is 192.168.1.13):
# tftp -g -r laser 192.168.1.13
- Give it executable rights, if lost during TFTP transfer:
# chmod a+x laser
- Launch it:
# ./laser timestamp: 624546 range at 0 degree : 1219 mm timestamp: 624646 range at 0 degree : 1217 mm timestamp: 624746 range at 0 degree : 1210 mm timestamp: 624846 range at 0 degree : 1213 mm timestamp: 624946 range at 0 degree : 1207 mm timestamp: 625046 range at 0 degree : 1213 mm timestamp: 625145 range at 0 degree : 1211 mm timestamp: 625245 range at 0 degree : 1220 mm timestamp: 625345 range at 0 degree : 1220 mm timestamp: 625445 range at 0 degree : 1205 mm timestamp: 625545 range at 0 degree : 1216 mm timestamp: 625645 range at 0 degree : 1214 mm timestamp: 625745 range at 0 degree : 1225 mm timestamp: 625845 range at 0 degree : 1217 mm timestamp: 625945 range at 0 degree : 1221 mm #
Now it's up to you ! ;-)