33 #ifndef RC_PICK_CLIENT_JSON_CONVERSIONS_H 34 #define RC_PICK_CLIENT_JSON_CONVERSIONS_H 38 #include <rc_common_msgs/ReturnCode.h> 40 #include <rc_pick_client/Box.h> 41 #include <rc_pick_client/Item.h> 42 #include <rc_pick_client/ItemModel.h> 43 #include <rc_pick_client/LoadCarrier.h> 44 #include <rc_pick_client/LoadCarrierWithFillingLevel.h> 45 #include <rc_pick_client/SuctionGrasp.h> 46 #include <rc_pick_client/RegionOfInterest.h> 47 #include <rc_pick_client/Compartment.h> 48 #include <rc_pick_client/CellFillingLevel.h> 49 #include <rc_pick_client/GridSize.h> 50 #include <rc_pick_client/RangeValue.h> 52 #include <rc_pick_client/DetectLoadCarriers.h> 53 #include <rc_pick_client/DeleteLoadCarriers.h> 54 #include <rc_pick_client/DeleteRegionsOfInterest.h> 55 #include <rc_pick_client/GetLoadCarriers.h> 56 #include <rc_pick_client/GetRegionsOfInterest.h> 57 #include <rc_pick_client/SetLoadCarrier.h> 58 #include <rc_pick_client/SetRegionOfInterest.h> 59 #include <rc_pick_client/ComputeGrasps.h> 60 #include <rc_pick_client/ComputeBoxGrasps.h> 61 #include <rc_pick_client/DetectItems.h> 62 #include <rc_pick_client/DetectFillingLevel.h> 68 j.at(
"value").get_to(r.value);
69 j.at(
"message").get_to(r.message);
85 j.at(
"x").get_to(r.x);
86 j.at(
"y").get_to(r.y);
87 j.at(
"z").get_to(r.z);
92 j[
"min_dimensions"] = r.min_dimensions;
93 j[
"max_dimensions"] = r.max_dimensions;
98 j.at(
"min_dimensions").get_to(r.min_dimensions);
99 j.at(
"max_dimensions").get_to(r.max_dimensions);
110 j.at(
"x").get_to(r.x);
111 j.at(
"y").get_to(r.y);
116 j[
"min_dimensions"] = r.min_dimensions;
117 j[
"max_dimensions"] = r.max_dimensions;
122 j.at(
"min_dimensions").get_to(r.min_dimensions);
123 j.at(
"max_dimensions").get_to(r.max_dimensions);
134 j.at(
"x").get_to(r.x);
135 j.at(
"y").get_to(r.y);
147 j.at(
"min").get_to(r.min);
148 j.at(
"max").get_to(r.max);
149 j.at(
"mean").get_to(r.mean);
154 j[
"cell_size"] = r.cell_size;
155 j[
"cell_position"] = r.cell_position;
156 j[
"level_in_percent"] = r.level_in_percent;
157 j[
"level_free_in_meters"] = r.level_free_in_meters;
158 j[
"coverage"] = r.coverage;
163 j.at(
"cell_size").get_to(r.cell_size);
164 j.at(
"cell_position").get_to(r.cell_position);
165 j.at(
"level_in_percent").get_to(r.level_in_percent);
166 j.at(
"level_free_in_meters").get_to(r.level_free_in_meters);
167 j.at(
"coverage").get_to(r.coverage);
172 j.at(
"uuid").get_to(r.uuid);
173 j.at(
"item_uuid").get_to(r.item_uuid);
174 j.at(
"pose").get_to(r.pose.pose);
175 j.at(
"timestamp").get_to(r.pose.header.stamp);
176 j.at(
"pose_frame").get_to(r.pose.header.frame_id);
177 j.at(
"quality").get_to(r.quality);
178 j.at(
"max_suction_surface_length").get_to(r.max_suction_surface_length);
179 j.at(
"max_suction_surface_width").get_to(r.max_suction_surface_width);
185 if (r.type == r.UNKNOWN)
187 j[
"unknown"] = r.unknown;
189 else if (r.type == r.RECTANGLE)
191 j[
"rectangle"] = r.rectangle;
197 j.at(
"uuid").get_to(r.uuid);
198 j.at(
"grasp_uuids").get_to(r.grasp_uuids);
199 j.at(
"type").get_to(r.type);
200 j.at(
"rectangle").get_to(r.rectangle);
201 j.at(
"pose").get_to(r.pose.pose);
202 j.at(
"timestamp").get_to(r.pose.header.stamp);
203 j.at(
"pose_frame").get_to(r.pose.header.frame_id);;
209 j[
"outer_dimensions"] = r.outer_dimensions;
210 j[
"inner_dimensions"] = r.inner_dimensions;
211 j[
"rim_thickness"] = r.rim_thickness;
212 j[
"pose"] = r.pose.pose;
213 j[
"pose_frame"] = r.pose.header.frame_id;
219 j.at(
"id").get_to(r.id);
220 j.at(
"outer_dimensions").get_to(r.outer_dimensions);
221 j.at(
"inner_dimensions").get_to(r.inner_dimensions);
222 j.at(
"rim_thickness").get_to(r.rim_thickness);
223 j.at(
"pose").get_to(r.pose.pose);
224 j.at(
"pose_frame").get_to(r.pose.header.frame_id);
226 if (j.count(
"overfilled"))
227 j.at(
"overfilled").get_to(r.overfilled);
232 j.at(
"id").get_to(r.id);
233 j.at(
"outer_dimensions").get_to(r.outer_dimensions);
234 j.at(
"inner_dimensions").get_to(r.inner_dimensions);
235 j.at(
"rim_thickness").get_to(r.rim_thickness);
236 j.at(
"pose").get_to(r.pose.pose);
237 j.at(
"pose_frame").get_to(r.pose.header.frame_id);
239 j.at(
"overfilled").get_to(r.overfilled);
240 j.at(
"overall_filling_level").get_to(r.overall_filling_level);
241 j.at(
"cells_filling_levels").get_to(r.cells_filling_levels);
242 j.at(
"filling_level_cell_count").get_to(r.filling_level_cell_count);
254 if (r.primitive.type == shape_msgs::SolidPrimitive::BOX)
257 if (r.primitive.dimensions.size() != 3)
259 throw std::runtime_error(
"Solid primitive of type \"box\" needs 3 dimensions.");
261 j[
"box"][
"x"] = r.primitive.dimensions[shape_msgs::SolidPrimitive::BOX_X];
262 j[
"box"][
"y"] = r.primitive.dimensions[shape_msgs::SolidPrimitive::BOX_Y];
263 j[
"box"][
"z"] = r.primitive.dimensions[shape_msgs::SolidPrimitive::BOX_Z];
265 else if (r.primitive.type == shape_msgs::SolidPrimitive::SPHERE)
267 j[
"type"] =
"SPHERE";
268 if (r.primitive.dimensions.size() != 1)
270 throw std::runtime_error(
"Solid primitive of type \"sphere\" needs 1 dimension.");
272 j[
"sphere"][
"radius"] = r.primitive.dimensions[shape_msgs::SolidPrimitive::BOX_X];
276 throw std::runtime_error(
"Type of solid primitive has to be of type \"box\" or \"sphere\"");
278 j[
"pose"] = r.pose.pose;
279 j[
"pose_frame"] = r.pose.header.frame_id;
284 j.at(
"id").get_to(r.id);
285 if (j.at(
"type") ==
"BOX")
287 r.primitive.type = shape_msgs::SolidPrimitive::BOX;
288 r.primitive.dimensions.resize(3);
289 r.primitive.dimensions[shape_msgs::SolidPrimitive::BOX_X] = j.at(
"box").at(
"x");
290 r.primitive.dimensions[shape_msgs::SolidPrimitive::BOX_Y] = j.at(
"box").at(
"y");
291 r.primitive.dimensions[shape_msgs::SolidPrimitive::BOX_Z] = j.at(
"box").at(
"z");
293 else if (j.at(
"type") ==
"SPHERE")
295 r.primitive.type = shape_msgs::SolidPrimitive::SPHERE;
296 r.primitive.dimensions.resize(1);
297 r.primitive.dimensions[shape_msgs::SolidPrimitive::BOX_X] = j.at(
"sphere").at(
"radius");
301 throw std::runtime_error(
"Type has to be \"BOX\" or \"SPHERE\"");
303 j.at(
"pose").get_to(r.pose.pose);
304 j.at(
"pose_frame").get_to(r.pose.header.frame_id);
309 j[
"gripper_id"] = r.gripper_id;
310 if (r.pre_grasp_offset.x != 0 || r.pre_grasp_offset.y != 0 || r.pre_grasp_offset.z != 0)
312 j[
"pre_grasp_offset"] = r.pre_grasp_offset;
320 j[
"load_carrier"] = r.load_carrier;
325 j.at(
"return_code").get_to(r.return_code);
330 j[
"load_carrier_ids"] = r.load_carrier_ids;
335 j.at(
"load_carriers").get_to(r.load_carriers);
336 j.at(
"return_code").get_to(r.return_code);
341 j[
"load_carrier_ids"] = r.load_carrier_ids;
346 j.at(
"return_code").get_to(r.return_code);
351 j[
"pose_frame"] = r.pose_frame;
352 j[
"region_of_interest_id"] = r.region_of_interest_id;
353 j[
"load_carrier_ids"] = r.load_carrier_ids;
354 if (r.pose_frame ==
"external")
356 j[
"robot_pose"] = r.robot_pose;
362 j.at(
"timestamp").get_to(r.timestamp);
363 j.at(
"load_carriers").get_to(r.load_carriers);
364 for (
auto lc : r.load_carriers)
366 j.at(
"timestamp").get_to(lc.pose.header.stamp);
368 j.at(
"return_code").get_to(r.return_code);
373 j[
"region_of_interest"] = r.region_of_interest;
374 j[
"pose_frame"] = r.region_of_interest.pose.header.frame_id;
375 if (r.region_of_interest.pose.header.frame_id ==
"external")
377 j[
"robot_pose"] = r.robot_pose;
383 j.at(
"return_code").get_to(r.return_code);
388 j[
"region_of_interest_ids"] = r.region_of_interest_ids;
393 j.at(
"regions_of_interest").get_to(r.regions_of_interest);
394 j.at(
"return_code").get_to(r.return_code);
399 j[
"load_carrier_ids"] = r.region_of_interest_ids;
404 j.at(
"return_code").get_to(r.return_code);
409 j[
"pose_frame"] = r.pose_frame;
410 if (r.pose_frame ==
"external")
412 j[
"robot_pose"] = r.robot_pose;
414 if (!r.region_of_interest_id.empty())
416 j[
"region_of_interest_id"] = r.region_of_interest_id;
418 if (!r.load_carrier_id.empty())
420 j[
"load_carrier_id"] = r.load_carrier_id;
421 j[
"load_carrier_compartment"] = r.load_carrier_compartment;
423 j[
"item_models"] = r.item_models;
424 j[
"suction_surface_length"] = r.suction_surface_length;
425 j[
"suction_surface_width"] = r.suction_surface_width;
426 if (!r.collision_detection.gripper_id.empty())
428 j[
"collision_detection"] = r.collision_detection;
434 j.at(
"timestamp").get_to(r.timestamp);
435 j.at(
"load_carriers").get_to(r.load_carriers);
436 j.at(
"grasps").get_to(r.grasps);
437 j.at(
"return_code").get_to(r.return_code);
442 j[
"pose_frame"] = r.pose_frame;
443 if (r.pose_frame ==
"external")
445 j[
"robot_pose"] = r.robot_pose;
447 if (!r.region_of_interest_id.empty())
449 j[
"region_of_interest_id"] = r.region_of_interest_id;
451 if (!r.load_carrier_id.empty())
453 j[
"load_carrier_id"] = r.load_carrier_id;
454 j[
"load_carrier_compartment"] = r.load_carrier_compartment;
456 if (!r.item_models.empty())
458 j[
"item_models"] = r.item_models;
460 j[
"suction_surface_length"] = r.suction_surface_length;
461 j[
"suction_surface_width"] = r.suction_surface_width;
462 if (!r.collision_detection.gripper_id.empty())
464 j[
"collision_detection"] = r.collision_detection;
470 j.at(
"timestamp").get_to(r.timestamp);
471 j.at(
"load_carriers").get_to(r.load_carriers);
472 j.at(
"items").get_to(r.items);
473 j.at(
"grasps").get_to(r.grasps);
474 j.at(
"return_code").get_to(r.return_code);
479 j[
"item_models"] = r.item_models;
480 j[
"pose_frame"] = r.pose_frame;
481 if (r.pose_frame ==
"external")
483 j[
"robot_pose"] = r.robot_pose;
485 if (!r.region_of_interest_id.empty())
487 j[
"region_of_interest_id"] = r.region_of_interest_id;
489 if (!r.load_carrier_id.empty())
491 j[
"load_carrier_id"] = r.load_carrier_id;
492 j[
"load_carrier_compartment"] = r.load_carrier_compartment;
498 j.at(
"timestamp").get_to(r.timestamp);
499 j.at(
"load_carriers").get_to(r.load_carriers);
500 j.at(
"items").get_to(r.items);
501 j.at(
"return_code").get_to(r.return_code);
506 j[
"pose_frame"] = r.pose_frame;
507 j[
"region_of_interest_id"] = r.region_of_interest_id;
508 j[
"load_carrier_ids"] = r.load_carrier_ids;
509 if (r.pose_frame ==
"external")
511 j[
"robot_pose"] = r.robot_pose;
513 j[
"filling_level_cell_count"] = r.filling_level_cell_count;
518 j.at(
"timestamp").get_to(r.timestamp);
519 j.at(
"load_carriers").get_to(r.load_carriers);
520 for (
auto lc : r.load_carriers)
522 j.at(
"timestamp").get_to(lc.pose.header.stamp);
524 j.at(
"return_code").get_to(r.return_code);
529 #endif // RC_PICK_CLIENT_JSON_CONVERSIONS_H
void to_json(nlohmann::json &j, const DetectFillingLevelRequest &r)
void from_json(const nlohmann::json &j, ReturnCode &r)