-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurdf_renderer_plugin_c.cpp
More file actions
324 lines (256 loc) · 8.36 KB
/
urdf_renderer_plugin_c.cpp
File metadata and controls
324 lines (256 loc) · 8.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include "urdf_renderer_plugin.h"
#include "urdf_renderer_plugin.hpp"
#include <cstring>
// Internal context structure
struct UrdfPluginContext {
URDFRendererPlugin* plugin;
};
// ============================================================================
// Context Management
// ============================================================================
UrdfPluginHandle urdf_plugin_create(const UrdfRenderConfig* render_config) {
try {
auto* context = new UrdfPluginContext();
context->plugin = new URDFRendererPlugin();
if (!context->plugin->initialize(render_config)) {
delete context->plugin;
delete context;
return nullptr;
}
return context;
} catch (...) {
return nullptr;
}
}
void urdf_plugin_destroy(UrdfPluginHandle handle) {
if (!handle) return;
if (handle->plugin) {
delete handle->plugin;
}
delete handle;
}
const char* urdf_plugin_get_error(UrdfPluginHandle handle) {
if (!handle || !handle->plugin) {
return "Invalid handle";
}
return handle->plugin->getLastError().c_str();
}
// ============================================================================
// URDF Operations
// ============================================================================
UrdfPluginError urdf_plugin_load_file(UrdfPluginHandle handle, const char* urdf_path) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!urdf_path) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->loadURDF(urdf_path);
}
const char* urdf_plugin_get_model_name(UrdfPluginHandle handle) {
if (!handle || !handle->plugin) {
return nullptr;
}
static std::string model_name;
model_name = handle->plugin->getModelName();
return model_name.c_str();
}
UrdfPluginError urdf_plugin_get_joint_count(UrdfPluginHandle handle, size_t* count) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!count) {
return URDF_ERROR_INVALID_PARAMETER;
}
*count = handle->plugin->getJointCount();
return URDF_SUCCESS;
}
UrdfPluginError urdf_plugin_get_joint_names(
UrdfPluginHandle handle,
char** names,
size_t max_names,
size_t name_buffer_size) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!names) {
return URDF_ERROR_INVALID_PARAMETER;
}
const auto joint_names = handle->plugin->getJointNames();
const size_t count = std::min(max_names, joint_names.size());
for (size_t i = 0; i < count; ++i) {
strncpy(names[i], joint_names[i].c_str(), name_buffer_size - 1);
names[i][name_buffer_size - 1] = '\0';
}
return URDF_SUCCESS;
}
UrdfPluginError urdf_plugin_get_joint_info(
UrdfPluginHandle handle,
const char* joint_name,
UrdfJointInfo* info) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!joint_name || !info) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->getJointInfo(joint_name, info);
}
// ============================================================================
// Joint Control
// ============================================================================
UrdfPluginError urdf_plugin_set_joint_angle(
UrdfPluginHandle handle,
const char* joint_name,
double angle) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!joint_name) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->setJointAngle(joint_name, angle);
}
UrdfPluginError urdf_plugin_get_joint_angle(
UrdfPluginHandle handle,
const char* joint_name,
double* angle) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!joint_name || !angle) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->getJointAngle(joint_name, angle);
}
UrdfPluginError urdf_plugin_set_multiple_joints(
UrdfPluginHandle handle,
const char** joint_names,
const double* angles,
size_t count) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!joint_names || !angles) {
return URDF_ERROR_INVALID_PARAMETER;
}
std::vector<std::string> names;
std::vector<double> angle_vec;
names.reserve(count);
angle_vec.reserve(count);
for (size_t i = 0; i < count; ++i) {
names.push_back(joint_names[i]);
angle_vec.push_back(angles[i]);
}
return handle->plugin->setMultipleJoints(names, angle_vec);
}
UrdfPluginError urdf_plugin_reset_joints(UrdfPluginHandle handle) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
return handle->plugin->resetJoints();
}
// ============================================================================
// Camera Control
// ============================================================================
UrdfPluginError urdf_plugin_set_camera(
UrdfPluginHandle handle,
const UrdfCameraConfig* camera_config) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!camera_config) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->setCamera(*camera_config);
}
UrdfPluginError urdf_plugin_get_camera(
UrdfPluginHandle handle,
UrdfCameraConfig* camera_config) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!camera_config) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->getCamera(camera_config);
}
// ============================================================================
// Rendering
// ============================================================================
UrdfPluginError urdf_plugin_set_render_config(
UrdfPluginHandle handle,
const UrdfRenderConfig* render_config) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!render_config) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->setRenderConfig(*render_config);
}
UrdfPluginError urdf_plugin_render_frame(UrdfPluginHandle handle) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
return handle->plugin->renderFrame();
}
UrdfPluginError urdf_plugin_start_continuous_render(
UrdfPluginHandle handle,
uint32_t target_fps) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
return handle->plugin->startContinuousRender(target_fps);
}
UrdfPluginError urdf_plugin_stop_continuous_render(UrdfPluginHandle handle) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
return handle->plugin->stopContinuousRender();
}
bool urdf_plugin_is_rendering(UrdfPluginHandle handle) {
if (!handle || !handle->plugin) {
return false;
}
return handle->plugin->isRendering();
}
// ============================================================================
// Image Output
// ============================================================================
UrdfPluginError urdf_plugin_get_image_buffer(
UrdfPluginHandle handle,
UrdfImageData* image_data) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!image_data) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->getImageBuffer(image_data);
}
UrdfPluginError urdf_plugin_save_image(
UrdfPluginHandle handle,
const char* file_path,
UrdfImageFormat format) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!file_path) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->saveImage(file_path, format);
}
UrdfPluginError urdf_plugin_copy_image_buffer(
UrdfPluginHandle handle,
uint8_t* buffer,
size_t buffer_size,
size_t* bytes_written) {
if (!handle || !handle->plugin) {
return URDF_ERROR_INVALID_HANDLE;
}
if (!buffer || !bytes_written) {
return URDF_ERROR_INVALID_PARAMETER;
}
return handle->plugin->copyImageBuffer(buffer, buffer_size, bytes_written);
}