Skip to content

Commit

Permalink
Merge pull request #18 from s-watanabe1527/master
Browse files Browse the repository at this point in the history
 Merge pull request
  • Loading branch information
s-watanabe1527 authored Jun 22, 2022
2 parents e1780bb + b08de54 commit 3f8f2f3
Show file tree
Hide file tree
Showing 20 changed files with 1,355 additions and 36 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# urgwidget

VERSION = 1.2.5
VERSION = 1.2.6
RELEASE_DIR = release
PACKAGE_EN_DIR = urg_library-$(VERSION)
PACKAGE_JA_DIR = urg_library_ja-$(VERSION)
Expand Down Expand Up @@ -46,7 +46,6 @@ dist : release_clean
cp current/include/cpp/*.h $(RELEASE_DIR)/$$i/include/cpp/; \
cp current/src/*.c $(RELEASE_DIR)/$$i/src/; \
cp current/src/*.cpp $(RELEASE_DIR)/$$i/src/; \
cp current/samples/c/*.sh $(RELEASE_DIR)/$$i/samples/c/; \
cp current/windowsexe/*.bat $(RELEASE_DIR)/$$i/windowsexe/; \
cp -r current/vs2005/ $(RELEASE_DIR)/$$i/; \
cp -r current/vs2010/ $(RELEASE_DIR)/$$i/; \
Expand Down
6 changes: 6 additions & 0 deletions Releasenotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2022-06-22
* 1.2.6 released.
* Added get_distance_io and get_distance_intensity_io functions.
* Added get_distance_io and get_distance_intensity_io samples for VS2017.
* Fixed urg_is_stable function.

2019-10-29
* 1.2.5 released.
* Added urg_t_initialize function.
Expand Down
138 changes: 128 additions & 10 deletions current/include/c/urg_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ extern "C" {
\brief Measurement types
*/
typedef enum {
URG_DISTANCE, //!< \~japanese 距離 \~english Distance (range)
URG_DISTANCE_INTENSITY, //!< \~japanese 距離 + 強度 \~english Distance (range) and intensity (strength)
URG_MULTIECHO, //!< \~japanese マルチエコーの距離 \~english Multiecho distance
URG_MULTIECHO_INTENSITY, //!< \~japanese マルチエコーの(距離 + 強度) \~english Multiecho distance and intensity
URG_STOP, //!< \~japanese 計測の停止 \~english Stop measurement
URG_UNKNOWN, //!< \~japanese 不明 \~english Unknown measurement type
URG_DISTANCE, //!< \~japanese 距離 \~english Distance (range)
URG_DISTANCE_INTENSITY, //!< \~japanese 距離 + 強度 \~english Distance (range) and intensity (strength)
URG_DISTANCE_IO, //!< \~japanese 距離 + IO情報 \~english Distance (range) and IO(input/output)
URG_DISTANCE_INTENSITY_IO, //!< \~japanese 距離 + 強度 + IO情報 \~english Distance (range), intensity and IO(input/output)
URG_MULTIECHO, //!< \~japanese マルチエコーの距離 \~english Multiecho distance
URG_MULTIECHO_INTENSITY, //!< \~japanese マルチエコーの(距離 + 強度) \~english Multiecho distance and intensity
URG_STOP, //!< \~japanese 計測の停止 \~english Stop measurement
URG_UNKNOWN, //!< \~japanese 不明 \~english Unknown measurement type
} urg_measurement_type_t;

/*!
Expand All @@ -54,7 +56,8 @@ extern "C" {

enum {
URG_SCAN_INFINITY = 0, //!< \~japanese 無限回のデータ取得 \~english Continuous data scanning
URG_MAX_ECHO = 3, //!< \~japanese マルチエコーの最大エコー数 \~english Maximum number of echoes
URG_MAX_ECHO = 3, //!< \~japanese マルチエコーの最大エコー数 \~english Maximum number of echoes
URG_MAX_IO = 2, //!< \~japanese IO情報の最大データ数 \~english Maximum number of IO(input/output)
};


Expand Down Expand Up @@ -451,6 +454,63 @@ extern "C" {
*/
extern int urg_get_distance(urg_t *urg, long data[], long *time_stamp);

/*!
\~japanese
\brief 距離データとIO情報の取得
センサから距離データとIO情報を取得します。事前に urg_start_measurement() を #URG_DISTANCE_IO 指定で呼び出しておく必要があります。
\param[in,out] urg URG センサ管理
\param[out] data 距離データ [mm]
\param[out] io IO情報
\param[out] time_stamp タイムスタンプ [msec]
\retval >=0 受信したデータ個数
\retval <0 エラー
io には、センサから取得したIO情報が格納されます。
io[0]に入力値、io[1]に出力値が格納されるため、2要素分のサイズを確保しておく必要があります。
data, time_stamp については urg_get_distance() と同じです。
なお、IO情報取得に対応していない機種では、エラーになります。
\~english
\brief Gets distance and IO(input/output) data
Receives distance and IO(input/output) data from the sensor. The urg_start_measurement() function was called beforehand with #URG_DISTANCE as type argument.
\param[in,out] urg URG control structure
\param[out] data Distance data array [mm]
\param[out] io IO data array
\param[out] time_stamp Timestamp [msec]
\retval >=0 Number of data points received
\retval <0 Error
IO data received from the sensor are stored in data array.
The input value is stored in io[0] and the output value in io[1].
The size of the two elements should be reserved in advance.
Regarding data and time_stamp arguments, refer to urg_get_distance().
Note that an error will occur for models that do not support IO information acquisition.
\~
Example
\code
long *data = (long*)malloc(urg_max_data_size(&urg) * sizeof(data[0]));
long *io = malloc(2 * sizeof(long));
long time_stamp;
...
urg_start_measurement(&urg, URG_DISTANCE_IO, 1, 0);
int n = urg_get_distance_io(&urg, data, io, &time_stamp); \endcode
\see urg_start_measurement()
*/
extern int urg_get_distance_io(urg_t* urg, long data[], long io[], long* time_stamp);

/*!
\~japanese
Expand Down Expand Up @@ -501,7 +561,7 @@ extern "C" {
...
urg_start_measurement(&urg, URG_DISTANCE_INTENSITY, 1, 0);
int n = urg_get_distance_intensity(&urg, data, intesnity, NULLL); \endcode
int n = urg_get_distance_intensity(&urg, data, intesnity, NULL); \endcode
\~
\see urg_start_measurement(), urg_max_data_size()
Expand All @@ -510,6 +570,64 @@ extern "C" {
unsigned short intensity[],
long *time_stamp);

/*!
\~japanese
\brief 距離・強度データとIO情報の取得
urg_get_distance_io() に加え、強度データの取得ができる関数です。事前に urg_start_measurement() を #URG_DISTANCE_INTENSITY_IO 指定で呼び出しておく必要があります。
\param[in,out] urg URG センサ管理
\param[out] data 距離データ [mm]
\param[out] intensity 強度データ
\param[out] io IO情報
\param[out] time_stamp タイムスタンプ [msec]
\retval >=0 受信したデータ個数
\retval <0 エラー
data, time_stamp については urg_get_distance()
intensity については urg_get_distance_intensity()
io については urg_get_distance_io() を参照してください。
なお、IO情報取得に対応していない機種では、エラーになります。
\~english
\brief Gets distance, intensity and IO(input/output) data
This is an extension to urg_get_distance_io() which allows to obtain also the intensity (strength) data. The urg_start_measurement() function was called beforehand with #URG_DISTANCE_INTENSITY_IO as type argument.
\param[in,out] urg URG control structure
\param[out] data Distance data array [mm]
\param[out] intensity Intensity data array
\param[out] io IO data array
\param[out] time_stamp Timestamp [msec]
\retval >=0 Number of data points received
\retval <0 Error
Regarding data and time_stamp arguments, refer to urg_get_distance().
Regarding io arguments, refer to urg_get_distance_io().
Note that an error will occur for models that do not support IO information acquisition.
\~
Example
\code
int data_size = urg_max_data_size(&urg);
long *data = malloc(data_size * sizeof(long));
long *intensity = malloc(data_size * sizeof(unsigned short));
long *io = malloc(2 * sizeof(long));
...
urg_start_measurement(&urg, URG_DISTANCE_INTENSITY_IO, 1, 0);
int n = urg_get_distance_intensity(&urg, data, intesnity, NULL); \endcode
\see urg_start_measurement(), urg_max_data_size()
*/
extern int urg_get_distance_intensity_io(urg_t* urg, long data[],
unsigned short intensity[],
long io[], long* time_stamp);

/*!
\~japanese
Expand Down Expand Up @@ -584,7 +702,7 @@ extern "C" {
...
urg_start_measurement(&urg, URG_MULTIECHO, 1, 0);
int n = urg_get_distance_intensity(&urg, data_multi, NULLL); \endcode
int n = urg_get_distance_intensity(&urg, data_multi, NULL); \endcode
\~
\see urg_start_measurement(), urg_max_data_size()
Expand Down Expand Up @@ -637,7 +755,7 @@ extern "C" {
urg_start_measurement(&urg, URG_DISTANCE_INTENSITY, 1, 0);
int n = urg_get_multiecho_intensity(&urg, data_multi,
intesnity_multi, NULLL); \endcode
intesnity_multi, NULL); \endcode
\~
\see urg_start_measurement(), urg_max_data_size()
Expand Down
2 changes: 2 additions & 0 deletions current/include/cpp/Lidar.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace qrk
Distance_intensity, //!< \~japanese 距離 + 強度 \~english Distance (range) and intensity (strength)
Multiecho, //!< \~japanese マルチエコーの距離 \~english Multiecho distance
Multiecho_intensity, //!< \~japanese マルチエコーの(距離 + 強度) \~english Multiecho distance and intensity
Distance_io, //!< \~japanese 距離 + IO \~english Distance (range) and io(input/output)
Distance_intensity_io, //!< \~japanese 距離 + 強度 + IO \~english Distance (range), intensity and io(input/output)
} measurement_type_t;

typedef enum {
Expand Down
8 changes: 8 additions & 0 deletions current/include/cpp/Urg_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ namespace qrk
std::vector<unsigned short>& intensity,
long *time_stamp = NULL);

bool get_distance_io(std::vector<long>& data, std::vector<long>& io, long *time_stamp = NULL);

bool get_distance_intensity_io(std::vector<long>& data,
std::vector<unsigned short>& intensity,
std::vector<long>& io,
long *time_stamp = NULL);

bool get_multiecho(std::vector<long>& data_multi,
long* time_stamp = NULL);

Expand Down Expand Up @@ -102,6 +109,7 @@ namespace qrk
long scan_usec(void) const;
int max_data_size(void) const;
int max_echo_size(void) const;
int max_io_size(void) const;

const char* product_type(void) const;
const char* firmware_version(void) const;
Expand Down
2 changes: 1 addition & 1 deletion current/samples/Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ URG_LIB = ../src/liburg_c.a
include ../build_rule.mk

CFLAGS = -O2 $(INCLUDES) -I../include
LDLIBS = -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh`
LDLIBS = -lm $(shell if test `echo $(OS) | grep Windows`; then echo "-lwsock32 -lsetupapi"; fi)

all : $(TARGET)

Expand Down
2 changes: 1 addition & 1 deletion current/samples/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CC = gcc
CFLAGS = -g -O0 -Wall -Werror -W $(INCLUDES)
INCLUDES = -I$(INCLUDEDIR)
LDFLAGS =
LDLIBS = -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh`
LDLIBS = -lm $(shell if test `echo $(OS) | grep Windows`; then echo "-lwsock32 -lsetupapi"; fi)

# Target
TARGET = \
Expand Down
2 changes: 1 addition & 1 deletion current/samples/c/Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ URG_LIB = ../../src/liburg_c.a
include ../../build_rule.mk

CFLAGS = -O2 $(INCLUDES) -I../../include/c
LDLIBS = -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh`
LDLIBS = -lm $(shell if test `echo $(OS) | grep Windows`; then echo "-lwsock32 -lsetupapi"; fi)

all : $(TARGET)

Expand Down
105 changes: 105 additions & 0 deletions current/samples/c/get_distance_intensity_io.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*!
\~japanese
\example get_distance_intensity.c 距離・強度・IOデータを取得する
\~english
\example get_distance_intensity.c Obtains distance, intensity and IO(input/output) data
\~
$Id$
*/

#include "urg_sensor.h"
#include "urg_utils.h"
#include "open_urg_sensor.h"
#include <stdio.h>
#include <stdlib.h>


static void print_data(urg_t *urg, long data[], unsigned short intensity[],
long io[], long time_stamp)
{
enum {
IO_BIT_SIZE = 18,
};

printf("timestamp: %ld\n", time_stamp);

// \~japanese IO情報を表示
// \~english Display IO information
unsigned long mask = (int)1 << (IO_BIT_SIZE - 1);
char in[IO_BIT_SIZE + 1];
char out[IO_BIT_SIZE + 1];
int i;
for (i = 0; i < IO_BIT_SIZE; ++i) {
in[i] = (mask & io[0] ? '1' : '0');
out[i] = (mask & io[1] ? '1' : '0');
mask >>= 1;
}
in[IO_BIT_SIZE] = '\0';
out[IO_BIT_SIZE] = '\0';
printf("input : %s (%ld)\n", in, io[0]);
printf("output : %s (%ld)\n", out, io[1]);

// \~japanese 前方のデータのみを表示
// \~english Shows only the front step
int front_index = urg_step2index(urg, 0);
printf("distance : %ld [mm]\n", data[front_index]);
printf("intensity: %ld [1]\n\n", intensity[front_index]);
}


int main(int argc, char *argv[])
{
enum {
CAPTURE_TIMES = 10,
};
urg_t urg;
int max_data_size;
long *io = malloc(2 * sizeof(long));
long *data = NULL;
unsigned short *intensity = NULL;
long time_stamp;
int n;
int i;

if (open_urg_sensor(&urg, argc, argv) < 0) {
return 1;
}

max_data_size = urg_max_data_size(&urg);
data = (long *)malloc(max_data_size * sizeof(data[0]));
if (!data) {
perror("urg_max_index()");
return 1;
}
intensity = malloc(max_data_size * sizeof(intensity[0]));
if (!intensity) {
perror("urg_max_index()");
return 1;
}

// \~japanese データ取得
// \~english Gets measurement data
urg_start_measurement(&urg, URG_DISTANCE_INTENSITY_IO, URG_SCAN_INFINITY, 0);
for (i = 0; i < CAPTURE_TIMES; ++i) {
n = urg_get_distance_intensity_io(&urg, data, intensity, io, &time_stamp);
if (n <= 0) {
printf("urg_get_distance_intensity_io: %s\n", urg_error(&urg));
free(data);
urg_close(&urg);
return 1;
}
print_data(&urg, data, intensity, io, time_stamp);
}

// \~japanese 切断
// \~english Disconnects
free(intensity);
free(data);
urg_close(&urg);

#if defined(URG_MSC)
getchar();
#endif
return 0;
}
Loading

0 comments on commit 3f8f2f3

Please sign in to comment.