All Classes Namespaces Files Functions Variables Enumerations Enumerator
Enumerations | Functions
libs/range_sensor/c/urg_ctrl.c File Reference

URG control. More...

#include "math_utils.h"
#include "urg_ctrl.h"
#include "scip_handler.h"
#include "urg_errno.h"
#include "serial_ctrl.h"
#include "serial_utils.h"
#include "serial_errno.h"
#include "urg_ticks.h"
#include "urg_delay.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Include dependency graph for urg_ctrl.c:

Go to the source code of this file.

Enumerations

enum  { ScipTimeout = 1000, EachTimeout = 100 * 2, InvalidRange = -1 }

Functions

void urg_initialize (urg_t *urg)
int urg_connect (urg_t *urg, const char *device, long baudrate)
 Connection.
void urg_disconnect (urg_t *urg)
 Disconnection.
int urg_isConnected (const urg_t *urg)
 Checks whether connected or not and returns the result.
const char * urg_error (const 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.
const char * urg_model (const urg_t *urg)
 URG Returns the sensor type.
int urg_dataMax (const urg_t *urg)
 Returns the number of maximum data obtained in one scan.
int urg_scanMsec (const urg_t *urg)
 Returns measurement time taken for one scan.
long urg_maxDistance (const urg_t *urg)
 Maximum measurable distance.
long urg_minDistance (const 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 (const urg_t *urg)
 Get number of remaining times on MD/MS capture.
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_receiveDataWithIntensity (urg_t *urg, long data[], int data_max, long intensity[])
 Get data with intensity.
int urg_receivePartialData (urg_t *urg, long data[], int data_max, int first_index, int last_index)
 Get partial URG data.
long urg_recentTimestamp (const urg_t *urg)
 Receive time stamp.
double urg_index2rad (const urg_t *urg, int index)
 Change index value into angle (radian)
int urg_index2deg (const urg_t *urg, int index)
 Change index into angle(degree)
int urg_rad2index (const urg_t *urg, double radian)
 Angle(radian) is converted to index value.
int urg_deg2index (const 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_reboot (urg_t *urg)
 reboot
int urg_reset (urg_t *urg)
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.c 1950 2011-05-07 08:18:39Z satofumi

Definition in file urg_ctrl.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
ScipTimeout 

[msec]

EachTimeout 

URG series timeout x 2 [msec]

Definition at line 28 of file urg_ctrl.c.


Function Documentation

int urg_connect ( urg_t urg,
const char *  device,
long  baudrate 
)

Connection.

Parameters:
[in,out]urgStructure of URG control
[in]deviceConnection device
[in]baudrateBaudrate
Return values:
0Normal
<0Error
See also:
gd_scan.c, md_scan.c

Example Example 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); 
Examples:
capture_sample.c, check_performance.c, convert_2d.c, evaluate_timestamp.c, gd_scan.c, get_parameters.c, get_timestamp.c, get_version_lines.c, index_convert.c, infinity_scan.c, intensity_sample.c, md_scan.c, multi_urg.c, and partial_scan.c.

Definition at line 138 of file urg_ctrl.c.

void urg_disconnect ( urg_t urg)
int urg_isConnected ( const urg_t urg)

Checks whether connected or not and returns the result.

Parameters:
[in,out]urgStructure of URG control
Return values:
0if connected
<0if disconnected
See also:
urg_connect(), urg_disconnect()

Example Example Example

if (urg_isConnected(&urg) < 0) {
  printf("not connected.\n");
} else {
  printf("connected.\n");
} 

Definition at line 189 of file urg_ctrl.c.

const char* urg_error ( const urg_t urg)

Get error message.

Parameters:
[in,out]urgStructure of URG control
Returns:
Error message
See also:
urg_connect()
gd_scan.c, md_scan.c
Examples:
capture_sample.c, check_performance.c, convert_2d.c, evaluate_timestamp.c, gd_scan.c, get_parameters.c, get_timestamp.c, get_version_lines.c, index_convert.c, infinity_scan.c, intensity_sample.c, md_scan.c, multi_urg.c, and partial_scan.c.

Definition at line 196 of file urg_ctrl.c.

int urg_versionLines ( urg_t urg,
char *  lines[],
int  lines_max 
)

Get string containing version information.

Parameters:
[in,out]urgStructure of URG control
[out]linesBuffer having version information
[in]lines_maxMaximum lines in buffer
Return values:
0Normal
<0Error
Attention:
The length of a line in the buffer should be equal to more than # UrgLineWidth[byte].
See also:
get_version_lines.c
Examples:
get_version_lines.c.

Definition at line 202 of file urg_ctrl.c.

int urg_parameters ( urg_t urg,
urg_parameter_t parameters 
)

URG Returns parameter.

Parameters:
[in,out]urgStructure of URG control
[out]parametersStructure of URG parameter
Return values:
0Normal
<0Error
See also:
urg_maxDistance(), urg_minDistance(), urg_scanMsec(), urg_dataMax()

Execution example of get_parameters.c (URG-04LX) Execution example of get_parameters.c (URG-04LX) Execution example of get_parameters.c (URG-04LX)

% ./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 
Examples:
capture_sample.c, evaluate_timestamp.c, get_parameters.c, infinity_scan.c, intensity_sample.c, md_scan.c, and partial_scan.c.

Definition at line 212 of file urg_ctrl.c.

const char* urg_model ( const urg_t urg)

URG Returns the sensor type.

Parameters:
[in,out]urgStructure of URG control
Return values:
URGsensor type
printf("URG type: %s\n", urg_model(&urg)); 
Examples:
intensity_sample.c.

Definition at line 228 of file urg_ctrl.c.

int urg_dataMax ( const urg_t urg)

Returns the number of maximum data obtained in one scan.

Parameters:
[in,out]urgStructure of URG control
Return values:
>=0number of maximum data obtained in one scan
<0Error
See also:
gd_scan.c

Example Example 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);
Examples:
capture_sample.c, convert_2d.c, evaluate_timestamp.c, gd_scan.c, get_parameters.c, index_convert.c, infinity_scan.c, intensity_sample.c, md_scan.c, and multi_urg.c.

Definition at line 234 of file urg_ctrl.c.

int urg_scanMsec ( const urg_t urg)

Returns measurement time taken for one scan.

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

Parameters:
[in,out]urgStructure of URG control
Return values:
>=0measurement time taken for one scan [msec]
<0Error
See also:
urg_setMotorSpeed()
md_scan.c
Examples:
get_parameters.c.

Definition at line 240 of file urg_ctrl.c.

long urg_maxDistance ( const urg_t urg)

Maximum measurable distance.

Parameters:
[in,out]urgStructure of URG control
Return values:
>=0Maximum measurable distance [mm]
<0Error
See also:
expand_2d.c

Example Example Example

...
n = urg_receiveData(&urg, data, data_max);

min_distance = urg_minDistance(&urg);
max_distance = urg_maxDistance(&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);
  }
}
Examples:
convert_2d.c, and get_parameters.c.

Definition at line 247 of file urg_ctrl.c.

long urg_minDistance ( const urg_t urg)

Minimum measureable distance.

Parameters:
[in,out]urgStructure of URG control
Return values:
>=0Minimum measurable distance [mm]
<0Error
See also:
expand_2d.c
Examples:
convert_2d.c, and get_parameters.c.

Definition at line 253 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]urgStructure of URG control
[in]linesNumber of lines to be skiped.
Return values:
0Normal
<0Error
Examples:
check_performance.c.

Definition at line 259 of file urg_ctrl.c.

int urg_setSkipFrames ( urg_t urg,
int  frames 
)

Sets number of scans to be skipped.

Parameters:
[in,out]urgStructure of URG control
[in]framesNumber of skipped frames.
Return values:
0Normal
<0Error
Attention:
Valid only with MD/MS command.
Examples:
check_performance.c.

Definition at line 274 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]urgStructure of URG control
[in]timesNumber of scan data
Return values:
0Normal
<0Error
Attention:
Valid only with MD/MS command
Specify UrgInfinityTimes to acquire data more than 100 times

Example Example Example

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

...

// Data acquistion is stopped if laser is switched off.
urg_laserOff(&urg);
Examples:
capture_sample.c, evaluate_timestamp.c, intensity_sample.c, md_scan.c, and multi_urg.c.

Definition at line 286 of file urg_ctrl.c.

int urg_remainCaptureTimes ( const urg_t urg)

Get number of remaining times on MD/MS capture.

Parameters:
[in,out]urgStructure of URG control
Return values:
remainingtimes. (100 means infinity times)
See also:
md_scan.c
Examples:
md_scan.c, and multi_urg.c.

Definition at line 299 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]. Return all scan data when specified URG_FIRST, URG_LAST.

Parameters:
[in,out]urgStructure of URG control
[in]request_typeReceived data type.
[in]first_indexIndex of the first data stored
[in]last_indexIndex of the last received data stored.
Return values:
0Normal
<0Error
See also:
urg_receiveData()
gd_scan.c, md_scan.c

Example Example 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
    ...
  }
} 
Examples:
capture_sample.c, check_performance.c, convert_2d.c, evaluate_timestamp.c, gd_scan.c, infinity_scan.c, intensity_sample.c, md_scan.c, multi_urg.c, and partial_scan.c.

Definition at line 311 of file urg_ctrl.c.

int urg_receiveData ( urg_t urg,
long  data[],
int  data_max 
)

Receive URG data.

Parameters:
[in,out]urgStructure of URG control
[out]dataStorage location of received data
[in]data_maxMaximum number of data that can be received
Return values:
0> Number of data received
<0Error
See also:
urg_requestData()
Examples:
capture_sample.c, check_performance.c, convert_2d.c, evaluate_timestamp.c, gd_scan.c, infinity_scan.c, md_scan.c, and multi_urg.c.

Definition at line 644 of file urg_ctrl.c.

int urg_receiveDataWithIntensity ( urg_t urg,
long  data[],
int  data_max,
long  intensity[] 
)

Get data with intensity.

Parameters:
[in,out]urgStructure of URG control
[out]dataStorage location of received data
[in]data_maxMaximum number of data that can be received
[out]intensityStorage location of intensity of received data.
Attention:
Applicable only to URG-04LX (currently 2008-12-24)
Examples:
intensity_sample.c.

Definition at line 654 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]urgStructure of URG control
[out]dataStorage location of received data
[in]data_maxMaximum number of data that can be received
[in]first_indexIndex of the first data stored.
[in]last_indexIndex of the last data stored
Return values:
0>Number of data received
<0Error
See also:
gd_scan.c, md_scan.c
Examples:
check_performance.c, and partial_scan.c.

Definition at line 677 of file urg_ctrl.c.

long urg_recentTimestamp ( const urg_t urg)

Receive time stamp.

Parameters:
[in,out]urgStructure of URG control
Return values:
Timestamp [msec]
See also:
md_scan.c

Example Example 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
  // !!!
} 
Examples:
capture_sample.c, evaluate_timestamp.c, gd_scan.c, infinity_scan.c, intensity_sample.c, md_scan.c, and multi_urg.c.

Definition at line 684 of file urg_ctrl.c.

double urg_index2rad ( const 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]urgStructure of URG control
[in]indexIndex value
Returns:
angle[radian]

Example

// To operate urg_index2rad(), data from 0 to last_index is stored.
// The data of the step not measured becomes -1.
urg_requestData(&urg, URG_GD, first_index, last_index);
n = urg_receiveData(&urg, data, data_max);
for (i = 0; i < n; ++i) {
  long l = data[i];
  if (l > min_distance) {
    double rad = urg_index2rad(&urg, i);
    double x = data[i] * cos(rad);
    double y = data[i] * sin(rad);
    printf("%f, %f\n", x, y);
  }
} 
See also:
index_convert.c
Examples:
convert_2d.c, and index_convert.c.

Definition at line 691 of file urg_ctrl.c.

int urg_index2deg ( const urg_t urg,
int  index 
)

Change index into angle(degree)

Parameters:
[in,out]urgStructure of URG control
[in]indexIndex value
Returns:
Angle [degree]
See also:
index_convert.c
Examples:
index_convert.c.

Definition at line 700 of file urg_ctrl.c.

int urg_rad2index ( const 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]urgStructure of URG control
[in]radianAngle(radian)
Returns:
Index
See also:
index_convert.c
Examples:
index_convert.c.

Definition at line 708 of file urg_ctrl.c.

int urg_deg2index ( const urg_t urg,
int  degree 
)

Angle(degree) is converted into index.

Parameters:
[in,out]urgStructure of URG control
[in]degreeAngle(degre)
Returns:
Index value
See also:
index_convert.c
Examples:
check_performance.c, and index_convert.c.

Definition at line 723 of file urg_ctrl.c.

int urg_laserOn ( urg_t urg)

Directs laser to switch on.

Parameters:
[in,out]urgStructure of URG control
Return values:
0Normal
<0Error
See also:
gd_scan.c

Definition at line 729 of file urg_ctrl.c.

int urg_laserOff ( urg_t urg)

Directs laser to switch off.

Parameters:
[in,out]urgStructure of URG control
Return values:
0Normal
<0Error
Examples:
multi_urg.c.

Definition at line 746 of file urg_ctrl.c.

int urg_reboot ( urg_t urg)

reboot

Return values:
0Normal
<0Error
Attention:
Only Top-URG (2010-02-04)

Definition at line 752 of file urg_ctrl.c.

int urg_reset ( urg_t urg)
Deprecated:
use reboot() function.

Definition at line 785 of file urg_ctrl.c.

Enters into time stamp mode.

Parameters:
[in,out]urgStructure of URG control
Return values:
0Normal
<0Error
Examples:
get_timestamp.c.

Definition at line 791 of file urg_ctrl.c.

Comes out of time stamp mode.

Parameters:
[in,out]urgStructure of URG control
Return values:
0Normal
<0Error
Examples:
get_timestamp.c.

Definition at line 803 of file urg_ctrl.c.

long urg_currentTimestamp ( urg_t urg)

Get time stamp.

Returns TM1 response.

Parameters:
[in,out]urgStructure of URG control
Return values:
>=0Timestamp [msec]
<0Error

Example Example 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)
}

// leave tiemstamp mode
urg_disableTimestampMode(&urg); 
Examples:
get_timestamp.c.

Definition at line 815 of file urg_ctrl.c.