3 #include "ensenso_camera_msgs/AccessTreeAction.h" 4 #include "ensenso_camera_msgs/CalibrateHandEyeAction.h" 5 #include "ensenso_camera_msgs/CalibrateWorkspaceAction.h" 6 #include "ensenso_camera_msgs/ExecuteCommandAction.h" 7 #include "ensenso_camera_msgs/FitPrimitiveAction.h" 8 #include "ensenso_camera_msgs/GetParameterAction.h" 9 #include "ensenso_camera_msgs/SetParameterAction.h" 21 #include <sensor_msgs/CameraInfo.h> 25 #include <geometry_msgs/TransformStamped.h> 27 #include <diagnostic_msgs/DiagnosticArray.h> 69 #define LOG_NXLIB_EXCEPTION(EXCEPTION) \ 72 if (EXCEPTION.getErrorCode() == NxLibExecutionFailed) \ 74 NxLibItem executionNode(EXCEPTION.getItemPath()); \ 75 ROS_ERROR("%s: %s", executionNode[itmResult][itmErrorSymbol].asString().c_str(), \ 76 executionNode[itmResult][itmErrorText].asString().c_str()); \ 82 ROS_DEBUG("Current NxLib tree: %s", NxLibItem().asJson(true).c_str()); 91 #define START_NXLIB_ACTION(ACTION_NAME, ACTION_SERVER) \ 92 ROS_DEBUG("Received a " #ACTION_NAME " request."); \ 93 auto& server = ACTION_SERVER; \ 94 if (server->isPreemptRequested()) \ 96 server->setPreempted(); \ 99 std::lock_guard<std::mutex> lock(nxLibMutex); \ 102 #define FINISH_NXLIB_ACTION(ACTION_NAME) \ 104 catch (NxLibException & e) \ 106 ROS_ERROR("NxLibException %d (%s) for item %s", e.getErrorCode(), e.getErrorText().c_str(), \ 107 e.getItemPath().c_str()); \ 108 LOG_NXLIB_EXCEPTION(e) \ 109 ensenso_camera_msgs::ACTION_NAME##Result result; \ 110 result.error.code = e.getErrorCode(); \ 111 result.error.message = e.getErrorText(); \ 112 server->setAborted(result); \ 115 catch (tf2::TransformException & e) \ 117 ROS_ERROR("TF Exception: %s", e.what()); \ 118 ensenso_camera_msgs::ACTION_NAME##Result result; \ 119 result.error.code = ERROR_CODE_TF; \ 120 result.error.message = e.what(); \ 121 server->setAborted(result); \ 124 catch (std::exception & e) \ 126 ROS_ERROR("Unknown Exception: %s", e.what()); \ 127 ensenso_camera_msgs::ACTION_NAME##Result result; \ 128 result.error.code = ERROR_CODE_UNKNOWN_EXCEPTION; \ 129 result.error.message = e.what(); \ 130 server->setAborted(result); \ 134 #define PREEMPT_ACTION_IF_REQUESTED \ 135 if (server->isPreemptRequested()) \ 137 server->setPreempted(); \ 176 ParameterSet(std::string
const& name, NxLibItem
const& defaultParameters);
186 bool createdFileCamera =
false;
229 Camera(
ros::NodeHandle const& n, std::string serial, std::string fileCameraPath,
bool fixed, std::string cameraFrame,
230 std::string targetFrame, std::string linkFrame);
238 virtual void initTfPublishTimer();
243 virtual void initStatusTimer();
249 virtual void startServers()
const;
258 bool loadSettings(std::string
const& jsonFile,
bool saveAsDefaultParameters =
false);
263 void onAccessTree(ensenso_camera_msgs::AccessTreeGoalConstPtr
const& goal);
268 void onExecuteCommand(ensenso_camera_msgs::ExecuteCommandGoalConstPtr
const& goal);
273 void onGetParameter(ensenso_camera_msgs::GetParameterGoalConstPtr
const& goal);
278 virtual void onSetParameter(ensenso_camera_msgs::SetParameterGoalConstPtr
const& goal) = 0;
288 void saveParameterSet(std::string name);
293 bool cameraIsAvailable()
const;
298 bool cameraIsOpen()
const;
311 void saveDefaultParameterSet();
316 void loadParameterSet(std::string name);
334 std::string
const& targetFrame =
"",
335 bool latestPatternOnly =
false)
const;
340 virtual std::vector<geometry_msgs::TransformStamped> estimatePatternPoses(
ros::Time imageTimestamp =
ros::Time::now(),
341 std::string
const& targetFrame =
"")
const;
353 bool useCachedTransformation =
false)
const;
360 void updateTransformations(
tf2::Transform const& targetFrameTransformation)
const;
371 void fillBasicCameraInfoFromNxLib(sensor_msgs::CameraInfoPtr
const& info)
const;
376 virtual void updateCameraInfo() = 0;
378 virtual ensenso_camera_msgs::ParameterPtr readParameter(std::string
const& key)
const;
380 virtual void writeParameter(ensenso_camera_msgs::Parameter
const& parameter);
387 void publishCameraLink();
389 geometry_msgs::TransformStamped stampedLinkToCamera();
std::string const DEFAULT_PARAMETER_SET
std::map< std::string, ParameterSet > parameterSets
double const POSE_TF_INTERVAL
std::string const TARGET_FRAME_LINK
double const STATUS_INTERVAL
int const ERROR_CODE_UNKNOWN_EXCEPTION
ros::Publisher statusPublisher
ros::Timer cameraPosePublisher
NxLibItem defaultParameters
double const TRANSFORMATION_REQUEST_TIMEOUT
std::unique_ptr< SetParameterServer > setParameterServer
std::string fileCameraPath
std::unique_ptr< ExecuteCommandServer > executeCommandServer
ParameterSet(std::string const &name, NxLibItem const &defaultParameters)
std::unique_ptr< AccessTreeServer > accessTreeServer
std::map< std::string, geometry_msgs::TransformStamped > transformationCache
std::unique_ptr< GetParameterServer > getParameterServer
std::string currentParameterSet
std::unique_ptr< tf2_ros::TransformListener > transformListener
std::unique_ptr< tf2_ros::TransformBroadcaster > transformBroadcaster