Skip to content

Commit

Permalink
Merge pull request #14 from j-fujimoto/master
Browse files Browse the repository at this point in the history
reboot, is_open, get_sensor_time_stampの修正
  • Loading branch information
j-fujimoto authored Aug 20, 2019
2 parents cc0d1fa + f092db0 commit 9c51641
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 19 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

*.exe

*.o

*.dll

*.a
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# urgwidget

VERSION = 1.2.3
VERSION = 1.2.4
RELEASE_DIR = release
PACKAGE_EN_DIR = urg_library-$(VERSION)
PACKAGE_JA_DIR = urg_library_ja-$(VERSION)
Expand Down
6 changes: 6 additions & 0 deletions Releasenotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2019-08-20
* 1.2.4 released.
* Fixed get_sensor_time_stamp to support timestamp offset.
* Changed is_open to return urg.is_active.
* Added handshake samples.

2018-06-01
* 1.2.3 released.
* Added x64 setting on VS2010.
Expand Down
2 changes: 1 addition & 1 deletion current/include/cpp/Lidar.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace qrk
virtual bool laser_on(void) = 0;
virtual bool laser_off(void) = 0;

virtual void reboot(void) = 0;
virtual bool reboot(void) = 0;

virtual void sleep(void) = 0;
virtual void wakeup(void) = 0;
Expand Down
2 changes: 1 addition & 1 deletion current/include/cpp/Urg_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace qrk
bool laser_on(void);
bool laser_off(void);

void reboot(void);
bool reboot(void);

void sleep(void);
void wakeup(void);
Expand Down
3 changes: 2 additions & 1 deletion current/samples/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LDLIBS = -lm `/bin/sh ld_wsock.sh` `/bin/sh ld_setupapi.sh`
# Target
TARGET = \
get_distance \
get_distance_handshake \
get_distance_intensity \
get_multiecho \
get_multiecho_intensity \
Expand All @@ -39,5 +40,5 @@ REQUIRE_LIB = $(SRCDIR)/liburg_c.a
$(REQUIRE_LIB) : $(wildcard $(SRCDIR)/*.[ch])
cd $(@D)/ && $(MAKE) $(@F)

get_distance get_distance_intensity get_multiecho get_multiecho_intensity calculate_xy sync_time_stamp sensor_parameter timeout_test reboot_test angle_convert_test : open_urg_sensor.o $(REQUIRE_LIB)
get_distance get_distance_handshake get_distance_intensity get_multiecho get_multiecho_intensity calculate_xy sync_time_stamp sensor_parameter timeout_test reboot_test angle_convert_test : open_urg_sensor.o $(REQUIRE_LIB)
find_port : $(REQUIRE_LIB)
2 changes: 1 addition & 1 deletion current/samples/c/Makefile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGET = sensor_parameter get_distance get_distance_intensity get_multiecho get_multiecho_intensity sync_time_stamp calculate_xy find_port
TARGET = sensor_parameter get_distance get_distance_handshake get_distance_intensity get_multiecho get_multiecho_intensity sync_time_stamp calculate_xy find_port

URG_LIB = ../../src/liburg_c.a

Expand Down
112 changes: 112 additions & 0 deletions current/samples/c/get_distance_handshake.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*!
\~japanese
\example get_distance.c 距離データを取得する
\~english
\example get_distance.c Obtains distance data
\~
\author Satofumi KAMIMURA
$Id$
*/

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


static void print_data(urg_t *urg, long data[], int data_n, long time_stamp)
{
#if 1
int front_index;

(void)data_n;

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

#else
(void)time_stamp;

int i;
long min_distance;
long max_distance;

// \~japanese 全てのデータの X-Y の位置を表示
// \~english Prints the X-Y coordinates for all the measurement points
urg_distance_min_max(urg, &min_distance, &max_distance);
for (i = 0; i < data_n; ++i) {
long l = data[i];
double radian;
long x;
long y;

if ((l <= min_distance) || (l >= max_distance)) {
continue;
}
radian = urg_index2rad(urg, i);
x = (long)(l * cos(radian));
y = (long)(l * sin(radian));
printf("(%ld, %ld), ", x, y);
}
printf("\n");
#endif
}


int main(int argc, char *argv[])
{
enum {
CAPTURE_TIMES = 10,
};
urg_t urg;
long *data = NULL;
long time_stamp;
int n;
int i;

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

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

// \~japanese データ取得
// \~english Gets measurement data
#if 0
// \~japanese データの取得範囲を変更する場合
// \~english Case where the measurement range (start/end steps) is defined
urg_set_scanning_parameter(&urg,
urg_deg2step(&urg, -90),
urg_deg2step(&urg, +90), 0);
#endif

for (i = 0; i < CAPTURE_TIMES; ++i) {
urg_start_measurement(&urg, URG_DISTANCE, 1, 0);
n = urg_get_distance(&urg, data, &time_stamp);
if (n <= 0) {
printf("urg_get_distance: %s\n", urg_error(&urg));
free(data);
urg_close(&urg);
return 1;
}
print_data(&urg, data, n, time_stamp);
}

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

#if defined(URG_MSC)
getchar();
#endif
return 0;
}
3 changes: 2 additions & 1 deletion current/samples/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ LDLIBS = -lm $(shell if test `echo $(OS) | grep Windows`; then echo "-lwsock32 -
# Target
TARGET = \
get_distance \
get_distance_handshake \
get_distance_intensity \
get_multiecho \
get_multiecho_intensity \
Expand All @@ -36,4 +37,4 @@ REQUIRE_LIB = $(SRCDIR)/liburg_cpp.a
$(REQUIRE_LIB) : $(wildcard $(SRCDIR)/*.[ch])
cd $(@D)/ && $(MAKE) $(@F)

get_distance get_distance_intensity get_multiecho get_multiecho_intensity sync_time_stamp sensor_parameter : Connection_information.o $(REQUIRE_LIB)
get_distance get_distance_handshake get_distance_intensity get_multiecho get_multiecho_intensity sync_time_stamp sensor_parameter : Connection_information.o $(REQUIRE_LIB)
2 changes: 1 addition & 1 deletion current/samples/cpp/Makefile.release
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGET = sensor_parameter get_distance get_distance_intensity get_multiecho get_multiecho_intensity sync_time_stamp
TARGET = sensor_parameter get_distance get_distance_handshake get_distance_intensity get_multiecho get_multiecho_intensity sync_time_stamp

SRCDIR = ../../src
URG_CPP_LIB = ../../src/liburg_cpp.a
Expand Down
95 changes: 95 additions & 0 deletions current/samples/cpp/get_distance_handshake.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*!
\~japanese
\example get_distance.cpp 距離データを取得する
\~english
\example get_distance.cpp Obtains distance data
\~
\author Satofumi KAMIMURA
$Id$
*/

#include "Urg_driver.h"
#include "Connection_information.h"
#include "math_utilities.h"
#include <iostream>

using namespace qrk;
using namespace std;


namespace
{
void print_data(const Urg_driver& urg,
const vector<long>& data, long time_stamp)
{
#if 1
// \~japanese 前方のデータのみを表示
// \~english Shows only the front step
int front_index = urg.step2index(0);
cout << data[front_index] << " [mm], ("
<< time_stamp << " [msec])" << endl;

#else
// \~japanese 全てのデータの X-Y の位置を表示
// \~english Prints the X-Y coordinates for all the measurement points
long min_distance = urg.min_distance();
long max_distance = urg.max_distance();
size_t data_n = data.size();
for (size_t i = 0; i < data_n; ++i) {
long l = data[i];
if ((l <= min_distance) || (l >= max_distance)) {
continue;
}
double radian = urg.index2rad(i);
long x = static_cast<long>(l * cos(radian));
long y = static_cast<long>(l * sin(radian));
cout << "(" << x << ", " << y << ")" << endl;
}
cout << endl;
#endif
}
}


int main(int argc, char *argv[])
{
Connection_information information(argc, argv);

// \~japanese 接続
// \~english Connects to the sensor
Urg_driver urg;
if (!urg.open(information.device_or_ip_name(),
information.baudrate_or_port_number(),
information.connection_type())) {
cout << "Urg_driver::open(): "
<< information.device_or_ip_name() << ": " << urg.what() << endl;
return 1;
}

// \~japanese データ取得
// \~english Gets measurement data
#if 1
// \~japanese データの取得範囲を変更する場合
// \~english Case where the measurement range (start/end steps) is defined
urg.set_scanning_parameter(urg.deg2step(-90), urg.deg2step(+90), 0);
#endif
enum { Capture_times = 10 };
for (int i = 0; i < Capture_times; ++i) {
vector<long> data;
long time_stamp = 0;

urg.start_measurement(Urg_driver::Distance, 1, 0);
if (!urg.get_distance(data, &time_stamp)) {
cout << "Urg_driver::get_distance(): " << urg.what() << endl;
return 1;
}
print_data(urg, data, time_stamp);
}

#if defined(URG_MSC)
getchar();
#endif
return 0;
}
24 changes: 12 additions & 12 deletions current/src/Urg_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
\~japanese
\brief URG ドライバ
\~english
\brief URG driver
\brief URG driver
\~
\author Satofumi KAMIMURA
Expand All @@ -27,7 +27,6 @@ using namespace std;
struct Urg_driver::pImpl
{
urg_t urg_;
bool is_opened_;
measurement_type_t last_measure_type_;
long time_stamp_offset_;

Expand All @@ -39,7 +38,7 @@ struct Urg_driver::pImpl


pImpl(void)
: is_opened_(false), last_measure_type_(Distance), time_stamp_offset_(0)
:last_measure_type_(Distance), time_stamp_offset_(0)
{
}

Expand Down Expand Up @@ -95,7 +94,6 @@ bool Urg_driver::open(const char* device_name, long baudrate,
connection_type_t type)
{
close();
pimpl->is_opened_ = false;
pimpl->product_type_.clear();
pimpl->firmware_version_.clear();
pimpl->serial_id_.clear();
Expand All @@ -107,23 +105,21 @@ bool Urg_driver::open(const char* device_name, long baudrate,
return false;
}

pimpl->is_opened_ = true;
return true;
}


void Urg_driver::close(void)
{
if (pimpl->is_opened_) {
if (is_open()) {
urg_close(&pimpl->urg_);
pimpl->is_opened_ = false;
}
}


bool Urg_driver::is_open(void) const
{
return pimpl->is_opened_;
return pimpl->urg_.is_active;
}


Expand All @@ -147,9 +143,9 @@ bool Urg_driver::laser_off(void)
}


void Urg_driver::reboot(void)
bool Urg_driver::reboot(void)
{
urg_reboot(&pimpl->urg_);
return urg_reboot(&pimpl->urg_) == URG_NO_ERROR;
}


Expand Down Expand Up @@ -314,13 +310,17 @@ void Urg_driver::stop_measurement(void)

long Urg_driver::get_sensor_time_stamp(void)
{
return urg_time_stamp(&pimpl->urg_) + pimpl->time_stamp_offset_;
long time_stamp = urg_time_stamp(&pimpl->urg_);
if (time_stamp < 0)
return time_stamp; // error code
pimpl->adjust_time_stamp(&time_stamp);
return time_stamp;
}

bool Urg_driver::set_sensor_time_stamp(long time_stamp)
{
// \~japanese この時点での PC のタイムスタンプを取得
// \~english Gets the PC's current timestamp
// \~english Gets the PC's current timestamp
long function_first_ticks = ticks();

// \~japanese PC とセンサのタイムスタンプの差を計算から推定し、
Expand Down

0 comments on commit 9c51641

Please sign in to comment.