kb_lrf.c File Reference

This module provides useful basic facilities to use the KoreBot with the LedRangeFinder card. More...

Include dependency graph for kb_lrf.c:

Go to the source code of this file.

Data Structures

struct  urg_state_t

Defines

#define GPIO_POWER   16
#define BAUDRATE   19200

Enumerations

enum  { Timeout = 800, LineLength = 16 + 64 + 1 + 1 + 1 }

Functions

static int com_connect (const char *device, long baudrate)
static int com_send (const char *data, int size)
static int com_recv (char *data, int max_size, int timeout)
static int urg_sendTag (const char *tag)
static int urg_readLine (char *buffer)
static int urg_sendMessage (const char *command, int timeout, int *recv_n)
static int urg_getParameters (urg_state_t *state)
static int urg_connect (urg_state_t *state, const char *port, const long baudrate)
static int urg_captureByGD (const urg_state_t *state)
static int urg_captureByMD (const urg_state_t *state, int capture_times)
static long urg_decode (const char *data, int data_byte)
static int urg_addRecvData (const char buffer[], long data[], int *filled)
static int urg_receiveData (urg_state_t *state, long data[], size_t max_size)
long kb_lrf_Get_Timestamp (void)
void kb_lrf_Laser_On (int LRF_DeviceHandle)
void kb_lrf_Laser_Off (int LRF_DeviceHandle)
void kb_lrf_Power_On (void)
void kb_lrf_Power_Off (void)
int kb_lrf_Init (char *LRF_DeviceName)
void kb_lrf_Close (int LRF_DeviceHandle)
int kb_lrf_GetDistances (int LRF_DeviceHandle)
int kb_lrf_GetDistances_Averaged (int LRF_DeviceHandle, int average)

Variables

static int HComm = -1
static char * ErrorMessage = "no error."
urg_state_t urg_state
long kb_lrf_DistanceData [LRF_DATA_NB]
long kb_lrf_DistanceDataSensor [LRF_DATA_NB]
long kb_lrf_DistanceDataSum [LRF_DATA_NB]
int kb_lrf_DistanceGoodCounter [LRF_DATA_NB]

Detailed Description

This module provides useful basic facilities to use the KoreBot with the LedRangeFinder card.

Support for KoreBot Led Range Finder.

Author:
Arnaud Maye (K-Team SA), 2011.10.31 J. Tharin : added support for LRF Hokuyo URG-04LX-UG01
Note:
Copyright (C) 2011 K-TEAM SA
Bug:
none discovered.
Todo:

Definition in file kb_lrf.c.


Define Documentation

#define BAUDRATE   19200

Definition at line 38 of file kb_lrf.c.

Referenced by kb_lrf_Init(), and main().

#define GPIO_POWER   16

Definition at line 36 of file kb_lrf.c.

Referenced by kb_lrf_Power_Off(), and kb_lrf_Power_On().


Enumeration Type Documentation

anonymous enum
Enumerator:
Timeout 
LineLength 

Definition at line 30 of file kb_lrf.c.


Function Documentation

static int com_connect ( const char *  device,
long  baudrate 
) [static]

Definition at line 95 of file kb_lrf.c.

References HComm, and Timeout.

Referenced by urg_connect().

static int com_recv ( char *  data,
int  max_size,
int  timeout 
) [static]

receive data from serial port

Parameters:
data data to be sent to the port
max_size max size of the data variable
timeout timeout in [ms]
Returns:
number of data read

Definition at line 155 of file kb_lrf.c.

References HComm.

Referenced by urg_sendMessage().

static int com_send ( const char *  data,
int  size 
) [static]

write to serial port

Parameters:
data data to be sent to the port
size size of the data \

Definition at line 136 of file kb_lrf.c.

References HComm.

Referenced by urg_sendTag().

void kb_lrf_Close ( int  LRF_DeviceHandle  ) 

kb_lrf_Close does powering off the LRF, the close the port device

Parameters:
LRF_DeviceHandle Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init

Definition at line 737 of file kb_lrf.c.

References kb_lrf_Laser_Off().

Referenced by ctrlc_handler(), handle_kill(), main(), and poweroff().

Here is the call graph for this function:

long kb_lrf_Get_Timestamp ( void   ) 

kb_lrf_get_timestamp : get the last timestep in [ms]

Returns:
the timestamp of last set of data

Definition at line 628 of file kb_lrf.c.

References urg_state_t::last_timestamp.

Referenced by lrfmeasure().

int kb_lrf_GetDistances ( int  LRF_DeviceHandle  ) 

kb_lrf_GetDistances is a high level function that does whole mechanism certify the link, get some distances.

Parameters:
LRF_DeviceHandle Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init
Returns:
  • 0 : Sucess
  • -1 : serial port not open
  • -2 : could not send command capture
    • -3 : could not received data

Definition at line 761 of file kb_lrf.c.

References kb_lrf_DistanceData, LRF_DATA_NB, urg_captureByMD(), and urg_receiveData().

Referenced by kb_lrf_GetDistances_Averaged(), koa_lrf_task(), lrfmeasure(), and main().

Here is the call graph for this function:

int kb_lrf_GetDistances_Averaged ( int  LRF_DeviceHandle,
int  average 
)

kb_lrf_GetDistances is a high level function that does whole mechanism certify the link, get some distances, averages then receive back the data from LRF,

Parameters:
LRF_DeviceHandle Handle to the lrf port which as been openned by kb_lrf_openComPort or kb_lrf_init
average number of acquisitions needed for averaging
Returns:
  • 0 : Sucess
  • -1 : serial port not open
  • -2 : could not send command capture
    • -3 : could not received data

Definition at line 797 of file kb_lrf.c.

References kb_lrf_DistanceData, kb_lrf_DistanceDataSum, kb_lrf_DistanceGoodCounter, kb_lrf_GetDistances(), and LRF_DATA_NB.

Referenced by lrfmeasure().

Here is the call graph for this function:

int kb_lrf_Init ( char *  LRF_DeviceName  ) 

kb_lrf_Init does openning port, turn power on the LRF then certify the link,

Parameters:
LRF_DeviceName String name of the serial port device where the laser is connected
Returns:
- < 0 : Any error code
  • > 0 : Handle to the device

Definition at line 701 of file kb_lrf.c.

References BAUDRATE, ErrorMessage, HComm, KB_ERROR, KB_ERROR_OPENLRF, kb_lrf_Laser_On(), and urg_connect().

Referenced by koa_lrf_task(), lrfinit(), and main().

Here is the call graph for this function:

void kb_lrf_Laser_Off ( int  LRF_DeviceHandle  ) 

kb_lrf_Laser_Off : set LRF laser beam OFF

Definition at line 652 of file kb_lrf.c.

References Timeout, and urg_sendMessage().

Referenced by kb_lrf_Close(), laseroff(), and poweroff().

Here is the call graph for this function:

void kb_lrf_Laser_On ( int  LRF_DeviceHandle  ) 

kb_lrf_Laser_On : set LRF laser beam ON

Definition at line 639 of file kb_lrf.c.

References Timeout, and urg_sendMessage().

Referenced by kb_lrf_Init(), and laseron().

Here is the call graph for this function:

void kb_lrf_Power_Off ( void   ) 

kb_lrf_Power_Off : power off the LRF battery supply module

Definition at line 682 of file kb_lrf.c.

References GPIO_POWER, kb_gpio_cleanup(), kb_gpio_clear(), kb_gpio_dir(), kb_gpio_function(), and kb_gpio_init().

Referenced by poweroff().

Here is the call graph for this function:

void kb_lrf_Power_On ( void   ) 

kb_lrf_Power_On : power on the LRF battery supply module

Definition at line 665 of file kb_lrf.c.

References GPIO_POWER, kb_gpio_cleanup(), kb_gpio_dir(), kb_gpio_function(), kb_gpio_init(), and kb_gpio_set().

Referenced by main(), and poweron().

Here is the call graph for this function:

static int urg_addRecvData ( const char  buffer[],
long  data[],
int *  filled 
) [static]

Receive and decode URG distance data

Parameters:
buffer buffer
data array of long containing the measurement values
filled ?
Returns:
0 no error

Definition at line 509 of file kb_lrf.c.

References urg_decode().

Referenced by urg_receiveData().

Here is the call graph for this function:

static int urg_captureByGD ( const urg_state_t state  )  [static]

Data read using GD-Command : read lastest measurement; sensor should be switched on before.

Parameters:
state parameters of the current LRF laser
Returns:
0 : OK ; <0 error

Definition at line 453 of file kb_lrf.c.

References urg_state_t::first, urg_state_t::last, LineLength, and urg_sendTag().

Here is the call graph for this function:

static int urg_captureByMD ( const urg_state_t state,
int  capture_times 
) [static]

Data read using MD-Command: captures number of scans defined by capture_times (0 = infinite) Laser is switched on and off automatically.

Parameters:
state parameters of the current LRF laser
capture_times number of times scans should be captured
Returns:
0 : OK ; <0 error

Definition at line 471 of file kb_lrf.c.

References urg_state_t::first, urg_state_t::last, LineLength, and urg_sendTag().

Referenced by kb_lrf_GetDistances().

Here is the call graph for this function:

static int urg_connect ( urg_state_t state,
const char *  port,
const long  baudrate 
) [static]

Process to connect with URG

Parameters:
state parameters of the current LRF laser
port serial port device
baudrate baudrate
Returns:
0: no error -1: cannot open serial port -2: cannot switch to SCIP2.0 communication protocol -3: get parameters failed

Definition at line 394 of file kb_lrf.c.

References com_connect(), ErrorMessage, HComm, urg_state_t::last_timestamp, Timeout, urg_getParameters(), and urg_sendMessage().

Referenced by kb_lrf_Init().

Here is the call graph for this function:

static long urg_decode ( const char *  data,
int  data_byte 
) [static]

Decode 6 bit data from URG

Parameters:
data data
data_byte size of data
Returns:
decoded value

Definition at line 489 of file kb_lrf.c.

Referenced by urg_addRecvData(), and urg_receiveData().

static int urg_getParameters ( urg_state_t state  )  [static]

Read URG parameters

Parameters:
state parameters of the current LRF laser
Returns:
0 if OK, <0 if an error occured

Definition at line 320 of file kb_lrf.c.

References urg_state_t::area_front, urg_state_t::area_max, urg_state_t::area_min, urg_state_t::area_total, urg_state_t::distance_max, urg_state_t::distance_min, urg_state_t::first, urg_state_t::last, LineLength, urg_state_t::max_size, urg_state_t::model, urg_state_t::scan_rpm, urg_readLine(), and urg_sendTag().

Referenced by urg_connect().

Here is the call graph for this function:

static int urg_readLine ( char *  buffer  )  [static]

Definition at line 248 of file kb_lrf.c.

Referenced by urg_getParameters(), and urg_receiveData().

static int urg_receiveData ( urg_state_t state,
long  data[],
size_t  max_size 
) [static]

Receive URG data

Parameters:
state state variable of the parameters of the laser
data array of long containing the measurement values
max_size maximum size of the array (can be determinated by urg_state.max_size )
Returns:
an error code

Definition at line 550 of file kb_lrf.c.

References urg_state_t::last_timestamp, LineLength, urg_addRecvData(), urg_decode(), and urg_readLine().

Referenced by kb_lrf_GetDistances().

Here is the call graph for this function:

static int urg_sendMessage ( const char *  command,
int  timeout,
int *  recv_n 
) [static]

Send data (Commands) to URG and wait for reply

Parameters:
command command to be sent
timeout for waiting the data back (ack)
recv_n number of bytes received
Returns:
return received data in hexa or -1 : received data size does not match -2 : command does not match

Definition at line 282 of file kb_lrf.c.

References com_recv(), LineLength, and urg_sendTag().

Referenced by kb_lrf_Laser_Off(), kb_lrf_Laser_On(), and urg_connect().

Here is the call graph for this function:

static int urg_sendTag ( const char *  tag  )  [static]

Send data(Commands) to URG

Parameters:
tag command to be sent
Returns:
size of the message sent

Definition at line 230 of file kb_lrf.c.

References com_send(), and LineLength.

Referenced by urg_captureByGD(), urg_captureByMD(), urg_getParameters(), and urg_sendMessage().

Here is the call graph for this function:


Variable Documentation

char* ErrorMessage = "no error." [static]

Definition at line 42 of file kb_lrf.c.

Referenced by kb_lrf_Init(), and urg_connect().

int HComm = -1 [static]

Definition at line 40 of file kb_lrf.c.

Referenced by com_connect(), com_recv(), com_send(), kb_lrf_Init(), and urg_connect().

long kb_lrf_DistanceData[LRF_DATA_NB]
long kb_lrf_DistanceDataSensor[LRF_DATA_NB]

Definition at line 80 of file kb_lrf.c.

long kb_lrf_DistanceDataSum[LRF_DATA_NB]

Definition at line 81 of file kb_lrf.c.

Referenced by kb_lrf_GetDistances_Averaged().

int kb_lrf_DistanceGoodCounter[LRF_DATA_NB]

Definition at line 82 of file kb_lrf.c.

Referenced by kb_lrf_GetDistances_Averaged().

Definition at line 75 of file kb_lrf.c.

Generated on Mon Dec 3 09:43:48 2012 for KoreBot Library by  doxygen 1.6.3