camera.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <ros/ros.h>
5 #include <sensor_msgs/CameraInfo.h>
8 
9 #include <map>
10 #include <memory>
11 #include <mutex>
12 #include <string>
13 #include <vector>
14 
15 #include <ensenso_camera_msgs/AccessTreeAction.h>
16 #include <ensenso_camera_msgs/CalibrateHandEyeAction.h>
17 #include <ensenso_camera_msgs/CalibrateWorkspaceAction.h>
18 #include <ensenso_camera_msgs/ExecuteCommandAction.h>
19 #include <ensenso_camera_msgs/FitPrimitiveAction.h>
20 #include <ensenso_camera_msgs/GetParameterAction.h>
21 #include <ensenso_camera_msgs/LocatePatternAction.h>
22 #include <ensenso_camera_msgs/ProjectPatternAction.h>
23 #include <ensenso_camera_msgs/RequestDataAction.h>
24 #include <ensenso_camera_msgs/SetParameterAction.h>
25 
29 
30 #include "nxLib.h"
31 
42 
48 {
53  NxLibItem node;
54 
58  bool useROI = false;
59 
65 
71  bool autoProjector = true;
72 
73  ParameterSet(std::string const& name, NxLibItem const& defaultParameters);
74 };
75 
81 {
82  projectorDontCare, //@< Inherit the projector settings from the parameter set.
83  projectorOn, //@< Enable the projector and disable the front light.
84  projectorOff //@< Enable the front light and disable the projector.
85 };
86 
87 class Camera
88 {
89 private:
90  std::string serial;
91  NxLibItem cameraNode;
92 
94  std::string fileCameraPath;
95  // Whether the camera was created by this node. If that is the case, we will
96  // delete it again after it got closed.
98 
99  // Whether the camera is fixed in the world or moves with a robot.
100  bool fixed;
101 
102  std::string cameraFrame;
103  std::string targetFrame;
104  std::string robotFrame;
105  std::string wristFrame;
106 
107  // Controls parallel access to the NxLib.
108  mutable std::mutex nxLibMutex;
109 
110  sensor_msgs::CameraInfoPtr leftCameraInfo;
111  sensor_msgs::CameraInfoPtr rightCameraInfo;
112  sensor_msgs::CameraInfoPtr leftRectifiedCameraInfo;
113  sensor_msgs::CameraInfoPtr rightRectifiedCameraInfo;
114 
117 
118  std::unique_ptr<AccessTreeServer> accessTreeServer;
119  std::unique_ptr<ExecuteCommandServer> executeCommandServer;
120  std::unique_ptr<GetParameterServer> getParameterServer;
121  std::unique_ptr<SetParameterServer> setParameterServer;
122  std::unique_ptr<RequestDataServer> requestDataServer;
123  std::unique_ptr<LocatePatternServer> locatePatternServer;
124  std::unique_ptr<ProjectPatternServer> projectPatternServer;
125  std::unique_ptr<CalibrateHandEyeServer> calibrateHandEyeServer;
126  std::unique_ptr<CalibrateWorkspaceServer> calibrateWorkspaceServer;
127  std::unique_ptr<FitPrimitiveServer> fitPrimitiveServer;
128 
135 
137 
140 
141  // Contains a parameter tree that is used for creating new parameter sets.
142  NxLibItem defaultParameters;
143 
144  std::map<std::string, ParameterSet> parameterSets;
145  std::string currentParameterSet;
146 
147  mutable std::map<std::string, tf::StampedTransform> transformationCache;
148 
149  // Information that we remember between the different steps of the hand eye
150  // calibration.
151  // We save the pattern buffer outside of the NxLib, because otherwise we
152  // could not use the LocatePattern action while a hand eye calibration is
153  // in progress.
155  std::vector<tf::Pose> handEyeCalibrationRobotPoses;
156 
157 public:
158  Camera(ros::NodeHandle nh, std::string const& serial, std::string const& fileCameraPath, bool fixed,
159  std::string const& cameraFrame, std::string const& targetFrame, std::string const& robotFrame,
160  std::string const& wristFrame);
161 
162  bool open();
163  void close();
164 
169  void startServers() const;
170 
178  bool loadSettings(std::string const& jsonFile, bool saveAsDefaultParameters = false);
179 
183  void onAccessTree(ensenso_camera_msgs::AccessTreeGoalConstPtr const& goal);
187  void onExecuteCommand(ensenso_camera_msgs::ExecuteCommandGoalConstPtr const& goal);
188 
192  void onGetParameter(ensenso_camera_msgs::GetParameterGoalConstPtr const& goal);
196  void onSetParameter(ensenso_camera_msgs::SetParameterGoalConstPtr const& goal);
197 
201  void onRequestData(ensenso_camera_msgs::RequestDataGoalConstPtr const& goal);
205  void onLocatePattern(ensenso_camera_msgs::LocatePatternGoalConstPtr const& goal);
209  void onProjectPattern(ensenso_camera_msgs::ProjectPatternGoalConstPtr const& goal);
213  void onCalibrateHandEye(ensenso_camera_msgs::CalibrateHandEyeGoalConstPtr const& goal);
217  void onCalibrateWorkspace(ensenso_camera_msgs::CalibrateWorkspaceGoalConstPtr const& goal);
221  void onFitPrimitive(ensenso_camera_msgs::FitPrimitiveGoalConstPtr const& goal);
222 
223 private:
227  bool cameraIsAvailable() const;
228 
232  bool cameraIsOpen() const;
237  void publishStatus(ros::TimerEvent const& event) const;
238 
244  void saveDefaultParameterSet();
245 
253  void saveParameterSet(std::string name, bool projectorWritten = false);
254 
263  void loadParameterSet(std::string name, ProjectorState projector = projectorDontCare);
264 
268  ros::Time capture() const;
269 
274  std::vector<CalibrationPattern> collectPattern(bool clearBuffer = false) const;
275 
286  tf::Stamped<tf::Pose> estimatePatternPose(ros::Time imageTimestamp = ros::Time::now(),
287  std::string const& targetFrame = "", bool latestPatternOnly = false) const;
288 
292  std::vector<tf::Stamped<tf::Pose>> estimatePatternPoses(ros::Time imageTimestamp = ros::Time::now(),
293  std::string const& targetFrame = "") const;
294 
304  void updateTransformations(ros::Time time = ros::Time::now(), std::string targetFrame = "",
305  bool useCachedTransformation = false) const;
306 
312  void updateTransformations(tf::Pose const& targetFrameTransformation) const;
313 
323  void fillCameraInfoFromNxLib(sensor_msgs::CameraInfoPtr const& info, bool right, bool rectified = false) const;
328  void updateCameraInfo();
329 
330  ensenso_camera_msgs::ParameterPtr readParameter(std::string const& key) const;
331  void writeParameter(ensenso_camera_msgs::Parameter const& parameter);
332 };
bool useROI
Definition: camera.h:58
std::vector< tf::Pose > handEyeCalibrationRobotPoses
Definition: camera.h:155
std::map< std::string, ParameterSet > parameterSets
Definition: camera.h:144
NxLibItem node
Definition: camera.h:53
image_transport::CameraPublisher leftRectifiedImagePublisher
Definition: camera.h:131
bool fixed
Definition: camera.h:100
std::unique_ptr< FitPrimitiveServer > fitPrimitiveServer
Definition: camera.h:127
std::string targetFrame
Definition: camera.h:103
image_transport::CameraPublisher leftRawImagePublisher
Definition: camera.h:129
tf::TransformBroadcaster transformBroadcaster
Definition: camera.h:116
bool autoProjector
Definition: camera.h:71
ros::Publisher statusPublisher
Definition: camera.h:138
std::string cameraFrame
Definition: camera.h:102
NxLibItem defaultParameters
Definition: camera.h:142
std::string robotFrame
Definition: camera.h:104
std::unique_ptr< RequestDataServer > requestDataServer
Definition: camera.h:122
image_transport::CameraPublisher rightRawImagePublisher
Definition: camera.h:130
image_transport::Publisher disparityMapPublisher
Definition: camera.h:133
ros::Publisher pointCloudPublisher
Definition: camera.h:136
std::mutex nxLibMutex
Definition: camera.h:108
sensor_msgs::CameraInfoPtr leftCameraInfo
Definition: camera.h:110
ProjectorState
Definition: camera.h:80
PointCloudROI roi
Definition: camera.h:64
std::unique_ptr< SetParameterServer > setParameterServer
Definition: camera.h:121
std::string handEyeCalibrationPatternBuffer
Definition: camera.h:154
std::string serial
Definition: camera.h:90
std::unique_ptr< LocatePatternServer > locatePatternServer
Definition: camera.h:123
image_transport::CameraPublisher rightRectifiedImagePublisher
Definition: camera.h:132
std::string fileCameraPath
Definition: camera.h:94
sensor_msgs::CameraInfoPtr rightCameraInfo
Definition: camera.h:111
std::string wristFrame
Definition: camera.h:105
std::unique_ptr< ExecuteCommandServer > executeCommandServer
Definition: camera.h:119
std::unique_ptr< CalibrateWorkspaceServer > calibrateWorkspaceServer
Definition: camera.h:126
bool isFileCamera
Definition: camera.h:93
NxLibItem cameraNode
Definition: camera.h:91
bool createdFileCamera
Definition: camera.h:97
tf::TransformListener transformListener
Definition: camera.h:115
ParameterSet(std::string const &name, NxLibItem const &defaultParameters)
Definition: camera.cpp:129
static Time now()
ros::Timer statusTimer
Definition: camera.h:139
std::unique_ptr< AccessTreeServer > accessTreeServer
Definition: camera.h:118
std::unique_ptr< GetParameterServer > getParameterServer
Definition: camera.h:120
sensor_msgs::CameraInfoPtr leftRectifiedCameraInfo
Definition: camera.h:112
std::map< std::string, tf::StampedTransform > transformationCache
Definition: camera.h:147
Definition: camera.h:87
std::string currentParameterSet
Definition: camera.h:145
sensor_msgs::CameraInfoPtr rightRectifiedCameraInfo
Definition: camera.h:113
std::unique_ptr< ProjectPatternServer > projectPatternServer
Definition: camera.h:124
std::unique_ptr< CalibrateHandEyeServer > calibrateHandEyeServer
Definition: camera.h:125
image_transport::CameraPublisher depthImagePublisher
Definition: camera.h:134


ensenso_camera
Author(s): Ensenso
autogenerated on Thu May 16 2019 02:44:23