URG laser

From ArmadeusWiki
Revision as of 21:19, 15 July 2010 by OlivierR (Talk | contribs) (Code example)

Jump to: navigation, search

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
# 

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, &timestamp);
		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. 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) /var/lib/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 hots, just do:

[host demos]$ make clean install

Links