15 node = NxLibItem()[
"rosParameterSets"][name];
16 node << defaultParameters;
51 if (cameraType != valMonocular)
72 std::string objectsFile =
"";
74 if (!objectsFile.empty())
82 std::string markerTopic;
83 double markerRate = 1;
91 nh, objectsFile, objectsFrame,
linkFrame, markerTopic, markerRate);
93 catch (std::exception
const& e)
95 ENSENSO_WARN(nh,
"Unable to load virtual objects file '%s'. Error: %s", objectsFile.c_str(), e.what());
104 transformListener = ensenso::std::make_unique<tf2_ros::TransformListener>(*tfBuffer);
112 statusPublisher = ensenso::ros::create_publisher<diagnostic_msgs::msg::DiagnosticArray>(
nh,
"/diagnostics", 1);
131 if (jsonFile.empty())
137 if (file.is_open() && file.rdbuf())
139 std::stringstream buffer;
140 buffer << file.rdbuf();
141 std::string
const& jsonSettings = buffer.str();
143 NxLibItem tmpParameters = NxLibItem()[
"rosTemporaryParameters"];
146 tmpParameters.setJson(jsonSettings);
148 catch (NxLibException&)
150 ENSENSO_ERROR(
nh,
"The file '%s' does not contain valid JSON", jsonFile.c_str());
156 if (tmpParameters[itmParameters].
exists())
159 cameraNode[itmParameters] << tmpParameters[itmParameters];
164 cameraNode[itmParameters].setJson(jsonSettings,
true);
166 tmpParameters.erase();
168 NxLibCommand synchronize(cmdSynchronize,
params.
serial);
170 synchronize.execute();
173 if (saveAsDefaultParameters)
180 catch (NxLibException& e)
201 NxLibItem item(goal->path);
203 bool treeChanged =
false;
209 else if (goal->set_null)
214 else if (!goal->json_value.empty())
216 item.setJson(goal->json_value);
225 ensenso::action::AccessTreeResult result;
227 result.exists =
false;
230 result.exists =
true;
232 result.json_value = item.asJson();
238 catch (NxLibException&)
254 NxLibCommand
command(goal->command);
255 command.parameters().setJson(goal->parameters);
258 ensenso::action::ExecuteCommandResult result;
259 result.result = command.result().asJson();
270 ensenso::action::GetParameterResult result;
275 for (
auto const& key : goal->keys)
306 diagnostic_msgs::msg::DiagnosticStatus cameraStatus;
307 cameraStatus.name =
"Camera";
309 cameraStatus.level = diagnostic_msgs::msg::DiagnosticStatus::OK;
310 cameraStatus.message =
"OK";
314 cameraStatus.level = diagnostic_msgs::msg::DiagnosticStatus::ERROR;
315 cameraStatus.message =
"Camera is no longer open";
318 diagnostic_msgs::msg::DiagnosticArray status;
320 status.status.push_back(cameraStatus);
328 info->width =
cameraNode[itmSensor][itmSize][0].asInt();
329 info->height =
cameraNode[itmSensor][itmSize][1].asInt();
341 info->binning_x =
cameraNode[itmParameters][itmCapture][itmBinning].asInt();
342 info->binning_y = info->binning_x;
372 if (targetFrame.empty())
388 geometry_msgs::msg::TransformStamped transformMsg;
402 NxLibItem()[itmLinks].setNull();
408 auto message = ensenso::std::make_shared<ensenso::msg::Parameter>();
419 switch (parameterMapping.
type)
422 message->bool_value = node.asBool();
425 message->float_value = node.asDouble();
428 message->string_value = node.asString();
434 ENSENSO_WARN(
nh,
"Reading the parameter %s, but the camera does not support it!", key.c_str());
456 ENSENSO_WARN(
nh,
"Writing the parameter %s, but the camera does not support it!", parameter.key.c_str());
460 switch (parameterMapping.
type)
463 node.set<
bool>(parameter.bool_value);
466 node.set<
double>(parameter.float_value);
469 node.set<std::string>(parameter.string_value);
495 NxLibCommand createCamera(cmdCreateCamera,
params.
serial);
496 createCamera.parameters()[itmSerialNumber] =
params.
serial;
498 createCamera.execute();
502 catch (NxLibException& e)
541 catch (NxLibException& e)
563 "Camera %s has an internal link (i.e. it is either extrinsically calibrated (workspace- or " 564 "hand-eye) or has a link to another camera), but camera and target frame are equal, which means " 565 "that neither a link nor a target frame has been provided. The images and 3d data retreived from " 566 "the camera are transformed by the NxLib with the transform stored in the camera's link node, " 567 "however, this transform is not known to tf. Please provide a link or target frame in order for " 568 "the transform to be published.",
591 catch (NxLibException&)
610 parameterSet.
node.erase();
632 bool changedParameters =
false;
636 changedParameters =
true;
639 if (changedParameters)
641 NxLibCommand synchronize(cmdSynchronize,
params.
serial);
643 synchronize.execute();
683 catch (NxLibException
const& e)
685 ENSENSO_WARN(
nh,
"Link does not exist. Therefore we cannot publish a transform to any target. Error message: %s",
686 e.getErrorText().c_str());
691 ENSENSO_WARN(
nh,
"Did not find a good transform from %s to %s. Transform has been set to identity",
std::string const DEFAULT_PARAMETER_SET
bool get_parameter(NodeHandle &nh, const char *name, T ¶meter)
geometry_msgs::msg::TransformStamped stampedLinkToCamera()
inline ::ros::Duration durationFromSeconds(double d)
std::map< std::string, ParameterSet > parameterSets
void ENSENSO_WARN_ONCE(T... args)
#define GET_K_MATRIX(info)
void ENSENSO_ERROR(T... args)
void writeTransformToNxLib(Transform const &transform, NxLibItem const &node)
void ENSENSO_DEBUG(T... args)
#define TIMER_CALLBACK_DEFINITION_ARGS
NxLibVersion nxLibVersion
virtual void initStatusTimer()
void publishStatus(TIMER_CALLBACK_DECLARATION_ARGS)
#define GET_P_MATRIX(info)
bool parameterExists(std::string const &key)
void ENSENSO_INFO(T... args)
std::map< std::string, ParameterMapping > const parameterInformation
CameraParameters(ensenso::ros::NodeHandle &nh, std::string const &cameraType, std::string serial)
double const POSE_TF_INTERVAL
std::string const TARGET_FRAME_LINK
virtual ensenso::msg::ParameterPtr readParameter(std::string const &key) const
void updateTransformations(tf2::Transform const &targetFrameTransformation) const
bool cameraIsOpen() const
std::unique_ptr< ensenso_camera::VirtualObjectHandler > virtualObjectHandler
NxLibItem node(NxLibItem const &cameraNode)
double const STATUS_INTERVAL
bool meetsMinimumRequirement(int majorRequired, int minorRequired) const
virtual void writeParameter(ensenso::msg::Parameter const ¶meter)
NxLibItem defaultParameters
std::string toString() const
std::string getNxLibTargetFrameName() const
std::string expandPath(std::string const &path_)
ensenso::ros::Timer cameraPosePublisher
Camera(ensenso::ros::NodeHandle &nh, CameraParameters params)
#define MAKE_SERVER(CallbackClass, ActionName, TopicName)
bool cameraIsAvailable() const
ensenso::ros::NodeHandle nh
double const TF_REQUEST_TIMEOUT
std::unique_ptr< SetParameterServer > setParameterServer
virtual void updateCameraInfo()=0
void updateGlobalLink(ensenso::ros::Time time, std::string targetFrame="", bool useCachedTransformation=false) const
virtual void initTfPublishTimer()
std::string fileCameraPath
ROSLIB_DECL std::string command(const std::string &cmd)
std::unique_ptr< tf2_ros::Buffer > tfBuffer
#define GET_D_MATRIX(info)
void publishCurrentLinks(TIMER_CALLBACK_DECLARATION_ARGS)
inline ::ros::Time now(ensenso::ros::NodeHandle const &nh)
tf2::Transform getCameraToLinkTransform()
const std::string PLUMB_BOB
virtual void updateCameraTypeSpecifics()
std::map< std::string, geometry_msgs::msg::TransformStamped > transformationCache
ensenso::ros::Timer statusTimer
ensenso::ros::Publisher< diagnostic_msgs::msg::DiagnosticArray > statusPublisher
def message(msg, args, kwargs)
::ros::NodeHandle NodeHandle
std::unique_ptr< ExecuteCommandServer > executeCommandServer
void ENSENSO_WARN(T... args)
void onAccessTree(ensenso::action::AccessTreeGoalConstPtr const &goal)
std::unique_ptr< tf2_ros::Buffer > make_tf2_buffer(ensenso::ros::NodeHandle const &nh)
#define CREATE_TIMER(nh, duration_in_seconds, callback_ref, object_ptr)
void loadParameterSet(std::string name)
#define LOG_NXLIB_EXCEPTION(EXCEPTION)
ParameterSet(std::string const &name, NxLibItem const &defaultParameters)
void move(std::vector< T > &a, std::vector< T > &b)
#define GET_R_MATRIX(info)
void saveDefaultParameterSet()
Transform transformFromNxLib(NxLibItem const &node)
void onGetParameter(ensenso::action::GetParameterGoalConstPtr const &goal)
void onExecuteCommand(ensenso::action::ExecuteCommandGoalConstPtr const &goal)
#define START_NXLIB_ACTION(ACTION_NAME, ACTION_SERVER)
void convert(const A &a, B &b)
bool isIdentity(Transform const &transform)
std::unique_ptr< AccessTreeServer > accessTreeServer
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
virtual void startServers() const
std::unique_ptr< GetParameterServer > getParameterServer
void saveParameterSet(std::string name)
std::unique_ptr< tf2_ros::TransformBroadcaster > make_tf2_broadcaster(ensenso::ros::NodeHandle const &nh)
ImagePtr imageFromNxLibNode(NxLibItem const &node, std::string const &frame, bool isFileCamera)
StampedTransformMsg fromTf(Transform const &transform, std::string parentFrame, std::string childFrame, ensenso::ros::Time timestamp)
#define FINISH_NXLIB_ACTION(ACTION_NAME)
std::string currentParameterSet
bool isValid(Transform const &transform)
bool loadSettings(std::string const &jsonFile, bool saveAsDefaultParameters=false)
std::unique_ptr< tf2_ros::TransformListener > transformListener
std::unique_ptr< tf2_ros::TransformBroadcaster > transformBroadcaster
void fillBasicCameraInfoFromNxLib(sensor_msgs::msg::CameraInfoPtr const &info) const