44 dynamic_reconfigure::Server<orb_slam2_ros::dynamic_reconfigureConfig>::CallbackType dynamic_param_callback;
69 if (!position.empty()) {
104 geometry_msgs::TransformStamped tf_msg =
tfBuffer->lookupTransform(frame_in, frame_target,
ros::Time(0));
107 tf_orig2target.
setBasis(transformStamped_temp.getBasis());
108 tf_orig2target.
setOrigin(transformStamped_temp.getOrigin());
146 tf_map2target = tf_map2orig * tf_orig2target;
147 return tf_map2target;
160 geometry_msgs::TransformStamped msg =
tf2::toMsg(tf_map2target_stamped);
176 geometry_msgs::PoseStamped pose_msg;
177 tf2::toMsg(tf_position_target_stamped, pose_msg);
182 std_msgs::Bool gba_status_msg;
183 gba_status_msg.data = gba_status;
188 std_msgs::Header header;
197 cv::Mat rotation(3,3,CV_32F);
198 cv::Mat translation(3,1,CV_32F);
200 rotation = position_mat.rowRange(0,3).colRange(0,3);
201 translation = position_mat.rowRange(0,3).col(3);
204 tf2::Matrix3x3 tf_camera_rotation (rotation.at<
float> (0,0), rotation.at<
float> (0,1), rotation.at<
float> (0,2),
205 rotation.at<
float> (1,0), rotation.at<
float> (1,1), rotation.at<
float> (1,2),
206 rotation.at<
float> (2,0), rotation.at<
float> (2,1), rotation.at<
float> (2,2)
209 tf2::Vector3 tf_camera_translation (translation.at<
float> (0), translation.at<
float> (1), translation.at<
float> (2));
217 tf_camera_rotation = tf_orb_to_ros*tf_camera_rotation;
218 tf_camera_translation = tf_orb_to_ros*tf_camera_translation;
221 tf_camera_rotation = tf_camera_rotation.
transpose();
222 tf_camera_translation = -(tf_camera_rotation*tf_camera_translation);
225 tf_camera_rotation = tf_orb_to_ros*tf_camera_rotation;
226 tf_camera_translation = tf_orb_to_ros*tf_camera_translation;
228 return tf2::Transform (tf_camera_rotation, tf_camera_translation);
233 if (map_points.size() == 0) {
234 std::cout <<
"Map point vector is empty!" << std::endl;
237 sensor_msgs::PointCloud2 cloud;
239 const int num_channels = 3;
244 cloud.width = map_points.size();
245 cloud.is_bigendian =
false;
246 cloud.is_dense =
true;
247 cloud.point_step = num_channels *
sizeof(float);
248 cloud.row_step = cloud.point_step * cloud.width;
249 cloud.fields.resize(num_channels);
251 std::string channel_id[] = {
"x",
"y",
"z"};
252 for (
int i = 0; i<num_channels; i++) {
253 cloud.fields[i].name = channel_id[i];
254 cloud.fields[i].offset = i *
sizeof(float);
255 cloud.fields[i].count = 1;
256 cloud.fields[i].datatype = sensor_msgs::PointField::FLOAT32;
259 cloud.data.resize(cloud.row_step * cloud.height);
261 unsigned char *cloud_data_ptr = &(cloud.data[0]);
263 float data_array[num_channels];
264 for (
unsigned int i=0; i<cloud.width; i++) {
266 data_array[0] = map_points.at(i)->GetWorldPos().at<
float> (2);
267 data_array[1] = -1.0* map_points.at(i)->GetWorldPos().at<
float> (0);
268 data_array[2] = -1.0* map_points.at(i)->GetWorldPos().at<
float> (1);
271 memcpy(cloud_data_ptr+(i*cloud.point_step), data_array, num_channels*
sizeof(
float));
283 if (config.reset_map) {
285 config.reset_map =
false;
292 bool Node::SaveMapSrv (orb_slam2_ros::SaveMap::Request &req, orb_slam2_ros::SaveMap::Response &res) {
315 bool load_calibration_from_cam =
false;
323 if (load_calibration_from_cam) {
326 if(camera_info ==
nullptr){
327 ROS_WARN(
"Did not receive camera info before timeout, defaulting to launch file params.");
329 parameters.
fx = camera_info->K[0];
330 parameters.
fy = camera_info->K[4];
331 parameters.
cx = camera_info->K[2];
332 parameters.
cy = camera_info->K[5];
334 parameters.
baseline = camera_info->P[3];
336 parameters.
k1 = camera_info->D[0];
337 parameters.
k2 = camera_info->D[1];
338 parameters.
p1 = camera_info->D[2];
339 parameters.
p2 = camera_info->D[3];
340 parameters.
k3 = camera_info->D[4];
345 bool got_cam_calibration =
true;
360 if (!got_cam_calibration) {
361 ROS_ERROR (
"Failed to get camera calibration parameters from the launch file.");
362 throw std::runtime_error(
"No cam calibration");
std::string camera_info_topic_
image_transport::Publisher rendered_image_publisher_
ros::Publisher status_gba_publisher_
std::string name_of_node_
void publish(const boost::shared_ptr< M > &message) const
std::string map_frame_id_param_
void ParamsChangedCallback(orb_slam2_ros::dynamic_reconfigureConfig &config, uint32_t level)
ros::Publisher map_points_publisher_
bool SaveMap(const string &filename)
std::string resolveName(const std::string &name, bool remap=true) const
dynamic_reconfigure::Server< orb_slam2_ros::dynamic_reconfigureConfig > dynamic_param_server_
ros::NodeHandle node_handle_
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
ORB_SLAM2::System * orb_slam_
ros::ServiceServer service_server_
ROSCPP_DECL const std::string & getName()
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void EnableLocalizationOnly(bool localize_only)
void PublishGBAStatus(bool gba_status)
void PublishPositionAsPoseStamped(cv::Mat position)
Matrix3x3 transpose() const
void LoadOrbParameters(ORB_SLAM2::ORBParameters ¶meters)
void PublishMapPoints(std::vector< ORB_SLAM2::MapPoint * > map_points)
std::string camera_frame_id_param_
std::string map_file_name_param_
void publish(const sensor_msgs::Image &message) const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
ros::Time current_frame_time_
void fromMsg(const A &, B &b)
void PublishPositionAsTransform(cv::Mat position)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool SaveMapSrv(orb_slam2_ros::SaveMap::Request &req, orb_slam2_ros::SaveMap::Response &res)
cv::Mat GetCurrentPosition()
std::string voc_file_name_param_
sensor_msgs::PointCloud2 MapPointsToPointCloud(std::vector< ORB_SLAM2::MapPoint * > map_points)
Node(ORB_SLAM2::System::eSensor sensor, ros::NodeHandle &node_handle, image_transport::ImageTransport &image_transport)
tf2::Transform TransformToTarget(tf2::Transform tf_in, std::string frame_in, std::string frame_target)
void PublishRenderedImage(cv::Mat image)
#define ROS_INFO_STREAM(args)
std::string target_frame_id_param_
tf2::Transform TransformFromMat(cv::Mat position_mat)
bool publish_pointcloud_param_
bool getParam(const std::string &key, std::string &s) const
int min_observations_per_point_
std::vector< MapPoint * > GetAllMapPoints()
void SaveKeyFrameTrajectoryTUM(const string &filename)
ros::Publisher pose_publisher_
cv::Mat DrawCurrentFrame()
void SetMinimumKeyFrames(int min_num_kf)
boost::shared_ptr< tf2_ros::TransformListener > tfListener
boost::shared_ptr< tf2_ros::Buffer > tfBuffer
sensor_msgs::ImagePtr toImageMsg() const
image_transport::ImageTransport image_transport_
ORB_SLAM2::System::eSensor sensor_