74 #define LOG_NXLIB_EXCEPTION(EXCEPTION) \ 77 if (EXCEPTION.getErrorCode() == NxLibExecutionFailed) \ 79 NxLibItem executionNode(EXCEPTION.getItemPath()); \ 80 ENSENSO_ERROR(nh, "%s: %s", executionNode[itmResult][itmErrorSymbol].asString().c_str(), \ 81 executionNode[itmResult][itmErrorText].asString().c_str()); \ 87 ENSENSO_DEBUG(nh, "Current NxLib tree: %s", NxLibItem().asJson(true).c_str()); 93 #define START_NXLIB_ACTION(ACTION_NAME, ACTION_SERVER) \ 94 ENSENSO_DEBUG(nh, "Received a " #ACTION_NAME " request."); \ 95 auto& server = ACTION_SERVER; \ 96 if (server->isPreemptRequested()) \ 98 server->setPreempted(); \ 101 std::lock_guard<std::mutex> lock(nxLibMutex); \ 104 #define FINISH_NXLIB_ACTION(ACTION_NAME) \ 106 catch (NxLibException & e) \ 108 ENSENSO_ERROR(nh, "NxLibException %d (%s) for item %s", e.getErrorCode(), e.getErrorText().c_str(), \ 109 e.getItemPath().c_str()); \ 110 LOG_NXLIB_EXCEPTION(e) \ 111 ensenso::action::ACTION_NAME##Result result; \ 112 result.error.code = e.getErrorCode(); \ 113 result.error.message = e.getErrorText(); \ 114 server->setAborted(std::move(result)); \ 117 catch (tf2::TransformException & e) \ 119 ENSENSO_ERROR(nh, "tf Exception: %s", e.what()); \ 120 ensenso::action::ACTION_NAME##Result result; \ 121 result.error.code = ERROR_CODE_TF; \ 122 result.error.message = e.what(); \ 123 server->setAborted(std::move(result)); \ 126 catch (std::exception & e) \ 128 ENSENSO_ERROR(nh, "Unknown Exception: %s", e.what()); \ 129 ensenso::action::ACTION_NAME##Result result; \ 130 result.error.code = ERROR_CODE_UNKNOWN_EXCEPTION; \ 131 result.error.message = e.what(); \ 132 server->setAborted(std::move(result)); \ 136 #define PREEMPT_ACTION_IF_REQUESTED \ 137 if (server->isPreemptRequested()) \ 139 server->setPreempted(); \ 169 ParameterSet(std::string
const& name, NxLibItem
const& defaultParameters);
186 bool isFileCamera =
false;
201 bool wait_for_camera =
false;
245 int captureTimeout = 0;
250 std::unique_ptr<ensenso_camera::VirtualObjectHandler> virtualObjectHandler =
nullptr;
262 bool createdFileCamera =
false;
314 virtual void init() = 0;
325 virtual void startServers()
const;
333 bool loadSettings(std::string
const& jsonFile,
bool saveAsDefaultParameters =
false);
338 void onAccessTree(ensenso::action::AccessTreeGoalConstPtr
const& goal);
343 void onExecuteCommand(ensenso::action::ExecuteCommandGoalConstPtr
const& goal);
348 void onGetParameter(ensenso::action::GetParameterGoalConstPtr
const& goal);
353 virtual void onSetParameter(ensenso::action::SetParameterGoalConstPtr
const& goal) = 0;
359 virtual void initTfPublishTimer();
364 virtual void initStatusTimer();
372 void saveParameterSet(std::string name);
377 bool cameraIsAvailable()
const;
382 bool cameraIsOpen()
const;
387 bool hasLink()
const;
398 void saveDefaultParameterSet();
403 void loadParameterSet(std::string name);
418 virtual geometry_msgs::msg::PoseStamped estimatePatternPose(
ensenso::ros::Time imageTimestamp,
419 std::string
const& targetFrame =
"",
420 bool latestPatternOnly =
false)
const = 0;
425 virtual std::vector<geometry_msgs::msg::PoseStamped>
426 estimatePatternPoses(
ensenso::ros::Time imageTimestamp, std::string
const& targetFrame =
"")
const = 0;
435 bool useCachedTransformation =
false)
const;
440 std::string getNxLibTargetFrameName()
const;
446 void updateTransformations(
tf2::Transform const& targetFrameTransformation)
const;
451 void fillBasicCameraInfoFromNxLib(sensor_msgs::msg::CameraInfoPtr
const& info)
const;
456 virtual void updateCameraInfo() = 0;
461 virtual ensenso::msg::ParameterPtr readParameter(std::string
const& key)
const;
466 virtual void writeParameter(ensenso::msg::Parameter
const& parameter);
478 void publishCameraLink();
483 geometry_msgs::msg::TransformStamped stampedLinkToCamera();
std::string const DEFAULT_PARAMETER_SET
std::map< std::string, ParameterSet > parameterSets
NxLibVersion nxLibVersion
void init(const M_string &remappings)
double const POSE_TF_INTERVAL
std::string const TARGET_FRAME_LINK
double const STATUS_INTERVAL
int const ERROR_CODE_UNKNOWN_EXCEPTION
NxLibItem defaultParameters
ensenso::ros::Timer cameraPosePublisher
ensenso::ros::NodeHandle nh
double const TF_REQUEST_TIMEOUT
std::unique_ptr< SetParameterServer > setParameterServer
std::string fileCameraPath
std::unique_ptr< tf2_ros::Buffer > tfBuffer
virtual void updateCameraTypeSpecifics()
std::map< std::string, geometry_msgs::msg::TransformStamped > transformationCache
ensenso::ros::Timer statusTimer
ensenso::ros::Publisher< diagnostic_msgs::msg::DiagnosticArray > statusPublisher
::ros::NodeHandle NodeHandle
std::unique_ptr< ExecuteCommandServer > executeCommandServer
::std::unique_ptr< ::ros::Publisher > Publisher
ParameterSet(std::string const &name, NxLibItem const &defaultParameters)
#define TIMER_CALLBACK_DECLARATION_ARGS
std::unique_ptr< AccessTreeServer > accessTreeServer
std::unique_ptr< GetParameterServer > getParameterServer
std::string currentParameterSet
std::unique_ptr< tf2_ros::TransformListener > transformListener
std::unique_ptr< tf2_ros::TransformBroadcaster > transformBroadcaster