9 #include <diagnostic_msgs/DiagnosticArray.h> 47 #define LOG_NXLIB_EXCEPTION(EXCEPTION) \ 50 if (EXCEPTION.getErrorCode() == NxLibExecutionFailed) \ 52 NxLibItem executionNode(EXCEPTION.getItemPath()); \ 53 ROS_ERROR("%s: %s", executionNode[itmResult][itmErrorSymbol].asString().c_str(), \ 54 executionNode[itmResult][itmErrorText].asString().c_str()); \ 60 ROS_DEBUG("Current NxLib tree: %s", NxLibItem().asJson(true).c_str()); 69 #define START_NXLIB_ACTION(ACTION_NAME, ACTION_SERVER) \ 70 ROS_DEBUG("Received a " #ACTION_NAME " request."); \ 71 auto& server = ACTION_SERVER; \ 72 if (server->isPreemptRequested()) \ 74 server->setPreempted(); \ 77 std::lock_guard<std::mutex> lock(nxLibMutex); \ 80 #define FINISH_NXLIB_ACTION(ACTION_NAME) \ 82 catch (NxLibException & e) \ 84 ROS_ERROR("NxLibException %d (%s) for item %s", e.getErrorCode(), e.getErrorText().c_str(), \ 85 e.getItemPath().c_str()); \ 86 LOG_NXLIB_EXCEPTION(e) \ 87 ensenso_camera_msgs::ACTION_NAME##Result result; \ 88 result.error.code = e.getErrorCode(); \ 89 result.error.message = e.getErrorText(); \ 90 server->setAborted(result); \ 93 catch (tf::TransformException & e) \ 95 ROS_ERROR("TF Exception: %s", e.what()); \ 96 ensenso_camera_msgs::ACTION_NAME##Result result; \ 97 result.error.code = ERROR_CODE_TF; \ 98 result.error.message = e.what(); \ 99 server->setAborted(result); \ 102 catch (std::exception & e) \ 104 ROS_ERROR("Unknown Exception: %s", e.what()); \ 105 ensenso_camera_msgs::ACTION_NAME##Result result; \ 106 result.error.code = ERROR_CODE_UNKNOWN_EXCEPTION; \ 107 result.error.message = e.what(); \ 108 server->setAborted(result); \ 112 #define PREEMPT_ACTION_IF_REQUESTED \ 113 if (server->isPreemptRequested()) \ 115 server->setPreempted(); \ 124 int nxLibMajor = NxLibItem()[itmVersion][itmMajor].asInt();
125 int nxLibMinor = NxLibItem()[itmVersion][itmMinor].asInt();
126 return (nxLibMajor > major) || (nxLibMajor == major && nxLibMinor >= minor);
133 node = NxLibItem()[
"rosParameterSets"][name];
134 node << defaultParameters;
138 std::string
const& cameraFrame, std::string
const& targetFrame, std::string
const& robotFrame,
139 std::string
const& wristFrame)
141 , fileCameraPath(fileCameraPath)
143 , cameraFrame(cameraFrame)
144 , targetFrame(targetFrame)
145 , robotFrame(robotFrame)
146 , wristFrame(wristFrame)
188 statusPublisher = nh.advertise<diagnostic_msgs::DiagnosticArray>(
"/diagnostics", 1);
208 NxLibCommand createCamera(cmdCreateCamera);
209 createCamera.parameters()[itmSerialNumber] =
serial;
211 createCamera.execute();
215 catch (NxLibException& e)
217 ROS_ERROR(
"Failed to create the file camera!");
236 NxLibCommand
open(cmdOpen);
237 open.parameters()[itmCameras] =
serial;
240 catch (NxLibException& e)
247 ROS_INFO(
"Opened camera with serial number '%s'.",
serial.c_str());
261 NxLibCommand
close(cmdClose);
262 close.parameters()[itmCameras] =
serial;
267 NxLibCommand deleteCmd(cmdDeleteCamera);
268 deleteCmd.parameters()[itmCameras] =
serial;
272 catch (NxLibException&)
296 if (jsonFile.empty())
299 std::ifstream file(jsonFile);
300 if (file.is_open() && file.rdbuf())
302 std::stringstream buffer;
303 buffer << file.rdbuf();
304 std::string
const& jsonSettings = buffer.str();
306 NxLibItem tmpParameters = NxLibItem()[
"rosTemporaryParameters"];
309 tmpParameters.setJson(jsonSettings);
311 catch (NxLibException&)
313 ROS_ERROR(
"The file '%s' does not contain valid JSON", jsonFile.c_str());
319 if (tmpParameters[itmParameters].
exists())
322 cameraNode[itmParameters] << tmpParameters[itmParameters];
327 cameraNode[itmParameters].setJson(jsonSettings,
true);
329 tmpParameters.erase();
331 NxLibCommand synchronize(cmdSynchronize);
332 synchronize.parameters()[itmCameras] =
serial;
333 synchronize.execute();
336 if (saveAsDefaultParameters)
339 catch (NxLibException& e)
347 ROS_ERROR(
"Could not open the file '%s'", jsonFile.c_str());
360 NxLibItem item(goal->path);
362 bool treeChanged =
false;
368 else if (goal->set_null)
373 else if (!goal->json_value.empty())
375 item.setJson(goal->json_value);
384 ensenso_camera_msgs::AccessTreeResult result;
386 result.exists =
false;
389 result.exists =
true;
391 result.json_value = item.asJson();
398 catch (NxLibException&)
414 NxLibCommand
command(goal->command);
415 command.parameters().setJson(goal->parameters);
418 ensenso_camera_msgs::ExecuteCommandResult result;
419 result.result = command.result().asJson();
430 NxLibCommand fitPrimitives(cmdFitPrimitive);
431 NxLibItem
const& primitives = fitPrimitives.parameters()[itmPrimitive];
433 int primitivesCount = 0;
434 for (
auto const& primitive : goal->primitives)
436 if (primitive.type == ensenso_camera_msgs::Primitive::SPHERE)
440 primitives[primitivesCount][itmCount] = primitive.count;
442 else if (primitive.type == ensenso_camera_msgs::Primitive::CYLINDER)
447 else if (primitive.type == ensenso_camera_msgs::Primitive::PLANE)
449 primitives[primitivesCount][itmCount] = primitive.count;
451 primitives[primitivesCount][itmType] = primitive.type;
453 primitives[primitivesCount][itmInlierFraction] = primitive.inlier_fraction_in;
458 NxLibItem
const& commandParameters = fitPrimitives.parameters();
459 if (goal->normal_radius)
461 commandParameters[itmNormal][itmRadius] = goal->normal_radius;
464 float const zeroThreshold = 10e-6;
465 if (!(std::abs(goal->region_of_interest.lower.x) < zeroThreshold &&
466 std::abs(goal->region_of_interest.lower.y) < zeroThreshold &&
467 std::abs(goal->region_of_interest.lower.z) < zeroThreshold))
471 if (!(std::abs(goal->region_of_interest.upper.x) < zeroThreshold &&
472 std::abs(goal->region_of_interest.upper.y) < zeroThreshold &&
473 std::abs(goal->region_of_interest.upper.z) < zeroThreshold))
478 if (goal->failure_probability != 0)
480 commandParameters[itmFailureProbability] = goal->failure_probability;
483 if (std::abs(goal->inlier_threshold) > zeroThreshold)
487 if (std::abs(goal->inlier_fraction) > zeroThreshold)
489 commandParameters[itmInlierFraction] = goal->inlier_fraction;
491 if (std::abs(goal->scaling) > zeroThreshold)
493 commandParameters[itmScaling] = goal->scaling;
495 if (goal->ransac_iterations != 0)
497 commandParameters[itmScaling] = goal->ransac_iterations;
500 fitPrimitives.execute();
502 ensenso_camera_msgs::FitPrimitiveResult result;
504 NxLibItem
const primitiveResults = fitPrimitives.result()[itmPrimitive];
505 if (primitiveResults.isArray())
507 result.primitives.reserve(primitiveResults.count());
508 for (
int primitiveCount = 0; primitiveCount < primitiveResults.count(); primitiveCount++)
510 NxLibItem
const& currentPrimitive = primitiveResults[primitiveCount];
511 ensenso_camera_msgs::Primitive primitive;
513 primitive.type = currentPrimitive[itmType].asString();
514 primitive.ransac_iterations = currentPrimitive[itmIterations].asInt();
515 primitive.inlier_count = currentPrimitive[itmInlierCount].asInt();
516 primitive.inlier_fraction_out = currentPrimitive[itmInlierFraction].asDouble();
517 primitive.score = currentPrimitive[itmScore].asDouble();
520 if (primitive.type == ensenso_camera_msgs::Primitive::PLANE)
526 else if (primitive.type == ensenso_camera_msgs::Primitive::SPHERE)
530 else if (primitive.type == ensenso_camera_msgs::Primitive::CYLINDER)
534 result.primitives.emplace_back(primitive);
547 ensenso_camera_msgs::GetParameterResult result;
552 for (
auto const& key : goal->keys)
566 ensenso_camera_msgs::SetParameterResult result;
570 result.parameter_file_applied =
false;
571 if (!goal->parameter_file.empty())
573 result.parameter_file_applied =
loadSettings(goal->parameter_file);
574 if (!result.parameter_file_applied)
576 server->setAborted(result);
581 bool projectorChanged =
false;
582 for (
auto const& parameter : goal->parameters)
586 if (parameter.key == parameter.PROJECTOR || parameter.key == parameter.FRONT_LIGHT)
588 projectorChanged =
true;
593 NxLibCommand synchronize(cmdSynchronize);
594 synchronize.parameters()[itmCameras] =
serial;
595 synchronize.execute();
603 for (
auto const& parameter : goal->parameters)
617 ensenso_camera_msgs::RequestDataResult result;
618 ensenso_camera_msgs::RequestDataFeedback feedback;
620 bool publishResults = goal->publish_results;
621 if (!goal->publish_results && !goal->include_results_in_response)
623 publishResults =
true;
626 bool requestPointCloud = goal->request_point_cloud || goal->request_depth_image;
627 if (!goal->request_raw_images && !goal->request_rectified_images && !goal->request_point_cloud &&
628 !goal->request_normals && !goal->request_depth_image)
630 requestPointCloud =
true;
633 bool computePointCloud = requestPointCloud || goal->request_normals;
634 bool computeDisparityMap = goal->request_disparity_map || computePointCloud;
641 feedback.images_acquired =
true;
644 if (goal->request_raw_images)
651 if (goal->include_results_in_response)
653 for (
auto const& imagePair : rawImages)
655 result.left_raw_images.push_back(*imagePair.first);
656 result.right_raw_images.push_back(*imagePair.second);
674 if (goal->request_rectified_images && !computeDisparityMap)
676 NxLibCommand rectify(cmdRectifyImages);
677 rectify.parameters()[itmCameras] =
serial;
680 else if (computeDisparityMap)
682 NxLibCommand computeDisparityMap(cmdComputeDisparityMap);
683 computeDisparityMap.parameters()[itmCameras] =
serial;
684 computeDisparityMap.execute();
687 if (goal->request_rectified_images)
694 if (goal->include_results_in_response)
696 for (
auto const& imagePair : rectifiedImages)
698 result.left_rectified_images.push_back(*imagePair.first);
699 result.right_rectified_images.push_back(*imagePair.second);
713 if (goal->request_disparity_map)
717 if (goal->include_results_in_response)
719 result.disparity_map = *disparityMap;
735 if (computePointCloud)
739 NxLibCommand computePointMap(cmdComputePointMap);
740 computePointMap.parameters()[itmCameras] =
serial;
741 computePointMap.execute();
743 if (requestPointCloud && !goal->request_normals)
747 if (goal->include_results_in_response)
757 if (goal->request_depth_image)
761 if (goal->include_results_in_response)
763 result.depth_image = *depthImage;
775 if (goal->request_normals)
777 NxLibCommand(cmdComputeNormals).execute();
782 if (goal->include_results_in_response)
801 ensenso_camera_msgs::LocatePatternResult result;
802 ensenso_camera_msgs::LocatePatternFeedback feedback;
806 int numberOfShots = goal->number_of_shots;
807 if (numberOfShots < 1)
812 std::vector<CalibrationPattern> patterns;
814 for (
int i = 0; i < numberOfShots; i++)
820 imageTimestamp = timestamp;
824 if (i == (numberOfShots - 1))
827 feedback.images_acquired =
true;
831 bool clearBuffer = (i == 0);
833 if (patterns.empty())
835 result.found_pattern =
false;
840 if (patterns.size() > 1)
848 result.found_pattern =
true;
849 result.patterns.resize(patterns.size());
850 for (
size_t i = 0; i < patterns.size(); i++)
852 patterns[i].writeToMessage(&result.patterns[i]);
858 if (!goal->target_frame.empty())
860 patternFrame = goal->target_frame;
863 result.frame = patternFrame;
865 if (patterns.size() > 1)
870 result.pattern_poses.resize(patternPoses.size());
871 for (
size_t i = 0; i < patternPoses.size(); i++)
882 result.pattern_poses.resize(1);
886 if (!goal->tf_frame.empty())
888 if (patterns.size() == 1)
895 ROS_WARN(
"Cannot publish the pattern pose in TF, because there are " 896 "multiple patterns!");
909 ensenso_camera_msgs::ProjectPatternResult result;
912 tf::poseMsgToTF(goal->target_frame_transformation, targetFrameTransformation);
928 NxLibItem()[itmParameters][itmPattern][itmGridSpacing] = goal->grid_spacing * 1000;
934 NxLibCommand projectPattern(cmdProjectPattern);
935 projectPattern.parameters()[itmCameras] =
serial;
936 projectPattern.parameters()[itmGridSpacing] = goal->grid_spacing * 1000;
937 projectPattern.parameters()[itmGridSize][0] = goal->grid_size_x;
938 projectPattern.parameters()[itmGridSize][1] = goal->grid_size_y;
940 projectPattern.execute();
944 int sensorWidth =
cameraNode[itmSensor][itmSize][0].asInt();
945 int sensorHeight =
cameraNode[itmSensor][itmSize][1].asInt();
947 NxLibItem projectedPoints = projectPattern.result()[itmStereo][0][itmPoints];
948 NxLibItem leftPoints = projectedPoints[0];
949 NxLibItem rightPoints = projectedPoints[1];
951 result.pattern_is_visible =
true;
952 result.left_points.resize(leftPoints.count());
953 result.right_points.resize(leftPoints.count());
954 for (
int i = 0; i < leftPoints.count(); i++)
956 double leftX = leftPoints[i][0].asDouble();
957 double leftY = leftPoints[i][1].asDouble();
958 double rightX = rightPoints[i][0].asDouble();
959 double rightY = rightPoints[i][1].asDouble();
961 result.left_points[i].x = leftX;
962 result.left_points[i].y = leftY;
963 result.right_points[i].x = rightX;
964 result.right_points[i].y = rightY;
966 if (leftX < 0 || leftX > sensorWidth || leftY < 0 || leftY > sensorHeight || rightX < 0 || rightX > sensorWidth ||
967 rightY < 0 || rightY > sensorHeight)
969 result.pattern_is_visible =
false;
982 ensenso_camera_msgs::CalibrateHandEyeResult result;
983 result.command = goal->command;
985 if (goal->command == goal->RESET)
990 else if (goal->command == goal->CAPTURE_PATTERN)
994 result.error_message =
"You need to specify a robot base and wrist frame " 995 "to do a hand eye calibration!";
996 ROS_ERROR(
"%s", result.error_message.c_str());
1010 NxLibCommand setPatternBuffer(cmdSetPatternBuffer);
1012 setPatternBuffer.execute();
1016 NxLibCommand(cmdDiscardPatterns).execute();
1020 if (patterns.empty())
1022 result.found_pattern =
false;
1026 if (patterns.size() > 1)
1028 result.error_message =
"Detected multiple calibration patterns during a " 1029 "hand eye calibration!";
1030 ROS_ERROR(
"%s", result.error_message.c_str());
1037 result.found_pattern =
true;
1038 patterns[0].writeToMessage(&result.pattern);
1052 result.error_message = std::string(
"Could not look up the robot pose due to the TF error: ") + e.what();
1053 ROS_ERROR(
"%s", result.error_message.c_str());
1059 NxLibCommand getPatternBuffer(cmdGetPatternBuffer);
1060 getPatternBuffer.execute();
1067 else if (goal->command == goal->START_CALIBRATION)
1071 result.error_message =
"You need collect at least 5 patterns before " 1072 "starting a hand eye calibration!";
1073 ROS_ERROR(
"%s", result.error_message.c_str());
1079 size_t numberOfPatterns = 0;
1080 NxLibCommand setPatternBuffer(cmdSetPatternBuffer);
1081 if (goal->pattern_observations.size() > 0)
1083 for (
size_t i = 0; i < goal->pattern_observations.size(); i++)
1087 NxLibItem patternNode = setPatternBuffer.parameters()[itmPatterns][i][
serial];
1096 numberOfPatterns = setPatternBuffer.parameters()[itmPatterns].count();
1097 setPatternBuffer.execute();
1101 if (goal->robot_poses.size() > 0)
1104 for (
auto const& pose : goal->robot_poses)
1108 robotPoses.push_back(tfPose);
1112 if (robotPoses.size() != numberOfPatterns)
1114 result.error_message =
"The number of pattern observations does not " 1115 "match the number of robot poses!";
1116 ROS_ERROR(
"%s", result.error_message.c_str());
1126 NxLibCommand calibrateHandEye(cmdCalibrateHandEye);
1127 calibrateHandEye.parameters()[itmSetup] =
fixed ? valFixed : valMoving;
1136 writePoseToNxLib(patternPose, calibrateHandEye.parameters()[itmPatternPose]);
1138 for (
size_t i = 0; i < robotPoses.size(); i++)
1140 writePoseToNxLib(robotPoses[i], calibrateHandEye.parameters()[itmTransformations][i]);
1143 calibrateHandEye.execute(
false);
1145 auto getCalibrationResidual = [](NxLibItem
const& node) {
1146 if (node[itmResidual].
exists())
1148 return node[itmResidual].asDouble();
1151 return node[itmReprojectionError].asDouble();
1155 while (!calibrateHandEye.finished())
1157 ensenso_camera_msgs::CalibrateHandEyeFeedback feedback;
1158 feedback.number_of_iterations = calibrateHandEye.result()[itmProgress][itmIterations].asInt();
1159 feedback.residual = getCalibrationResidual(calibrateHandEye.result()[itmProgress]);
1164 NxLibCommand(cmdBreak).execute();
1170 waitingRate.
sleep();
1173 result.calibration_time =
1174 calibrateHandEye.result()[itmTime].asDouble() / 1000;
1176 result.number_of_iterations = calibrateHandEye.result()[itmIterations].asInt();
1177 result.residual = getCalibrationResidual(calibrateHandEye.result());
1182 if (goal->write_calibration_to_eeprom)
1185 NxLibCommand storeCalibration(cmdStoreCalibration);
1186 storeCalibration.parameters()[itmCameras] =
serial;
1187 storeCalibration.parameters()[itmLink] =
true;
1188 storeCalibration.execute();
1203 ROS_WARN(
"You are performing a workspace calibration for a moving camera. " 1204 "Are you sure that this is what you want to do?");
1207 ensenso_camera_msgs::CalibrateWorkspaceResult result;
1208 result.successful =
true;
1212 int numberOfShots = goal->number_of_shots;
1213 if (numberOfShots < 1)
1219 for (
int i = 0; i < numberOfShots; i++)
1225 imageTimestamp = timestamp;
1229 bool clearBuffer = (i == 0);
1230 std::vector<CalibrationPattern> patterns =
collectPattern(clearBuffer);
1231 if (patterns.size() != 1)
1233 result.successful =
false;
1248 NxLibCommand calibrateWorkspace(cmdCalibrateWorkspace);
1249 calibrateWorkspace.parameters()[itmCameras] =
serial;
1250 writePoseToNxLib(patternTransformation, calibrateWorkspace.parameters()[itmPatternPose]);
1251 writePoseToNxLib(definedPatternPose, calibrateWorkspace.parameters()[itmDefinedPose]);
1253 calibrateWorkspace.execute();
1255 if (goal->write_calibration_to_eeprom)
1258 NxLibCommand storeCalibration(cmdStoreCalibration);
1259 storeCalibration.parameters()[itmCameras] =
serial;
1260 storeCalibration.parameters()[itmLink] =
true;
1261 storeCalibration.execute();
1272 cameraNode[itmStatus][itmAvailable].asBool();
1283 std::lock_guard<std::mutex> lock(
nxLibMutex);
1285 diagnostic_msgs::DiagnosticStatus cameraStatus;
1286 cameraStatus.name =
"Camera";
1287 cameraStatus.hardware_id =
serial;
1288 cameraStatus.level = diagnostic_msgs::DiagnosticStatus::OK;
1289 cameraStatus.message =
"OK";
1293 cameraStatus.level = diagnostic_msgs::DiagnosticStatus::ERROR;
1294 cameraStatus.message =
"Camera is no longer open";
1297 diagnostic_msgs::DiagnosticArray status;
1299 status.status.push_back(cameraStatus);
1317 parameterSet.
node.erase();
1320 if (projectorWasSet)
1333 ROS_DEBUG(
"Loading parameter set '%s'", name.c_str());
1344 bool changedParameters =
false;
1348 changedParameters =
true;
1357 cameraNode[itmParameters][itmCapture][itmProjector] =
true;
1358 cameraNode[itmParameters][itmCapture][itmFrontLight] =
false;
1362 cameraNode[itmParameters][itmCapture][itmProjector] =
false;
1363 cameraNode[itmParameters][itmCapture][itmFrontLight] =
true;
1365 changedParameters =
true;
1373 if (changedParameters)
1375 NxLibCommand synchronize(cmdSynchronize);
1376 synchronize.parameters()[itmCameras] =
serial;
1377 synchronize.execute();
1387 NxLibCommand
capture(cmdCapture);
1388 capture.parameters()[itmCameras] =
serial;
1391 NxLibItem imageNode =
cameraNode[itmImages][itmRaw];
1392 if (imageNode.isArray())
1394 imageNode = imageNode[0];
1396 imageNode = imageNode[itmLeft];
1405 NxLibCommand(cmdDiscardPatterns).execute();
1409 collectPattern.parameters()[itmCameras] =
serial;
1410 collectPattern.parameters()[itmDecodeData] =
true;
1411 collectPattern.parameters()[itmFilter][itmCameras] =
serial;
1412 collectPattern.parameters()[itmFilter][itmUseModel] =
true;
1413 collectPattern.parameters()[itmFilter][itmType] = valStatic;
1414 collectPattern.parameters()[itmFilter][itmValue] =
true;
1417 collectPattern.execute();
1419 catch (NxLibException& e)
1421 if (e.getErrorCode() == NxLibExecutionFailed)
1423 if (collectPattern.result()[itmErrorSymbol] == errPatternNotFound ||
1424 collectPattern.result()[itmErrorSymbol] == errPatternNotDecodable)
1432 if (!collectPattern.result()[itmStereo].exists())
1438 std::vector<CalibrationPattern> result;
1440 for (
int i = 0; i < collectPattern.result()[itmStereo].count(); i++)
1442 result.emplace_back(collectPattern.result()[itmStereo][i]);
1447 NxLibItem pattern = collectPattern.result()[itmPatterns][0][
serial];
1448 if (pattern[itmLeft].count() > 1 || pattern[itmRight].count() > 1)
1455 for (
size_t i = 0; i < result.size(); i++)
1457 for (
int j = 0; j < pattern[itmLeft][i][itmPoints].count(); j++)
1459 NxLibItem pointNode = pattern[itmLeft][i][itmPoints][j];
1461 ensenso_camera_msgs::ImagePoint point;
1462 point.x = pointNode[0].asDouble();
1463 point.y = pointNode[1].asDouble();
1464 result[i].leftPoints.push_back(point);
1466 for (
int j = 0; j < pattern[itmRight][i][itmPoints].count(); j++)
1468 NxLibItem pointNode = pattern[itmRight][i][itmPoints][j];
1470 ensenso_camera_msgs::ImagePoint point;
1471 point.x = pointNode[0].asDouble();
1472 point.y = pointNode[1].asDouble();
1473 result[i].rightPoints.push_back(point);
1481 bool latestPatternOnly)
const 1486 if (latestPatternOnly)
1488 estimatePatternPose.parameters()[itmAverage] =
false;
1490 int patternCount = NxLibItem()[itmParameters][itmPatternCount].asInt();
1491 estimatePatternPose.parameters()[itmFilter][itmOr][0][itmAnd][0][itmType] = valIndex;
1492 estimatePatternPose.parameters()[itmFilter][itmOr][0][itmAnd][0][itmValue] = patternCount - 1;
1496 estimatePatternPose.parameters()[itmAverage] =
true;
1498 estimatePatternPose.execute();
1500 ROS_ASSERT(estimatePatternPose.result()[itmPatterns].count() == 1);
1511 estimatePatternPose.parameters()[itmAverage] =
false;
1512 estimatePatternPose.parameters()[itmFilter][itmCameras] =
serial;
1513 estimatePatternPose.parameters()[itmFilter][itmUseModel] =
true;
1514 estimatePatternPose.parameters()[itmFilter][itmType] = valStatic;
1515 estimatePatternPose.parameters()[itmFilter][itmValue] =
true;
1516 estimatePatternPose.execute();
1518 int numberOfPatterns = estimatePatternPose.result()[itmPatterns].count();
1520 std::vector<tf::Stamped<tf::Pose>> result;
1521 result.reserve(numberOfPatterns);
1523 for (
int i = 0; i < numberOfPatterns; i++)
1585 info->width =
cameraNode[itmSensor][itmSize][0].asInt();
1586 info->height =
cameraNode[itmSensor][itmSize][1].asInt();
1588 NxLibItem monoCalibrationNode =
cameraNode[itmCalibration][itmMonocular][right ? itmRight : itmLeft];
1589 NxLibItem stereoCalibrationNode =
cameraNode[itmCalibration][itmStereo][right ? itmRight : itmLeft];
1599 info->D.resize(5, 0);
1604 for (
int row = 0; row < 3; row++)
1606 for (
int column = 0; column < 3; column++)
1608 info->P[4 * row + column] = stereoCalibrationNode[itmCamera][column][row].asDouble();
1612 info->K[3 * row + column] = 1;
1613 info->R[3 * row + column] = 1;
1622 for (
int i = 0; i < 5; i++)
1624 info->D.push_back(monoCalibrationNode[itmDistortion][i].asDouble());
1630 for (
int row = 0; row < 3; row++)
1632 for (
int column = 0; column < 3; column++)
1634 info->K[3 * row + column] = monoCalibrationNode[itmCamera][column][row].asDouble();
1635 info->P[4 * row + column] = stereoCalibrationNode[itmCamera][column][row].asDouble();
1637 info->R[3 * row + column] = stereoCalibrationNode[itmRotation][column][row].asDouble();
1646 double fx = stereoCalibrationNode[itmCamera][0][0].asDouble();
1647 double baseline =
cameraNode[itmCalibration][itmStereo][itmBaseline].asDouble() / 1000.0;
1648 info->P[3] = -fx * baseline;
1651 info->binning_x =
cameraNode[itmParameters][itmCapture][itmBinning].asInt();
1652 info->binning_y = info->binning_x;
1654 int leftTopX =
cameraNode[itmParameters][itmDisparityMap][itmAreaOfInterest][itmLeftTop][0].asInt();
1655 int leftTopY =
cameraNode[itmParameters][itmDisparityMap][itmAreaOfInterest][itmLeftTop][1].asInt();
1656 int rightBottomX =
cameraNode[itmParameters][itmDisparityMap][itmAreaOfInterest][itmRightBottom][0].asInt();
1657 int rightBottomY =
cameraNode[itmParameters][itmDisparityMap][itmAreaOfInterest][itmRightBottom][1].asInt();
1658 info->roi.x_offset = leftTopX;
1659 info->roi.y_offset = leftTopY;
1660 info->roi.width = rightBottomX - leftTopX;
1661 info->roi.height = rightBottomY - leftTopY;
1664 info->roi.do_rectify =
true;
1678 auto message = boost::make_shared<ensenso_camera_msgs::Parameter>();
1681 if (key == ensenso_camera_msgs::Parameter::REGION_OF_INTEREST)
1685 message->region_of_interest_value.lower.x = roi.
minX;
1686 message->region_of_interest_value.lower.y = roi.
minY;
1687 message->region_of_interest_value.lower.z = roi.
minZ;
1688 message->region_of_interest_value.upper.x = roi.
maxX;
1689 message->region_of_interest_value.upper.y = roi.
maxY;
1690 message->region_of_interest_value.upper.z = roi.
maxZ;
1692 else if (key == ensenso_camera_msgs::Parameter::FLEX_VIEW)
1694 NxLibItem flexViewNode =
cameraNode[itmParameters][itmCapture][itmFlexView];
1696 if (!flexViewNode.exists())
1698 message->float_value = -1;
1700 else if (flexViewNode.isNumber())
1702 message->float_value = flexViewNode.asInt();
1706 message->float_value = 0;
1718 switch (parameterMapping.
type)
1721 message->bool_value = node.asBool();
1724 message->float_value = node.asDouble();
1727 message->string_value = node.asString();
1733 ROS_WARN(
"Reading the parameter %s, but the camera does not support it!", key.c_str());
1738 ROS_ERROR(
"Unknown parameter '%s'!", key.c_str());
1746 if (parameter.key == ensenso_camera_msgs::Parameter::REGION_OF_INTEREST)
1750 roi.
minX = parameter.region_of_interest_value.lower.x;
1751 roi.
minY = parameter.region_of_interest_value.lower.y;
1752 roi.
minZ = parameter.region_of_interest_value.lower.z;
1753 roi.
maxX = parameter.region_of_interest_value.upper.x;
1754 roi.
maxY = parameter.region_of_interest_value.upper.y;
1755 roi.
maxZ = parameter.region_of_interest_value.upper.z;
1759 else if (parameter.key == ensenso_camera_msgs::Parameter::FLEX_VIEW)
1761 NxLibItem flexViewNode =
cameraNode[itmParameters][itmCapture][itmFlexView];
1763 if (!flexViewNode.exists())
1765 ROS_WARN(
"Writing the parameter FlexView, but the camera does not " 1770 int n =
static_cast<int>(std::round(parameter.float_value));
1773 flexViewNode =
false;
1789 ROS_WARN(
"Writing the parameter %s, but the camera does not support it!", parameter.key.c_str());
1793 switch (parameterMapping.
type)
1796 node.set<
bool>(parameter.bool_value);
1799 node.set<
double>(parameter.float_value);
1802 node.set<std::string>(parameter.string_value);
1807 ROS_ERROR(
"Unknown parameter '%s'!", parameter.key.c_str());
sensor_msgs::ImagePtr imageFromNxLibNode(NxLibItem const &node, std::string const &frame)
std::vector< tf::Pose > handEyeCalibrationRobotPoses
std::map< std::string, ParameterSet > parameterSets
static void poseMsgToTF(const geometry_msgs::Pose &msg, Pose &bt)
image_transport::CameraPublisher leftRectifiedImagePublisher
void onFitPrimitive(ensenso_camera_msgs::FitPrimitiveGoalConstPtr const &goal)
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
std::unique_ptr< FitPrimitiveServer > fitPrimitiveServer
std::vector< CalibrationPattern > collectPattern(bool clearBuffer=false) const
void publish(const boost::shared_ptr< M > &message) const
NxLibItem toEnsensoPoint(geometry_msgs::Point32 const &point, bool convertUnits=true)
std::string const DEFAULT_PARAMETER_SET
bool parameterExists(std::string const &key)
std::vector< std::pair< sensor_msgs::ImagePtr, sensor_msgs::ImagePtr > > imagesFromNxLibNode(NxLibItem const &node, std::string const &frame)
ros::Time timestampFromNxLibNode(NxLibItem const &node)
void onCalibrateHandEye(ensenso_camera_msgs::CalibrateHandEyeGoalConstPtr const &goal)
double const TRANSFORMATION_REQUEST_TIMEOUT
std::map< std::string, ParameterMapping > const parameterInformation
static void poseStampedTFToMsg(const Stamped< Pose > &bt, geometry_msgs::PoseStamped &msg)
image_transport::CameraPublisher leftRawImagePublisher
tf::TransformBroadcaster transformBroadcaster
std::vector< tf::Stamped< tf::Pose > > estimatePatternPoses(ros::Time imageTimestamp=ros::Time::now(), std::string const &targetFrame="") const
NxLibItem node(NxLibItem const &cameraNode)
void publishStatus(ros::TimerEvent const &event) const
ros::Publisher statusPublisher
NxLibItem defaultParameters
std::unique_ptr< RequestDataServer > requestDataServer
bool cameraIsOpen() const
Camera(ros::NodeHandle nh, std::string const &serial, std::string const &fileCameraPath, bool fixed, std::string const &cameraFrame, std::string const &targetFrame, std::string const &robotFrame, std::string const &wristFrame)
void fillCameraInfoFromNxLib(sensor_msgs::CameraInfoPtr const &info, bool right, bool rectified=false) const
#define START_NXLIB_ACTION(ACTION_NAME, ACTION_SERVER)
image_transport::CameraPublisher rightRawImagePublisher
image_transport::Publisher disparityMapPublisher
void writeToNxLib(NxLibItem const &node, bool right=false)
ros::Publisher pointCloudPublisher
sensor_msgs::CameraInfoPtr leftCameraInfo
geometry_msgs::Point32 toRosPoint(NxLibItem const &itemArray, bool convertUnits=true)
void writePoseToNxLib(tf::Pose const &pose, NxLibItem const &node)
void onCalibrateWorkspace(ensenso_camera_msgs::CalibrateWorkspaceGoalConstPtr const &goal)
std::unique_ptr< SetParameterServer > setParameterServer
std::string handEyeCalibrationPatternBuffer
void loadParameterSet(std::string name, ProjectorState projector=projectorDontCare)
std::unique_ptr< LocatePatternServer > locatePatternServer
#define LOG_NXLIB_EXCEPTION(EXCEPTION)
ROSLIB_DECL std::string command(const std::string &cmd)
void publish(const sensor_msgs::Image &message) const
void updateTransformations(ros::Time time=ros::Time::now(), std::string targetFrame="", bool useCachedTransformation=false) const
int const ERROR_CODE_UNKNOWN_EXCEPTION
void onRequestData(ensenso_camera_msgs::RequestDataGoalConstPtr const &goal)
TFSIMD_FORCE_INLINE Quaternion inverse(const Quaternion &q)
const std::string PLUMB_BOB
void onGetParameter(ensenso_camera_msgs::GetParameterGoalConstPtr const &goal)
void onAccessTree(ensenso_camera_msgs::AccessTreeGoalConstPtr const &goal)
pcl::PointCloud< pcl::PointXYZ >::Ptr pointCloudFromNxLib(NxLibItem const &node, std::string const &frame, PointCloudROI const *roi=0)
void writeParameter(ensenso_camera_msgs::Parameter const ¶meter)
#define PREEMPT_ACTION_IF_REQUESTED
void saveParameterSet(std::string name, bool projectorWritten=false)
bool poseIsValid(tf::Pose const &transform)
void onSetParameter(ensenso_camera_msgs::SetParameterGoalConstPtr const &goal)
image_transport::CameraPublisher rightRectifiedImagePublisher
std::string fileCameraPath
sensor_msgs::CameraInfoPtr rightCameraInfo
std::unique_ptr< ExecuteCommandServer > executeCommandServer
tf::StampedTransform transformFromPose(geometry_msgs::PoseStamped const &pose, std::string const &childFrame)
std::unique_ptr< CalibrateWorkspaceServer > calibrateWorkspaceServer
pcl::PointCloud< pcl::PointNormal >::Ptr pointCloudWithNormalsFromNxLib(NxLibItem const &pointMapNode, NxLibItem const &normalNode, std::string const &frame, PointCloudROI const *roi=0)
tf::Stamped< tf::Pose > estimatePatternPose(ros::Time imageTimestamp=ros::Time::now(), std::string const &targetFrame="", bool latestPatternOnly=false) const
void startServers() const
sensor_msgs::ImagePtr depthImageFromNxLibNode(NxLibItem const &node, std::string const &frame)
bool cameraIsAvailable() const
static void poseTFToMsg(const Pose &bt, geometry_msgs::Pose &msg)
void onExecuteCommand(ensenso_camera_msgs::ExecuteCommandGoalConstPtr const &goal)
tf::Pose poseFromNxLib(NxLibItem const &node)
void onProjectPattern(ensenso_camera_msgs::ProjectPatternGoalConstPtr const &goal)
tf::TransformListener transformListener
void onLocatePattern(ensenso_camera_msgs::LocatePatternGoalConstPtr const &goal)
const int conversionFactor
ParameterSet(std::string const &name, NxLibItem const &defaultParameters)
void saveDefaultParameterSet()
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
std::unique_ptr< AccessTreeServer > accessTreeServer
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
std::unique_ptr< GetParameterServer > getParameterServer
sensor_msgs::CameraInfoPtr leftRectifiedCameraInfo
bool checkNxLibVersion(int major, int minor)
std::map< std::string, tf::StampedTransform > transformationCache
double const STATUS_INTERVAL
ensenso_camera_msgs::ParameterPtr readParameter(std::string const &key) const
std::string currentParameterSet
sensor_msgs::CameraInfoPtr rightRectifiedCameraInfo
std::unique_ptr< ProjectPatternServer > projectPatternServer
std::unique_ptr< CalibrateHandEyeServer > calibrateHandEyeServer
bool loadSettings(std::string const &jsonFile, bool saveAsDefaultParameters=false)
#define FINISH_NXLIB_ACTION(ACTION_NAME)
std::string const TARGET_FRAME_LINK
ros::Time capture() const
image_transport::CameraPublisher depthImagePublisher