19 #ifndef LOCALIZATION_VIVE_LOCALIZATION_SRC_VIVE_SOLVER_H_
20 #define LOCALIZATION_VIVE_LOCALIZATION_SRC_VIVE_SOLVER_H_
26 #include <geometry_msgs/PoseStamped.h>
27 #include <nav_msgs/Path.h>
30 #include <ff_hw_msgs/ViveLight.h>
31 #include <ff_hw_msgs/ViveLighthouses.h>
32 #include <ff_hw_msgs/ViveTrackers.h>
35 #include <ceres/ceres.h>
36 #include <ceres/rotation.h>
58 template <
typename T>
inline
61 ceres::AngleAxisRotatePoint(&transform[3], x, tmp);
62 x[0] = tmp[0] + transform[0];
63 x[1] = tmp[1] + transform[1];
64 x[2] = tmp[2] + transform[2];
68 template <
typename T>
inline
71 tmp[0] = x[0] - transform[0];
72 tmp[1] = x[1] - transform[1];
73 tmp[2] = x[2] - transform[2];
74 aa[0] = -transform[3];
75 aa[1] = -transform[4];
76 aa[2] = -transform[5];
77 ceres::AngleAxisRotatePoint(aa, tmp, x);
85 template <
typename T>
inline
87 T b_q[4], a_q[4], ba_q[4];
89 for (
size_t i = 0; i < 3; i++)
93 ceres::AngleAxisToQuaternion(&a[3], a_q);
94 ceres::AngleAxisToQuaternion(&b[3], b_q);
95 ceres::QuaternionProduct(b_q, a_q, ba_q);
96 ceres::QuaternionToAngleAxis(ba_q, &ba[3]);
100 template <
typename T>
inline
102 T a_aa[3], b_aa[3], a_q[4], b_q[4], q[4];
103 for (
size_t i = 0; i < 3; i++) {
104 err[i] = a[i] - b[i];
108 ceres::AngleAxisToQuaternion(a_aa, a_q);
109 ceres::AngleAxisToQuaternion(b_aa, b_q);
110 ceres::QuaternionProduct(a_q, b_q, q);
111 ceres::QuaternionToAngleAxis(q, &err[3]);
125 template <
typename T>
127 const T*
const next_state,
132 for (
size_t i = 0; i < 6; i++)
133 residual[i] *= T(smooth_);
149 std::map<std::string,
161 explicit LightCost(uint16_t sensor,
double angles[2],
bool correct)
162 : sensor_(sensor), correct_(correct) {
167 template <
typename T>
172 const T*
const sensors,
173 const T*
const params,
177 x[0] = sensors[6 * sensor_ + 0];
178 x[1] = sensors[6 * sensor_ + 1];
179 x[2] = sensors[6 * sensor_ + 2];
186 Predict(params, x, angle, correct_);
188 residual[0] = angle[0] - T(obs_[0]);
189 residual[1] = angle[1] - T(obs_[1]);
208 explicit Solver(ros::NodeHandle nh);
209 void Add(ff_hw_msgs::ViveTrackers::ConstPtr msg,
ros::Time const& t);
210 void Add(ff_hw_msgs::ViveLighthouses::ConstPtr msg,
ros::Time const& t);
211 void Add(ff_hw_msgs::ViveLight::ConstPtr msg,
ros::Time const& t);
212 void Add(geometry_msgs::PoseStamped::ConstPtr msg,
ros::Time const& t);
217 void Publish(ros::Publisher & pub,
218 std::string
const& frame, std::map<
ros::Time,
double[6]>
const& x);
220 void GetTruth(nav_msgs::Path & path);
221 void GetVive(nav_msgs::Path & path);
224 double res_, smooth_, min_angle_, max_angle_, duration_;
226 bool correct_, calibrate_, refine_, register_,
227 refine_extrinsics_, refine_sensors_, refine_head_, refine_params_;
229 Eigen::Quaterniond modification_quaternion;
230 ceres::Solver::Options options_;
232 std::map<std::string, Eigen::Affine3d> calibration_;
238 ros::Publisher pub_vive_, pub_ekf_;
243 #endif // LOCALIZATION_VIVE_LOCALIZATION_SRC_VIVE_SOLVER_H_