-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from j-fujimoto/master
reboot, is_open, get_sensor_time_stampの修正
- Loading branch information
Showing
12 changed files
with
242 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
*.exe | ||
|
||
*.o | ||
|
||
*.dll | ||
|
||
*.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters