-
Notifications
You must be signed in to change notification settings - Fork 2
/
RpcLibServerBase.cpp
632 lines (515 loc) · 31.8 KB
/
RpcLibServerBase.cpp
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// in header only mode, control library is not available
#ifndef AUTONOMYLIB_HEADER_ONLY
// RPC code requires C++14. If build system like Unreal doesn't support it then use compiled binaries
#ifndef AUTONOMYLIB_NO_RPC
// if using Unreal Build system then include precompiled header file first
#include "api/RpcLibServerBase.hpp"
#include "common/Common.hpp"
STRICT_MODE_OFF
#ifndef RPCLIB_MSGPACK
#define RPCLIB_MSGPACK clmdep_msgpack
#endif // !RPCLIB_MSGPACK
#include "common/utils/MinWinDefines.hpp"
#undef NOUSER
#include "common/utils/WindowsApisCommonPre.hpp"
#undef FLOAT
#undef check
#include "rpc/server.h"
// TODO: HACK: UE4 defines macro with stupid names like "check" that conflicts with msgpack library
#ifndef check
#define check(expr) (static_cast<void>((expr)))
#endif
#include "api/RpcLibAdaptorsBase.hpp"
#include "common/utils/WindowsApisCommonPost.hpp"
#include <functional>
#include <thread>
STRICT_MODE_ON
namespace nervosys {
namespace autonomylib {
struct RpcLibServerBase::impl {
rpc::server server;
bool is_async_ = false;
impl(string server_address, uint16_t port) : server(server_address, port) {}
impl(uint16_t port) : server(port) {}
~impl() {}
void stop() {
server.close_sessions();
if (!is_async_) {
// this deadlocks UI thread if async_run was called while there are pending rpc calls.
server.stop();
}
}
void run(bool block, std::size_t thread_count) {
if (block) {
server.run();
} else {
is_async_ = true;
server.async_run(thread_count); // 4 threads
}
}
};
typedef nervosys::autonomylib_rpclib::RpcLibAdaptorsBase RpcLibAdaptorsBase;
RpcLibServerBase::RpcLibServerBase(ApiProvider *api_provider, const std::string &server_address, uint16_t port)
: api_provider_(api_provider) {
if (server_address == "") {
pimpl_.reset(new impl(port));
} else {
pimpl_.reset(new impl(server_address, port));
}
pimpl_->server.bind("ping", [&]() -> bool { return true; });
pimpl_->server.bind("getServerVersion", []() -> int { return 1; });
pimpl_->server.bind("getMinRequiredClientVersion", []() -> int { return 1; });
pimpl_->server.bind("simPause", [&](bool is_paused) -> void { getWorldSimApi()->pause(is_paused); });
pimpl_->server.bind("simIsPaused", [&]() -> bool { return getWorldSimApi()->isPaused(); });
pimpl_->server.bind("simContinueForTime",
[&](double seconds) -> void { getWorldSimApi()->continueForTime(seconds); });
pimpl_->server.bind("simContinueForFrames",
[&](uint32_t frames) -> void { getWorldSimApi()->continueForFrames(frames); });
pimpl_->server.bind("simSetTimeOfDay",
[&](bool is_enabled, const string &start_datetime, bool is_start_datetime_dst,
float celestial_clock_speed, float update_interval_secs, bool move_sun) -> void {
getWorldSimApi()->setTimeOfDay(is_enabled, start_datetime, is_start_datetime_dst,
celestial_clock_speed, update_interval_secs, move_sun);
});
pimpl_->server.bind("simEnableWeather", [&](bool enable) -> void { getWorldSimApi()->enableWeather(enable); });
pimpl_->server.bind("simSetWeatherParameter", [&](WorldSimApiBase::WeatherParameter param, float val) -> void {
getWorldSimApi()->setWeatherParameter(param, val);
});
pimpl_->server.bind("enableApiControl", [&](bool is_enabled, const std::string &vehicle_name) -> void {
getVehicleApi(vehicle_name)->enableApiControl(is_enabled);
});
pimpl_->server.bind("isApiControlEnabled", [&](const std::string &vehicle_name) -> bool {
return getVehicleApi(vehicle_name)->isApiControlEnabled();
});
pimpl_->server.bind("armDisarm", [&](bool arm, const std::string &vehicle_name) -> bool {
return getVehicleApi(vehicle_name)->armDisarm(arm);
});
pimpl_->server.bind("simRunConsoleCommand", [&](const std::string &command) -> bool {
return getWorldSimApi()->runConsoleCommand(command);
});
pimpl_->server.bind(
"simGetImages",
[&](const std::vector<RpcLibAdaptorsBase::ImageRequest> &request_adapter, const std::string &vehicle_name,
bool external) -> vector<RpcLibAdaptorsBase::ImageResponse> {
const auto &response = getWorldSimApi()->getImages(RpcLibAdaptorsBase::ImageRequest::to(request_adapter),
vehicle_name, external);
return RpcLibAdaptorsBase::ImageResponse::from(response);
});
pimpl_->server.bind("simGetImage",
[&](const std::string &camera_name, ImageCaptureBase::ImageType type,
const std::string &vehicle_name, bool external) -> vector<uint8_t> {
return getWorldSimApi()->getImage(type, CameraDetails(camera_name, vehicle_name, external));
});
// CinemAutonomySim
pimpl_->server.bind(
"simGetPresetLensSettings",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> vector<string> {
return getWorldSimApi()->getPresetLensSettings(CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simGetLensSettings",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> string {
return getWorldSimApi()->getLensSettings(
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simSetPresetLensSettings",
[&](const std::string preset_lens_settings, const std::string &camera_name,
const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->setPresetLensSettings(preset_lens_settings,
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind(
"simGetPresetFilmbackSettings",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> vector<string> {
return getWorldSimApi()->getPresetFilmbackSettings(CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simSetPresetFilmbackSettings",
[&](const std::string preset_filmback_settings, const std::string &camera_name,
const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->setPresetFilmbackSettings(
preset_filmback_settings, CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simGetFilmbackSettings",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> string {
return getWorldSimApi()->getFilmbackSettings(
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simSetFilmbackSettings",
[&](const float width, const float heigth, const std::string &camera_name,
const std::string &vehicle_name, bool external) -> float {
return getWorldSimApi()->setFilmbackSettings(
width, heigth, CameraDetails(camera_name, vehicle_name, external));
;
});
pimpl_->server.bind("simGetFocalLength",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> float {
return getWorldSimApi()->getFocalLength(CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simSetFocalLength",
[&](const float focal_lenght, const std::string &camera_name, const std::string &vehicle_name,
bool external) -> void {
getWorldSimApi()->setFocalLength(focal_lenght,
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind(
"simEnableManualFocus",
[&](const bool enable, const std::string &camera_name, const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->enableManualFocus(enable, CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simGetFocusDistance",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> float {
return getWorldSimApi()->getFocusDistance(
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simSetFocusDistance",
[&](const float focus_distance, const std::string &camera_name, const std::string &vehicle_name,
bool external) -> void {
getWorldSimApi()->setFocusDistance(focus_distance,
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simGetFocusAperture",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> float {
return getWorldSimApi()->getFocusAperture(
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simSetFocusAperture",
[&](const float focus_aperture, const std::string &camera_name, const std::string &vehicle_name,
bool external) -> void {
getWorldSimApi()->setFocusAperture(focus_aperture,
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind(
"simEnableFocusPlane",
[&](const bool enable, const std::string &camera_name, const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->enableFocusPlane(enable, CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simGetCurrentFieldOfView",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> string {
return getWorldSimApi()->getCurrentFieldOfView(
CameraDetails(camera_name, vehicle_name, external));
});
// end CinemAutonomySim
pimpl_->server.bind("simTestLineOfSightToPoint",
[&](const RpcLibAdaptorsBase::GeoPoint &point, const std::string &vehicle_name) -> bool {
return getVehicleSimApi(vehicle_name)->testLineOfSightToPoint(point.to());
});
pimpl_->server.bind(
"simTestLineOfSightBetweenPoints",
[&](const RpcLibAdaptorsBase::GeoPoint &point1, const RpcLibAdaptorsBase::GeoPoint &point2) -> bool {
return getWorldSimApi()->testLineOfSightBetweenPoints(point1.to(), point2.to());
});
pimpl_->server.bind("simGetWorldExtents", [&]() -> vector<RpcLibAdaptorsBase::GeoPoint> {
std::vector<nervosys::autonomylib::GeoPoint> result =
getWorldSimApi()->getWorldExtents(); // returns vector with min, max
std::vector<RpcLibAdaptorsBase::GeoPoint> conv_result;
RpcLibAdaptorsBase::from(result, conv_result);
return conv_result;
});
pimpl_->server.bind("simGetMeshPositionVertexBuffers",
[&]() -> vector<RpcLibAdaptorsBase::MeshPositionVertexBuffersResponse> {
const auto &response = getWorldSimApi()->getMeshPositionVertexBuffers();
return RpcLibAdaptorsBase::MeshPositionVertexBuffersResponse::from(response);
});
pimpl_->server.bind("simAddVehicle",
[&](const std::string &vehicle_name, const std::string &vehicle_type,
const RpcLibAdaptorsBase::Pose &pose, const std::string &pawn_path) -> bool {
return getWorldSimApi()->addVehicle(vehicle_name, vehicle_type, pose.to(), pawn_path);
});
pimpl_->server.bind(
"simSetVehiclePose",
[&](const RpcLibAdaptorsBase::Pose &pose, bool ignore_collision, const std::string &vehicle_name) -> void {
getVehicleSimApi(vehicle_name)->setPose(pose.to(), ignore_collision);
});
pimpl_->server.bind("simGetVehiclePose", [&](const std::string &vehicle_name) -> RpcLibAdaptorsBase::Pose {
const auto &pose = getVehicleSimApi(vehicle_name)->getPose();
return RpcLibAdaptorsBase::Pose(pose);
});
pimpl_->server.bind(
"simSetTraceLine",
[&](const std::vector<float> &color_rgba, float thickness, const std::string &vehicle_name) -> void {
getVehicleSimApi(vehicle_name)->setTraceLine(color_rgba, thickness);
});
pimpl_->server.bind("simSetSegmentationObjectID",
[&](const std::string &mesh_name, int object_id, bool is_name_regex) -> bool {
return getWorldSimApi()->setSegmentationObjectID(mesh_name, object_id, is_name_regex);
});
pimpl_->server.bind("simGetSegmentationObjectID", [&](const std::string &mesh_name) -> int {
return getWorldSimApi()->getSegmentationObjectID(mesh_name);
});
pimpl_->server.bind("simAddDetectionFilterMeshName",
[&](const std::string &camera_name, ImageCaptureBase::ImageType type,
const std::string &mesh_name, const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->addDetectionFilterMeshName(
type, mesh_name, CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simSetDetectionFilterRadius",
[&](const std::string &camera_name, ImageCaptureBase::ImageType type, const float radius_cm,
const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->setDetectionFilterRadius(
type, radius_cm, CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simClearDetectionMeshNames",
[&](const std::string &camera_name, ImageCaptureBase::ImageType type,
const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->clearDetectionMeshNames(
type, CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind(
"simGetDetections",
[&](const std::string &camera_name, ImageCaptureBase::ImageType type, const std::string &vehicle_name,
bool external) -> vector<RpcLibAdaptorsBase::DetectionInfo> {
const auto &response =
getWorldSimApi()->getDetections(type, CameraDetails(camera_name, vehicle_name, external));
return RpcLibAdaptorsBase::DetectionInfo::from(response);
});
pimpl_->server.bind("reset", [&]() -> void {
// Exit if already resetting.
static bool resetInProgress;
if (resetInProgress)
return;
// Reset
resetInProgress = true;
auto *sim_world_api = getWorldSimApi();
if (sim_world_api) {
sim_world_api->reset();
} else {
getVehicleApi("")->reset();
}
resetInProgress = false;
});
pimpl_->server.bind(
"simPrintLogMessage",
[&](const std::string &message, const std::string &message_param, unsigned char severity) -> void {
getWorldSimApi()->printLogMessage(message, message_param, severity);
});
pimpl_->server.bind("getHomeGeoPoint", [&](const std::string &vehicle_name) -> RpcLibAdaptorsBase::GeoPoint {
const auto &geo_point = getVehicleApi(vehicle_name)->getHomeGeoPoint();
return RpcLibAdaptorsBase::GeoPoint(geo_point);
});
pimpl_->server.bind(
"getLidarData",
[&](const std::string &lidar_name, const std::string &vehicle_name) -> RpcLibAdaptorsBase::LidarData {
const auto &lidar_data = getVehicleApi(vehicle_name)->getLidarData(lidar_name);
return RpcLibAdaptorsBase::LidarData(lidar_data);
});
pimpl_->server.bind(
"getImuData", [&](const std::string &imu_name, const std::string &vehicle_name) -> RpcLibAdaptorsBase::ImuData {
const auto &imu_data = getVehicleApi(vehicle_name)->getImuData(imu_name);
return RpcLibAdaptorsBase::ImuData(imu_data);
});
pimpl_->server.bind(
"getBarometerData",
[&](const std::string &barometer_name, const std::string &vehicle_name) -> RpcLibAdaptorsBase::BarometerData {
const auto &barometer_data = getVehicleApi(vehicle_name)->getBarometerData(barometer_name);
return RpcLibAdaptorsBase::BarometerData(barometer_data);
});
pimpl_->server.bind("getMagnetometerData",
[&](const std::string &magnetometer_name,
const std::string &vehicle_name) -> RpcLibAdaptorsBase::MagnetometerData {
const auto &magnetometer_data =
getVehicleApi(vehicle_name)->getMagnetometerData(magnetometer_name);
return RpcLibAdaptorsBase::MagnetometerData(magnetometer_data);
});
pimpl_->server.bind(
"getGpsData", [&](const std::string &gps_name, const std::string &vehicle_name) -> RpcLibAdaptorsBase::GpsData {
const auto &gps_data = getVehicleApi(vehicle_name)->getGpsData(gps_name);
return RpcLibAdaptorsBase::GpsData(gps_data);
});
pimpl_->server.bind("getDistanceSensorData",
[&](const std::string &distance_sensor_name,
const std::string &vehicle_name) -> RpcLibAdaptorsBase::DistanceSensorData {
const auto &distance_sensor_data =
getVehicleApi(vehicle_name)->getDistanceSensorData(distance_sensor_name);
return RpcLibAdaptorsBase::DistanceSensorData(distance_sensor_data);
});
pimpl_->server.bind("simGetCameraInfo",
[&](const std::string &camera_name, const std::string &vehicle_name,
bool external) -> RpcLibAdaptorsBase::CameraInfo {
const auto &camera_info =
getWorldSimApi()->getCameraInfo(CameraDetails(camera_name, vehicle_name, external));
return RpcLibAdaptorsBase::CameraInfo(camera_info);
});
pimpl_->server.bind("simSetDistortionParam",
[&](const std::string &camera_name, const std::string ¶m_name, float value,
const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->setDistortionParam(param_name, value,
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind(
"simGetDistortionParams",
[&](const std::string &camera_name, const std::string &vehicle_name, bool external) -> std::vector<float> {
return getWorldSimApi()->getDistortionParams(CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simSetCameraPose",
[&](const std::string &camera_name, const RpcLibAdaptorsBase::Pose &pose,
const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->setCameraPose(pose.to(),
CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind(
"simSetCameraFov",
[&](const std::string &camera_name, float fov_degrees, const std::string &vehicle_name, bool external) -> void {
getWorldSimApi()->setCameraFoV(fov_degrees, CameraDetails(camera_name, vehicle_name, external));
});
pimpl_->server.bind("simGetCollisionInfo",
[&](const std::string &vehicle_name) -> RpcLibAdaptorsBase::CollisionInfo {
const auto &collision_info = getVehicleSimApi(vehicle_name)->getCollisionInfoAndReset();
return RpcLibAdaptorsBase::CollisionInfo(collision_info);
});
pimpl_->server.bind("simListSceneObjects", [&](const std::string &name_regex) -> std::vector<string> {
return getWorldSimApi()->listSceneObjects(name_regex);
});
pimpl_->server.bind("simLoadLevel",
[&](const std::string &level_name) -> bool { return getWorldSimApi()->loadLevel(level_name); });
pimpl_->server.bind("simSpawnObject",
[&](string &object_name, const string &load_component, const RpcLibAdaptorsBase::Pose &pose,
const RpcLibAdaptorsBase::Vector3r &scale, bool physics_enabled,
bool is_blueprint) -> string {
return getWorldSimApi()->spawnObject(object_name, load_component, pose.to(), scale.to(),
physics_enabled, is_blueprint);
});
pimpl_->server.bind("simDestroyObject", [&](const string &object_name) -> bool {
return getWorldSimApi()->destroyObject(object_name);
});
pimpl_->server.bind("simListAssets", [&]() -> std::vector<std::string> { return getWorldSimApi()->listAssets(); });
pimpl_->server.bind("simGetObjectPose", [&](const std::string &object_name) -> RpcLibAdaptorsBase::Pose {
const auto &pose = getWorldSimApi()->getObjectPose(object_name);
return RpcLibAdaptorsBase::Pose(pose);
});
pimpl_->server.bind("simGetObjectScale", [&](const std::string &object_name) -> RpcLibAdaptorsBase::Vector3r {
const auto &scale = getWorldSimApi()->getObjectScale(object_name);
return RpcLibAdaptorsBase::Vector3r(scale);
});
pimpl_->server.bind(
"simSetObjectPose",
[&](const std::string &object_name, const RpcLibAdaptorsBase::Pose &pose, bool teleport) -> bool {
return getWorldSimApi()->setObjectPose(object_name, pose.to(), teleport);
});
pimpl_->server.bind("simSetObjectScale",
[&](const std::string &object_name, const RpcLibAdaptorsBase::Vector3r &scale) -> bool {
return getWorldSimApi()->setObjectScale(object_name, scale.to());
});
pimpl_->server.bind("simFlushPersistentMarkers", [&]() -> void { getWorldSimApi()->simFlushPersistentMarkers(); });
pimpl_->server.bind("simPlotPoints",
[&](const std::vector<RpcLibAdaptorsBase::Vector3r> &points, const vector<float> &color_rgba,
float size, float duration, bool is_persistent) -> void {
vector<Vector3r> conv_points;
RpcLibAdaptorsBase::to(points, conv_points);
getWorldSimApi()->simPlotPoints(conv_points, color_rgba, size, duration, is_persistent);
});
pimpl_->server.bind("simPlotLineStrip",
[&](const std::vector<RpcLibAdaptorsBase::Vector3r> &points, const vector<float> &color_rgba,
float thickness, float duration, bool is_persistent) -> void {
vector<Vector3r> conv_points;
RpcLibAdaptorsBase::to(points, conv_points);
getWorldSimApi()->simPlotLineStrip(conv_points, color_rgba, thickness, duration,
is_persistent);
});
pimpl_->server.bind("simPlotLineList",
[&](const std::vector<RpcLibAdaptorsBase::Vector3r> &points, const vector<float> &color_rgba,
float thickness, float duration, bool is_persistent) -> void {
vector<Vector3r> conv_points;
RpcLibAdaptorsBase::to(points, conv_points);
getWorldSimApi()->simPlotLineList(conv_points, color_rgba, thickness, duration,
is_persistent);
});
pimpl_->server.bind("simPlotArrows",
[&](const std::vector<RpcLibAdaptorsBase::Vector3r> &points_start,
const std::vector<RpcLibAdaptorsBase::Vector3r> &points_end,
const vector<float> &color_rgba, float thickness, float arrow_size, float duration,
bool is_persistent) -> void {
vector<Vector3r> conv_points_start;
RpcLibAdaptorsBase::to(points_start, conv_points_start);
vector<Vector3r> conv_points_end;
RpcLibAdaptorsBase::to(points_end, conv_points_end);
getWorldSimApi()->simPlotArrows(conv_points_start, conv_points_end, color_rgba, thickness,
arrow_size, duration, is_persistent);
});
pimpl_->server.bind("simPlotStrings",
[&](const std::vector<std::string> strings,
const std::vector<RpcLibAdaptorsBase::Vector3r> &positions, float scale,
const vector<float> &color_rgba, float duration) -> void {
vector<Vector3r> conv_positions;
RpcLibAdaptorsBase::to(positions, conv_positions);
getWorldSimApi()->simPlotStrings(strings, conv_positions, scale, color_rgba, duration);
});
pimpl_->server.bind("simPlotTransforms",
[&](const std::vector<RpcLibAdaptorsBase::Pose> &poses, float scale, float thickness,
float duration, bool is_persistent) -> void {
vector<Pose> conv_poses;
RpcLibAdaptorsBase::to(poses, conv_poses);
getWorldSimApi()->simPlotTransforms(conv_poses, scale, thickness, duration, is_persistent);
});
pimpl_->server.bind("simPlotTransformsWithNames",
[&](const std::vector<RpcLibAdaptorsBase::Pose> &poses, const std::vector<std::string> names,
float tf_scale, float tf_thickness, float text_scale, const vector<float> &text_color_rgba,
float duration) -> void {
vector<Pose> conv_poses;
RpcLibAdaptorsBase::to(poses, conv_poses);
getWorldSimApi()->simPlotTransformsWithNames(conv_poses, names, tf_scale, tf_thickness,
text_scale, text_color_rgba, duration);
});
pimpl_->server.bind(
"simGetGroundTruthKinematics", [&](const std::string &vehicle_name) -> RpcLibAdaptorsBase::KinematicsState {
const Kinematics::State &result = *getVehicleSimApi(vehicle_name)->getGroundTruthKinematics();
return RpcLibAdaptorsBase::KinematicsState(result);
});
pimpl_->server.bind("simSetKinematics", [&](const RpcLibAdaptorsBase::KinematicsState &state, bool ignore_collision,
const std::string &vehicle_name) {
getVehicleSimApi(vehicle_name)->setKinematics(state.to(), ignore_collision);
});
pimpl_->server.bind("simGetGroundTruthEnvironment",
[&](const std::string &vehicle_name) -> RpcLibAdaptorsBase::EnvironmentState {
const Environment::State &result =
(*getVehicleSimApi(vehicle_name)->getGroundTruthEnvironment()).getState();
return RpcLibAdaptorsBase::EnvironmentState(result);
});
pimpl_->server.bind("simCreateVoxelGrid",
[&](const RpcLibAdaptorsBase::Vector3r &position, const int &x, const int &y, const int &z,
const float &res, const std::string &output_file) -> bool {
return getWorldSimApi()->createVoxelGrid(position.to(), x, y, z, res, output_file);
});
pimpl_->server.bind("simSetLightIntensity", [&](const std::string &light_name, float intensity) -> bool {
return getWorldSimApi()->setLightIntensity(light_name, intensity);
});
pimpl_->server.bind("cancelLastTask", [&](const std::string &vehicle_name) -> void {
getVehicleApi(vehicle_name)->cancelLastTask();
});
pimpl_->server.bind(
"simSwapTextures",
[&](const std::string tag, int tex_id, int component_id, int material_id) -> std::vector<string> {
return *getWorldSimApi()->swapTextures(tag, tex_id, component_id, material_id);
});
pimpl_->server.bind(
"simSetObjectMaterial",
[&](const std::string &object_name, const std::string &material_name, const int component_id) -> bool {
return getWorldSimApi()->setObjectMaterial(object_name, material_name, component_id);
});
pimpl_->server.bind(
"simSetObjectMaterialFromTexture",
[&](const std::string &object_name, const std::string &texture_path, const int component_id) -> bool {
return getWorldSimApi()->setObjectMaterialFromTexture(object_name, texture_path, component_id);
});
pimpl_->server.bind("startRecording", [&]() -> void { getWorldSimApi()->startRecording(); });
pimpl_->server.bind("stopRecording", [&]() -> void { getWorldSimApi()->stopRecording(); });
pimpl_->server.bind("isRecording", [&]() -> bool { return getWorldSimApi()->isRecording(); });
pimpl_->server.bind(
"simSetWind", [&](const RpcLibAdaptorsBase::Vector3r &wind) -> void { getWorldSimApi()->setWind(wind.to()); });
pimpl_->server.bind("simSetExtForce", [&](const RpcLibAdaptorsBase::Vector3r &ext_force) -> void {
getWorldSimApi()->setExtForce(ext_force.to());
});
pimpl_->server.bind("listVehicles", [&]() -> vector<string> { return getWorldSimApi()->listVehicles(); });
pimpl_->server.bind("getSettingsString", [&]() -> std::string { return getWorldSimApi()->getSettingsString(); });
// if we don't suppress then server will bomb out for exceptions raised by any method
pimpl_->server.suppress_exceptions(true);
}
// required for pimpl
RpcLibServerBase::~RpcLibServerBase() { stop(); }
void RpcLibServerBase::start(bool block, std::size_t thread_count) { pimpl_->run(block, thread_count); }
void RpcLibServerBase::stop() { pimpl_->stop(); }
void *RpcLibServerBase::getServer() const { return &pimpl_->server; }
} // namespace autonomylib
} // namespace nervosys
#endif
#endif