urg_ctrl.h File Reference

#include "urg_t.h"

 



Enumerations

enum  { UrgLineWidth = 64 + 1 + 1, UrgInfinityTimes = 0 }
 Parameter for object. More...
enum  urg_request_type {
  URG_GD, URG_GD_INTENSITY, URG_GS, URG_MD,
  URG_MD_INTENSITY, URG_MS
}
 Command type of URG. More...
enum  { URG_FIRST = -1, URG_LAST = -1, UrgInvalidTimestamp = -1 }
 To omit URG data range specification. More...

Functions

int urg_connect (urg_t *urg, const char *device, long baudrate)
 Connection.
void urg_disconnect (urg_t *urg)
 Disconnection.
int urg_isConnected (urg_t *urg)
 Checks whether connected or not and returns the result.
const char * urg_error (urg_t *urg)
 Get error message.
int urg_versionLines (urg_t *urg, char *lines[], int lines_max)
 Get string containing version information.
int urg_parameters (urg_t *urg, urg_parameter_t *parameters)
 URG Returns parameter.
int urg_dataMax (urg_t *urg)
 Returns the number of maximum data obtained in one scan.
int urg_scanMsec (urg_t *urg)
 Returns measurement time taken for one scan.
long urg_maxDistance (urg_t *urg)
 Maximum measurable distance.
long urg_minDistance (urg_t *urg)
 Minimum measureable distance.
int urg_setSkipLines (urg_t *urg, int lines)
 Sets the number of lines to be skiped.
int urg_setSkipFrames (urg_t *urg, int frames)
 Sets number of scans to be skipped.
int urg_setCaptureTimes (urg_t *urg, int times)
 Sets number of times the data to be acquired .
int urg_remainCaptureTimes (urg_t *urg)
 MD/MS データ取得における残りスキャン数を取得.
int urg_requestData (urg_t *urg, urg_request_type request_type, int first_index, int last_index)
 Request for distance data.
int urg_receiveData (urg_t *urg, long data[], int data_max)
 Receive URG data.
int urg_receivePartialData (urg_t *urg, long data[], int data_max, int first_index, int last_index)
 Get partial URG data.
long urg_recentTimestamp (urg_t *urg)
 Receive time stamp.
double urg_index2rad (urg_t *urg, int index)
 Change index value into angle (radian).
int urg_index2deg (urg_t *urg, int index)
 Change index into angle(degree).
int urg_rad2index (urg_t *urg, double radian)
 Angle(radian) is converted to index value.
int urg_deg2index (urg_t *urg, int degree)
 Angle(degree) is converted into index.
int urg_laserOn (urg_t *urg)
 Directs laser to switch on.
int urg_laserOff (urg_t *urg)
 Directs laser to switch off.
int urg_enableTimestampMode (urg_t *urg)
 Enters into time stamp mode.
int urg_disableTimestampMode (urg_t *urg)
 Comes out of time stamp mode.
long urg_currentTimestamp (urg_t *urg)
 Get time stamp.

Detailed Description

URG control.

Author:
Satofumi KAMIMURA
Id
urg_ctrl.h 534 2009-02-01 15:48:15Z satofumi

Todo:
Define examples for each functions

Definition in file urg_ctrl.h.


Enumeration Type Documentation

anonymous enum

Parameter for object.

Enumerator:
UrgLineWidth  Maximum length of a line
UrgInfinityTimes  continuous data transmission

Definition at line 23 of file urg_ctrl.h.

Command type of URG.

Enumerator:
URG_GD  GD command
URG_GD_INTENSITY  GD command(Inclusing intensity data)
URG_GS  GS command
URG_MD  MD command
URG_MD_INTENSITY  MD command(Including intensity data)
URG_MS  MS command

Definition at line 32 of file urg_ctrl.h.

anonymous enum

To omit URG data range specification.

Enumerator:
URG_FIRST  starting position when complete data is to be acquired
URG_LAST  end position when complete data is to be acquired
UrgInvalidTimestamp  Error value of timestamp

Definition at line 45 of file urg_ctrl.h.


Function Documentation

int urg_connect ( urg_t urg,


const char *  device,


long  baudrate 

)


Connection.

Parameters:
[in,out] urg Structure of URG control
[in] device Connection device
[in] baudrate Baudrate
Return values:

0 Normal

<0 Error
See also:
gd_scan.c, md_scan.c
Usage example
urg_t urg;

// Coonnection
if (urg_connect(&urg, "COM3", 115200) < 0) {
printf("urg_connect: %s\n", urg_error(&urg));
return -1;
}

...

urg_disconnect(&urg);

Definition at line 120 of file urg_ctrl.c.

void urg_disconnect ( urg_t urg  ) 

Disconnection.

Parameters:
[in,out] urg Structure of URG control
See also:
urg_connect()

gd_scan.c, md_scan.c

Definition at line 158 of file urg_ctrl.c.

int urg_isConnected ( urg_t urg  ) 

Checks whether connected or not and returns the result.

Parameters:
[in,out] urg Structure of URG control
Return values:

0 if connected

<0 if disconnected
See also:
urg_connect(), urg_disconnect()
Usage example
if (urg_isConnected(&urg) < 0) {
printf("not connected.\n");
} else {
printf("connected.\n");
}

Definition at line 169 of file urg_ctrl.c.

const char* urg_error ( urg_t urg  ) 

Get error message.

Parameters:
[in,out] urg Structure of URG control
Returns:
Error message
See also:
urg_connect()

gd_scan.c, md_scan.c

Definition at line 176 of file urg_ctrl.c.

int urg_versionLines ( urg_t urg,


char *  lines[],


int  lines_max 

)


Get string containing version information.

Parameters:
[in,out] urg Structure of URG control
[out] lines Buffer having version information
[in] lines_max Maximum lines in buffer
Return values:

0 Normal

<0 Error
Attention:
The length of a line in the buffer should be equal to more than # UrgLineWidth[byte].
See also:
get_version_lines.c

Definition at line 182 of file urg_ctrl.c.

int urg_parameters ( urg_t urg,


urg_parameter_t parameters 

)


URG Returns parameter.

Parameters:
[in,out] urg Structure of URG control
[out] parameters Structure of URG parameter
Return values:

0 Normal

<0 Error
See also:
urg_maxDistance(), urg_minDistance(), urg_scanMsec(), urg_dataMax()

get_parameters.c

Execution example of get_parameters.c (Classic-URG)
% ./get_parameters
urg_getParameters: No Error.
distance_min: 20
distance_max: 5600
area_total: 1024
area_min: 44
area_max: 725
area_front: 384
scan_rpm: 600

urg_getDistanceMax(): 5600
urg_getDistanceMin(): 20
urg_getScanMsec(): 100
urg_getDataMax(): 726

Definition at line 189 of file urg_ctrl.c.

int urg_dataMax ( urg_t urg  ) 

Returns the number of maximum data obtained in one scan.

Parameters:
[in,out] urg Structure of URG control
Return values:

>=0 number of maximum data obtained in one scan

<0 Error
See also:
gd_scan.c
Usage example
enum { BufferSize = 2048 };
long data[BufferSize];

...

// Checks whether number of maximum data obtained by URG sensor does not exceeds receive buffer
// (This is not necessary if size of buffer is dynamically allocated.)
int data_max = urg_dataMax(&urg);
ASSERT(BufferSize >= data_max);

Definition at line 207 of file urg_ctrl.c.

int urg_scanMsec ( urg_t urg  ) 

Returns measurement time taken for one scan.

Returns measurement time when motor speed is 100% as specified.

Parameters:
[in,out] urg Structure of URG control
Return values:

>=0 measurement time taken for one scan [msec]

<0 Error
See also:
urg_setMotorSpeed()

md_scan.c

Definition at line 213 of file urg_ctrl.c.

long urg_maxDistance ( urg_t urg  ) 

Maximum measurable distance.

Parameters:
[in,out] urg Structure of URG control
Return values:

>=0 Maximum measurable distance [mm]

<0 Error
See also:
expand_2d.c
Usage example
...
n = urg_receiveData(&urg, data, data_max);

min_distance = urg_minDistance(&urg);
max_distance = urg_minDistance(&urg);

// Output only valid data
for (i = 0; i < n; ++i) {
long length = data[i];
if ((length > min_distance) && (length < max_distance)) {
printf("%d:%d\n", i, length);
}
}

Definition at line 220 of file urg_ctrl.c.

long urg_minDistance ( urg_t urg  ) 

Minimum measureable distance.

Parameters:
[in,out] urg Structure of URG control
Return values:

>=0 Minimum measurable distance [mm]

<0 Error
See also:
expand_2d.c

Definition at line 226 of file urg_ctrl.c.

int urg_setSkipLines ( urg_t urg,


int  lines 

)


Sets the number of lines to be skiped.

The volume of acquire data can be reduced by skipping the lines .

Parameters:
[in,out] urg Structure of URG control
[in] lines Number of lines to be skiped.
Return values:

0 Normal

< Error

Definition at line 232 of file urg_ctrl.c.

int urg_setSkipFrames ( urg_t urg,


int  frames 

)


Sets number of scans to be skipped.

Parameters:
[in,out] urg Structure of URG control
[in] frames Number of skipped frames.
Return values:

0 Normal

<0 Error
Attention:
Valid only with MD/MS command.

Definition at line 246 of file urg_ctrl.c.

int urg_setCaptureTimes ( urg_t urg,


int  times 

)


Sets number of times the data to be acquired .

Parameters:
[in,out] urg Structure of URG control
[in] times Number of scan data
Return values:

0 Normal

<0 Error
Attention:
Valid only with MD/MS command

Specify UrgInfinityTimes to acquire data more than 100 times

Usage example
// Data is supplied indefinitely
urg_setCaptureTimes(&urg, UrgInfinityTimes);

...

// Data acquistion is stopped if laser is switched off.
urg_laserOff(&urg);

Definition at line 255 of file urg_ctrl.c.

int urg_remainCaptureTimes ( urg_t urg  ) 

MD/MS データ取得における残りスキャン数を取得.

Parameters:
[in,out] urg Structure of URG control
Return values:

残りスキャン数。ただし、無限回のデータ取得のときは 100 を返す
See also:
md_scan.c

Definition at line 268 of file urg_ctrl.c.

int urg_requestData ( urg_t urg,


urg_request_type  request_type,


int  first_index,


int  last_index 

)


Request for distance data.

Request for distance data of [first_index, last_index].first_index, last_index にそれぞれ URG_FIRST, URG_LAST を指定することで、全範囲のデータ取得を行わせることができる。

Parameters:
[in,out] urg Structure of URG control
[in] request_type Received data type.
[in] first_index Index of the first data stored
[in] last_index Index of the last received data stored.
Return values:

0 Normal

<0 Error
See also:
urg_receiveData()

gd_scan.c, md_scan.c

Usage example
// Get one scan data from GD command
urg_requestData(&urg, URG_GD, URG_FIRST, URG_LAST);
n = urg_receiveData(&urg, data, data_max);

// Get data continuously from MD scan
urg_requestData(&urg, URG_MD, URG_FIRST, URG_LAST);
while (1) {
n = urg_receiveData(&urg, data, data_max);
if (n > 0) {
// Display data etc
...
}
}

Definition at line 280 of file urg_ctrl.c.

int urg_receiveData ( urg_t urg,


long  data[],


int  data_max 

)


Receive URG data.

Parameters:
[in,out] urg Structure of URG control
[out] data Storage location of received data
[in] data_max Maximum number of data that can be received
Return values:

0 > Number of data received

<0 Error
See also:
urg_requestData()

Definition at line 578 of file urg_ctrl.c.

int urg_receivePartialData ( urg_t urg,


long  data[],


int  data_max,


int  first_index,


int  last_index 

)


Get partial URG data.

Parameters:
[in,out] urg Structure of URG control
[out] data Storage location of received data
[in] data_max Maximum number of data that can be received
[in] first_index Index of the first data stored.
[in] last_index Index of the last data stored
Return values:

0 > Number of data received

<0 Error
Attention:
未実装
See also:
gd_scan.c, md_scan.c

Definition at line 608 of file urg_ctrl.c.

long urg_recentTimestamp ( urg_t urg  ) 

Receive time stamp.

Parameters:
[in,out] urg Structure of URG control
Return values:

Time stamp [msec]
See also:
md_scan.c
Usage example
urg_requestData(&urg, URG_GD, URG_FIRST, URG_LAST);
n = urg_receiveData(&urg, data, data_max);
if (n > 0) {
long timestamp = urg_recentTimestamp(&urg);
printf("timestamp: %d\n", timestamp);

// Display data etc
// !!!
}

Definition at line 615 of file urg_ctrl.c.

double urg_index2rad ( urg_t urg,


int  index 

)


Change index value into angle (radian).

urg_sensor_radian.png

Front of the sensor is a positive in X axis

Parameters:
[in,out] urg Structure of URG control
[in] index Index value
Returns:
angle[radian]
See also:
index_convert.c

Definition at line 622 of file urg_ctrl.c.

int urg_index2deg ( urg_t urg,


int  index 

)


Change index into angle(degree).

Parameters:
[in,out] urg Structure of URG control
[in] index Index value
Returns:
Angle [degree]
See also:
index_convert.c

Definition at line 631 of file urg_ctrl.c.

int urg_rad2index ( urg_t urg,


double  radian 

)


Angle(radian) is converted to index value.

urg_sensor_radian.png

Front of the sensor is a positive in X axis

Parameters:
[in,out] urg Structure of URG control
[in] Angle(radian) 
Returns:
Index
See also:
index_convert.c

Definition at line 639 of file urg_ctrl.c.

int urg_deg2index ( urg_t urg,


int  degree 

)


Angle(degree) is converted into index.

Parameters:
[in,out] urg Structure of URG control
[in] Angle(degre) 
Returns:
Index value
See also:
index_convert.c

Definition at line 654 of file urg_ctrl.c.

int urg_laserOn ( urg_t urg  ) 

Directs laser to switch on.

Parameters:
[in,out] urg Structure of URG control
Return values:

0 Normal

<0 Error
See also:
gd_scan.c

Definition at line 660 of file urg_ctrl.c.

int urg_laserOff ( urg_t urg  ) 

Directs laser to switch off.

Parameters:
[in,out] urg Structure of URG control
Return values:

0 Normal

<0 Error

Definition at line 677 of file urg_ctrl.c.

int urg_enableTimestampMode ( urg_t urg  ) 

Enters into time stamp mode.

Parameters:
[in,out] urg Structure of URG control
Return values:

0 Normal

<0 Error

Definition at line 684 of file urg_ctrl.c.

int urg_disableTimestampMode ( urg_t urg  ) 

Comes out of time stamp mode.

Parameters:
[in,out] urg Structure of URG control
Return values:

0 Normal

<0 Error

Definition at line 697 of file urg_ctrl.c.

long urg_currentTimestamp ( urg_t urg  ) 

Get time stamp.

Returns TM1 response.

Parameters:
[in,out] urg Structure of URG control
Return values:

>=0 Timestamp [msec]

<0 Error
Usage example
// Enters into time stamp
urg_enableTimestampMode(&urg);

// Get URG time stamp continuously.
for (i = 0; i < 5; ++i) {
long timestamp = urg_currentTimestamp(&urg);
printf("timestamp: %ld\n", timestamp)
}

// タイムスタンプモードから抜ける
urg_disableTimestampMode(&urg);

Definition at line 710 of file urg_ctrl.c.

Comments