13 node = NxLibItem()[
"rosParameterSets"][name];
14 node << defaultParameters;
18 std::string cameraFrame, std::string targetFrame, std::string linkFrame)
19 : fileCameraPath(
std::move(fileCameraPath))
20 , serial(
std::move(serial))
22 , cameraFrame(
std::move(cameraFrame))
23 , linkFrame(
std::move(linkFrame))
24 , targetFrame(
std::move(targetFrame))
40 statusPublisher = nh.advertise<diagnostic_msgs::DiagnosticArray>(
"/diagnostics", 1);
62 std::ifstream file(jsonFile);
63 if (file.is_open() && file.rdbuf())
65 std::stringstream buffer;
66 buffer << file.rdbuf();
67 std::string
const& jsonSettings = buffer.str();
69 NxLibItem tmpParameters = NxLibItem()[
"rosTemporaryParameters"];
72 tmpParameters.setJson(jsonSettings);
74 catch (NxLibException&)
76 ROS_ERROR(
"The file '%s' does not contain valid JSON", jsonFile.c_str());
82 if (tmpParameters[itmParameters].
exists())
85 cameraNode[itmParameters] << tmpParameters[itmParameters];
90 cameraNode[itmParameters].setJson(jsonSettings,
true);
92 tmpParameters.erase();
94 NxLibCommand synchronize(cmdSynchronize,
serial);
95 synchronize.parameters()[itmCameras] =
serial;
96 synchronize.execute();
99 if (saveAsDefaultParameters)
102 catch (NxLibException& e)
110 ROS_ERROR(
"Could not open the file '%s'", jsonFile.c_str());
123 NxLibItem item(goal->path);
125 bool treeChanged =
false;
131 else if (goal->set_null)
136 else if (!goal->json_value.empty())
138 item.setJson(goal->json_value);
147 ensenso_camera_msgs::AccessTreeResult result;
149 result.exists =
false;
152 result.exists =
true;
154 result.json_value = item.asJson();
161 catch (NxLibException&)
177 NxLibCommand
command(goal->command);
178 command.parameters().setJson(goal->parameters);
181 ensenso_camera_msgs::ExecuteCommandResult result;
182 result.result = command.result().asJson();
193 ensenso_camera_msgs::GetParameterResult result;
198 for (
auto const& key : goal->keys)
224 diagnostic_msgs::DiagnosticStatus cameraStatus;
225 cameraStatus.name =
"Camera";
226 cameraStatus.hardware_id =
serial;
227 cameraStatus.level = diagnostic_msgs::DiagnosticStatus::OK;
228 cameraStatus.message =
"OK";
232 cameraStatus.level = diagnostic_msgs::DiagnosticStatus::ERROR;
233 cameraStatus.message =
"Camera is no longer open";
236 diagnostic_msgs::DiagnosticArray status;
238 status.status.push_back(cameraStatus);
246 info->width =
cameraNode[itmSensor][itmSize][0].asInt();
247 info->height =
cameraNode[itmSensor][itmSize][1].asInt();
249 info->binning_x =
cameraNode[itmParameters][itmCapture][itmBinning].asInt();
250 info->binning_y = info->binning_x;
286 geometry_msgs::TransformStamped transform;
299 NxLibItem()[itmLinks].setNull();
309 estimatePatternPose.parameters()[itmAverage] =
false;
310 estimatePatternPose.parameters()[itmFilter][itmCameras] =
serial;
311 estimatePatternPose.parameters()[itmFilter][itmUseModel] =
true;
312 estimatePatternPose.parameters()[itmFilter][itmType] = valStatic;
313 estimatePatternPose.parameters()[itmFilter][itmValue] =
true;
314 estimatePatternPose.execute();
316 int numberOfPatterns = estimatePatternPose.result()[itmPatterns].count();
318 std::vector<geometry_msgs::TransformStamped> result;
319 result.reserve(numberOfPatterns);
321 for (
int i = 0; i < numberOfPatterns; i++)
331 bool latestPatternOnly)
const 336 if (latestPatternOnly)
338 estimatePatternPose.parameters()[itmAverage] =
false;
340 int patternCount = NxLibItem()[itmParameters][itmPatternCount].asInt();
341 estimatePatternPose.parameters()[itmFilter][itmOr][0][itmAnd][0][itmType] = valIndex;
342 estimatePatternPose.parameters()[itmFilter][itmOr][0][itmAnd][0][itmValue] = patternCount - 1;
346 estimatePatternPose.parameters()[itmAverage] =
true;
348 estimatePatternPose.execute();
350 ROS_ASSERT(estimatePatternPose.result()[itmPatterns].count() == 1);
357 auto message = boost::make_shared<ensenso_camera_msgs::Parameter>();
368 switch (parameterMapping.
type)
371 message->bool_value = node.asBool();
374 message->float_value = node.asDouble();
377 message->string_value = node.asString();
383 ROS_WARN(
"Reading the parameter %s, but the camera does not support it!", key.c_str());
388 ROS_ERROR(
"Unknown parameter '%s'!", key.c_str());
405 ROS_WARN(
"Writing the parameter %s, but the camera does not support it!", parameter.key.c_str());
409 switch (parameterMapping.
type)
412 node.set<
bool>(parameter.bool_value);
415 node.set<
double>(parameter.float_value);
418 node.set<std::string>(parameter.string_value);
423 ROS_ERROR(
"Unknown parameter '%s'!", parameter.key.c_str());
439 NxLibCommand createCamera(cmdCreateCamera,
serial);
440 createCamera.parameters()[itmSerialNumber] =
serial;
442 createCamera.execute();
446 catch (NxLibException& e)
448 ROS_ERROR(
"Failed to create the file camera!");
468 open.parameters()[itmCameras] =
serial;
471 catch (NxLibException& e)
481 ROS_INFO(
"Opened camera with serial number '%s'.",
serial.c_str());
492 close.parameters()[itmCameras] =
serial;
497 NxLibCommand deleteCmd(cmdDeleteCamera,
serial);
498 deleteCmd.parameters()[itmCameras] =
serial;
502 catch (NxLibException&)
521 parameterSet.
node.erase();
532 ROS_DEBUG(
"Loading parameter set '%s'", name.c_str());
543 bool changedParameters =
false;
547 changedParameters =
true;
550 if (changedParameters)
552 NxLibCommand synchronize(cmdSynchronize,
serial);
553 synchronize.parameters()[itmCameras] =
serial;
554 synchronize.execute();
573 bool cameraLinkExists =
cameraNode[itmLink][itmTarget].exists();
575 if (cameraLinkExists)
588 return transformStamped;
599 catch (NxLibException
const& e)
601 ROS_WARN(
"Link does not exists.Therefore we cannot publish a transform to any target. Error message: %s",
602 e.getErrorText().c_str());
608 ROS_WARN(
"Did not find a good transform from %s to %s. Transform has been set to identity",
cameraFrame.c_str(),
sensor_msgs::ImagePtr imageFromNxLibNode(NxLibItem const &node, std::string const &frame)
std::string const DEFAULT_PARAMETER_SET
std::map< std::string, ParameterSet > parameterSets
virtual void initStatusTimer()
void publish(const boost::shared_ptr< M > &message) const
bool parameterExists(std::string const &key)
void updateTransformations(tf2::Transform const &targetFrameTransformation) const
std::map< std::string, ParameterMapping > const parameterInformation
VersionInfo getCurrentNxLibVersion()
void updateGlobalLink(ros::Time time=ros::Time::now(), std::string frame="", bool useCachedTransformation=false) const
geometry_msgs::TransformStamped stampedLinkToCamera()
double const POSE_TF_INTERVAL
std::string const TARGET_FRAME_LINK
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
NxLibItem node(NxLibItem const &cameraNode)
virtual void publishStatus(ros::TimerEvent const &event) const
double const STATUS_INTERVAL
ros::Publisher statusPublisher
ros::Timer cameraPosePublisher
NxLibItem defaultParameters
bool cameraIsOpen() const
virtual std::vector< geometry_msgs::TransformStamped > estimatePatternPoses(ros::Time imageTimestamp=ros::Time::now(), std::string const &targetFrame="") const
void writePoseToNxLib(tf2::Transform const &pose, NxLibItem const &node)
double const TRANSFORMATION_REQUEST_TIMEOUT
std::unique_ptr< SetParameterServer > setParameterServer
virtual void updateCameraInfo()=0
virtual void initTfPublishTimer()
ROSLIB_DECL std::string command(const std::string &cmd)
tf2::Transform getCameraToLinkTransform()
void publishCurrentLinks(ros::TimerEvent const &timerEvent=ros::TimerEvent())
Camera(ros::NodeHandle const &n, std::string serial, std::string fileCameraPath, bool fixed, std::string cameraFrame, std::string targetFrame, std::string linkFrame)
void onGetParameter(ensenso_camera_msgs::GetParameterGoalConstPtr const &goal)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
virtual geometry_msgs::TransformStamped estimatePatternPose(ros::Time imageTimestamp=ros::Time::now(), std::string const &targetFrame="", bool latestPatternOnly=false) const
void onAccessTree(ensenso_camera_msgs::AccessTreeGoalConstPtr const &goal)
virtual void writeParameter(ensenso_camera_msgs::Parameter const ¶meter)
bool isValid(tf2::Transform const &pose)
std::string fileCameraPath
std::unique_ptr< ExecuteCommandServer > executeCommandServer
virtual void startServers() const
geometry_msgs::TransformStamped fromTfTransform(tf2::Transform const &transform, std::string parentFrame, std::string childFrame)
bool cameraIsAvailable() const
void onExecuteCommand(ensenso_camera_msgs::ExecuteCommandGoalConstPtr const &goal)
virtual void onSetParameter(ensenso_camera_msgs::SetParameterGoalConstPtr const &goal)=0
void loadParameterSet(std::string name)
#define LOG_NXLIB_EXCEPTION(EXCEPTION)
ParameterSet(std::string const &name, NxLibItem const &defaultParameters)
tf2::Transform poseFromNxLib(NxLibItem const &node)
void saveDefaultParameterSet()
#define START_NXLIB_ACTION(ACTION_NAME, ACTION_SERVER)
void convert(const A &a, B &b)
std::unique_ptr< AccessTreeServer > accessTreeServer
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
std::map< std::string, geometry_msgs::TransformStamped > transformationCache
std::unique_ptr< GetParameterServer > getParameterServer
void saveParameterSet(std::string name)
void fillBasicCameraInfoFromNxLib(sensor_msgs::CameraInfoPtr const &info) const
virtual ensenso_camera_msgs::ParameterPtr readParameter(std::string const &key) const
#define FINISH_NXLIB_ACTION(ACTION_NAME)
std::string currentParameterSet
bool loadSettings(std::string const &jsonFile, bool saveAsDefaultParameters=false)
std::unique_ptr< tf2_ros::TransformListener > transformListener
std::unique_ptr< tf2_ros::TransformBroadcaster > transformBroadcaster