質問編集履歴
3
文章の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
その際に、下記ライブラリは*.libしか作成されないため、*.dllを作成する必要があります。
|
3
3
|
*.dllを作成するにあたり、提供されているライブラリがクラスになっているため、c++/CLIラッパを採用して作成しています。
|
4
4
|
|
5
|
+
Urg_driver.cppを直接ラッピングしたUrgDriver.cppを新規で作成しています。
|
6
|
+
|
5
7
|
https://sourceforge.net/projects/urgnetwork/files/urg_library/urg_library_ja-1.2.5.zip/download
|
6
8
|
|
7
9
|
```UrgDriver.cpp
|
2
削除し忘れていた文章を削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,10 +4,6 @@
|
|
4
4
|
|
5
5
|
https://sourceforge.net/projects/urgnetwork/files/urg_library/urg_library_ja-1.2.5.zip/download
|
6
6
|
|
7
|
-
ライブラリである\urg_library_ja-1.2.5\include\cpp\Urg_driver.hをUrgLib.h、
|
8
|
-
\urg_library_ja-1.2.5\src\Urg_driver.cppをUrgLib.cpp
|
9
|
-
として記述しました。
|
10
|
-
|
11
7
|
```UrgDriver.cpp
|
12
8
|
#include "pch.h"
|
13
9
|
|
1
間にWrapperClassを挟むのをやめ、UrgDriverを直接ラッピングするようにしました
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,40 +8,8 @@
|
|
8
8
|
\urg_library_ja-1.2.5\src\Urg_driver.cppをUrgLib.cpp
|
9
9
|
として記述しました。
|
10
10
|
|
11
|
-
```
|
11
|
+
```UrgDriver.cpp
|
12
|
-
//------追記部分--------
|
13
|
-
#ifdef URGLIB_EXPORTS
|
14
|
-
#define URGLIB_API __declspec(dllexport)
|
15
|
-
#else
|
16
|
-
#define URGLIB_API __declspec(dllimport)
|
17
|
-
#endif
|
18
|
-
//---------------------
|
19
|
-
|
20
|
-
#include <memory>
|
21
|
-
#include <string>
|
22
|
-
|
23
|
-
#include <vector>
|
24
|
-
#include <cstddef>
|
25
|
-
#include "Lidar.h"
|
26
|
-
|
27
|
-
namespace qrk
|
28
|
-
{
|
29
|
-
class URGLIB_API UrgLib : public Lidar //classの後にURGLIB_APIを追記
|
30
|
-
{
|
31
|
-
|
32
|
-
private:
|
33
|
-
UrgLib(const UrgLib& rhs);
|
34
|
-
UrgLib& operator = (const UrgLib& rhs);
|
35
|
-
|
36
|
-
struct pImpl;
|
37
|
-
std::auto_ptr<pImpl> pimpl;
|
38
|
-
};
|
39
|
-
}
|
40
|
-
```
|
41
|
-
|
42
|
-
```UrgLib.cpp(途中省略、追記した個所はなし)
|
43
12
|
#include "pch.h"
|
44
|
-
#include "UrgLib.h"
|
45
13
|
|
46
14
|
#include "ticks.h"
|
47
15
|
extern "C" {
|
@@ -52,138 +20,81 @@
|
|
52
20
|
#include "urg_debug.h"
|
53
21
|
}
|
54
22
|
|
23
|
+
#include "UrgDriver.h"
|
55
|
-
|
24
|
+
#include <string>
|
56
|
-
|
25
|
+
#include <vector>
|
26
|
+
#include <msclr\marshal.h>
|
57
27
|
|
58
|
-
```
|
59
|
-
WrapperClass.hはUrgLib.hをラッピング、WrapperClass.cppはUrgLib.cppをラッピングして作成しています。
|
60
|
-
|
61
|
-
```WrapperClass.h(途中省略)
|
62
|
-
#include "../UrgLib/UrgLib.h"
|
63
|
-
|
64
|
-
#include <msclr/marshal_cppstd.h>
|
65
|
-
#include <msclr/marshal.h>
|
66
|
-
|
67
|
-
using namespace System;
|
68
|
-
using namespace System::Runtime::InteropServices;
|
69
|
-
using namespace System::Collections::Generic;
|
70
28
|
using namespace msclr::interop;
|
29
|
+
using namespace qrk;
|
71
30
|
|
72
|
-
|
73
|
-
namespace
|
31
|
+
namespace QRK
|
74
32
|
{
|
75
|
-
public ref class WrapperClass
|
76
|
-
{
|
77
|
-
|
78
|
-
private:
|
79
|
-
qrk::UrgLib* _urglib;
|
80
|
-
|
81
|
-
public:
|
82
|
-
|
83
|
-
WrapperClass();
|
84
|
-
~WrapperClass();
|
85
|
-
!WrapperClass();
|
86
|
-
|
87
|
-
enum class Default{
|
88
|
-
Default_baudrate = 115200,
|
89
|
-
Default_port = 10940,
|
90
|
-
Infinity_times = -1,
|
91
|
-
};
|
92
|
-
|
93
|
-
};
|
94
|
-
}
|
95
|
-
```
|
96
|
-
|
97
|
-
その際、UrgLib.cppで記述されている
|
98
|
-
|
99
|
-
```UrgLib.cppで記述されているstruct
|
100
|
-
struct UrgLib::pImpl
|
101
|
-
{
|
102
|
-
urg_t urg_;
|
103
|
-
measurement_type_t last_measure_type_;
|
104
|
-
long time_stamp_offset_;
|
105
|
-
|
106
|
-
string product_type_; //WrapperClass.cppではSystem::String^ product_type = msclr::interop::marshal_as<System::String^>(product_type_);と記述する予定。下のstringも同じように記述する予定
|
107
|
-
|
33
|
+
UrgDriver::UrgDriver(void)
|
108
|
-
string serial_id_;
|
109
|
-
string status_;
|
110
|
-
string state_;
|
111
|
-
|
112
|
-
|
113
|
-
pImpl(void)
|
114
|
-
:last_measure_type_(Distance), time_stamp_offset_(0)
|
115
34
|
{
|
35
|
+
urg_ = new urg_t;
|
116
|
-
urg_t_initialize(
|
36
|
+
urg_t_initialize(urg_);
|
117
37
|
}
|
118
38
|
|
119
|
-
|
120
|
-
|
39
|
+
UrgDriver::~UrgDriver(void)
|
121
40
|
{
|
122
|
-
|
41
|
+
Close();
|
123
|
-
*time_stamp += time_stamp_offset_;
|
124
|
-
}
|
125
42
|
}
|
126
|
-
};
|
127
|
-
```
|
128
|
-
をWrapperClass.cppに記述しようとしているのですが、構造がややこしく検索してもマーシャリングの方法が分からなかったため、お手数をおかけしますがご教示お願いいたします。
|
129
43
|
|
130
|
-
urg_t urg_;のurg_tはUrgLib.cppでインクルードしているurg_sensor.hの中で記述されている構造体(下記)で、
|
131
|
-
|
44
|
+
bool UrgDriver::StartMeasurement(MeasurementType type,
|
132
|
-
|
45
|
+
int scan_times, int skip_scan)
|
46
|
+
{
|
133
47
|
|
48
|
+
typedef struct { //struct部分にてマネージドクラスのメンバー関数ではローカルクラス定義は使用できません
|
49
|
+
urg_measurement_type_t c_type;
|
134
|
-
|
50
|
+
MeasurementType type;
|
51
|
+
} type_table_t;
|
52
|
+
|
135
53
|
|
136
|
-
|
54
|
+
type_table_t type_table[] = {
|
55
|
+
{ URG_DISTANCE, QRK::MeasurementType::Distance },
|
56
|
+
{ URG_DISTANCE_INTENSITY, QRK::MeasurementType::Distance_intensity },
|
57
|
+
{ URG_MULTIECHO, QRK::MeasurementType::Multiecho },
|
58
|
+
{ URG_MULTIECHO_INTENSITY, QRK::MeasurementType::Multiecho_intensity },
|
59
|
+
};
|
137
60
|
|
61
|
+
size_t n = sizeof(type_table) / sizeof(type_table[0]);
|
62
|
+
for (size_t i = 0; i < n; ++i) {
|
63
|
+
const type_table_t* p = &type_table[i];
|
138
|
-
|
64
|
+
if (type == p->type) {
|
65
|
+
int ret = urg_start_measurement(urg_,
|
139
|
-
|
66
|
+
p->c_type, scan_times, skip_scan);
|
140
|
-
|
67
|
+
if (ret == URG_NO_ERROR) {
|
141
|
-
|
68
|
+
last_measure_type_ = type;
|
69
|
+
}
|
70
|
+
return (ret == URG_NO_ERROR) ? true : false;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
return false;
|
74
|
+
}
|
142
75
|
|
143
|
-
|
76
|
+
bool UrgDriver::GetDistanceIntensity(System::Collections::Generic::IList<int>^ data, System::Collections::Generic::IList<unsigned short>^ intensity, int% time_stamp)
|
144
77
|
{
|
78
|
+
if (last_measure_type_ != QRK::MeasurementType::Distance_intensity) {
|
79
|
+
urg_.last_errno = URG_MEASUREMENT_TYPE_MISMATCH;
|
145
|
-
|
80
|
+
return false;
|
146
|
-
int last_errno;
|
147
|
-
urg_connection_t connection; //urg_connection.hにて定義されている構造体
|
148
|
-
//中身は下記
|
149
|
-
//typedef struct
|
150
|
-
|
81
|
+
}
|
151
|
-
// urg_connection_type_t type;
|
152
|
-
|
82
|
+
// 最大サイズを確保し、そこにデータを格納する
|
83
|
+
size_t data_size = MaxDataSize();
|
84
|
+
data.resize(data_size); //①resize部分にて、class "System::Collections::Generic::IList<int>"にメンバー"resize"がありません
|
85
|
+
intensity.resize(data_size); //①と同じエラー
|
153
|
-
|
86
|
+
int ret = urg_get_distance_intensity(urg_,
|
87
|
+
&data[0], &intensity[0], (long*)time_stamp);//1. dataおよびintensity部分にて、式は左辺値または関数指定子である必要があります
|
88
|
+
if (ret > 0) {
|
89
|
+
data.resize(ret); //①と同じエラー
|
90
|
+
intensity.resize(ret);//①と同じエラー
|
154
|
-
|
91
|
+
adjust_time_stamp(time_stamp);
|
92
|
+
}
|
93
|
+
return (ret < 0) ? false : true;
|
94
|
+
}
|
155
95
|
|
156
|
-
int first_data_index;
|
157
|
-
int last_data_index;
|
158
|
-
int front_data_index;
|
159
|
-
int area_resolution;
|
160
|
-
|
96
|
+
}
|
161
|
-
int min_distance;
|
162
|
-
int max_distance;
|
163
|
-
int scanning_first_step;
|
164
|
-
int scanning_last_step;
|
165
|
-
int scanning_skip_step;
|
166
|
-
int scanning_skip_scan;
|
167
|
-
urg_range_data_byte_t range_data_byte;
|
168
97
|
|
169
|
-
int timeout;
|
170
|
-
int specified_scan_times;
|
171
|
-
int scanning_remain_times;
|
172
|
-
int is_laser_on;
|
173
|
-
|
174
|
-
int received_first_index;
|
175
|
-
int received_last_index;
|
176
|
-
int received_skip_step;
|
177
|
-
urg_range_data_byte_t received_range_data_byte;
|
178
|
-
int is_sending;
|
179
|
-
|
180
|
-
urg_error_handler error_handler;
|
181
|
-
|
182
|
-
char return_buffer[80];
|
183
|
-
} urg_t;
|
184
|
-
|
185
|
-
|
186
98
|
```
|
187
|
-
また、この構造体をc#で使用するにはどのように使用すればよいかもご教示いただけると幸いです。
|
188
99
|
|
189
100
|
|