28 const sensor_msgs::JointState& msg)
30 for (
size_t i = 0; i < msg.name.size(); ++i)
32 if (msg.name[i] == name)
33 return msg.position[i];
36 std::cerr <<
"Unable to find " << name <<
" in sensor_msgs::JointState" << std::endl;
42 root_(root), tip_(tip), name_(name)
47 auto error_msg = std::string{
"Failed to build a chain model from "} + root +
" to " + tip +
", check the link names";
49 throw std::runtime_error(error_msg);
54 const robot_calibration_msgs::CalibrationData& data,
58 std::vector<geometry_msgs::PointStamped> points;
62 for (
size_t obs = 0; obs < data.observations.size(); obs++)
64 if (data.observations[obs].sensor_name ==
name_)
78 points.resize(data.observations[sensor_idx].features.size());
84 for (
size_t i = 0; i < points.size(); ++i)
86 points[i].header.frame_id =
root_;
89 p.
p.
x(data.observations[sensor_idx].features[i].point.x);
90 p.
p.
y(data.observations[sensor_idx].features[i].point.y);
91 p.
p.
z(data.observations[sensor_idx].features[i].point.z);
96 if (data.observations[sensor_idx].features[i].header.frame_id !=
tip_)
99 if (offsets.
getFrame(data.observations[sensor_idx].features[i].header.frame_id, p2))
109 points[i].point.x = p.
p.
x();
110 points[i].point.y = p.p.y();
111 points[i].point.z = p.p.z();
118 const sensor_msgs::JointState& state)
146 p_out = p_out * KDL::Frame(totip.
M * correction.
M * totip.
M.
Inverse() * pose.
M);
164 param_name_(param_name)
170 const robot_calibration_msgs::CalibrationData& data,
173 std::vector<geometry_msgs::PointStamped> points;
177 for (
size_t obs = 0; obs < data.observations.size(); obs++)
179 if (data.observations[obs].sensor_name ==
name_)
193 if (data.observations[sensor_idx].ext_camera_info.camera_info.P.size() != 12)
194 std::cerr <<
"Unexpected CameraInfo projection matrix size" << std::endl;
206 double z_offset = 0.0;
207 double z_scaling = 1.0;
208 for (
size_t i = 0; i < data.observations[sensor_idx].ext_camera_info.parameters.size(); i++)
210 if (data.observations[sensor_idx].ext_camera_info.parameters[i].name ==
"z_scaling")
212 z_scaling = data.observations[sensor_idx].ext_camera_info.parameters[i].value;
214 else if (data.observations[sensor_idx].ext_camera_info.parameters[i].name ==
"z_offset_mm")
216 z_offset = data.observations[sensor_idx].ext_camera_info.parameters[i].value / 1000.0;
221 double new_camera_fx = camera_fx * (1.0 + offsets.
get(
param_name_ +
"_fx"));
222 double new_camera_fy = camera_fy * (1.0 + offsets.
get(
param_name_ +
"_fy"));
223 double new_camera_cx = camera_cx * (1.0 + offsets.
get(
param_name_ +
"_cx"));
224 double new_camera_cy = camera_cy * (1.0 + offsets.
get(
param_name_ +
"_cy"));
226 double new_z_scaling = 1.0 + offsets.
get(
param_name_ +
"_z_scaling");
228 points.resize(data.observations[sensor_idx].features.size());
233 for (
size_t i = 0; i < points.size(); ++i)
236 double x = data.observations[sensor_idx].features[i].point.x;
237 double y = data.observations[sensor_idx].features[i].point.y;
238 double z = data.observations[sensor_idx].features[i].point.z;
241 double u = x * camera_fx / z + camera_cx;
242 double v = y * camera_fy / z + camera_cy;
243 double depth = z/z_scaling - z_offset;
248 pt.
p.
z((depth + new_z_offset) * new_z_scaling);
249 pt.
p.
x((u - new_camera_cx) * pt.
p.
z() / new_camera_fx);
250 pt.
p.
y((v - new_camera_cy) * pt.
p.
z() / new_camera_fy);
255 points[i].point.x = pt.
p.
x();
256 points[i].point.y = pt.p.y();
257 points[i].point.z = pt.p.z();
258 points[i].header.frame_id =
root_;
266 return "Camera3dModel";
271 double magnitude =
sqrt(x*x + y*y + z*z);
273 if (magnitude == 0.0)
277 y/magnitude *
sin(magnitude/2.0),
278 z/magnitude *
sin(magnitude/2.0),
284 double qx, qy, qz, qw;
293 double magnitude = 2 *
acos(qw);
294 double k =
sqrt(1 - (qw*qw));
296 x = (qx / k) * magnitude;
297 y = (qy / k) * magnitude;
298 z = (qz / k) * magnitude;
virtual std::vector< geometry_msgs::PointStamped > project(const robot_calibration_msgs::CalibrationData &data, const CalibrationOffsetParser &offsets)
Compute the position of the estimated points.
virtual std::string getType() const
Get the type for this model.
unsigned int getNrOfSegments() const
Combined parser and configuration for calibration offsets. Holds the configuration of what is to be c...
static Rotation Quaternion(double x, double y, double z, double w)
const Segment & getSegment(unsigned int nr) const
Frame getFrameToTip() const
double get(const std::string name) const
Get the offset.
ChainModel(const std::string &name, KDL::Tree model, std::string root, std::string tip)
Create a new chain model.
KDL::Frame getChainFK(const CalibrationOffsetParser &offsets, const sensor_msgs::JointState &state)
Compute the forward kinematics of the chain, based on the offsets and the joint positions of the stat...
const Joint & getJoint() const
Frame pose(const double &q) const
bool getChain(const std::string &chain_root, const std::string &chain_tip, Chain &chain) const
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
const JointType & getType() const
Calibration code lives under this namespace.
virtual std::string getType() const
Get the type of this model.
Camera3dModel(const std::string &name, const std::string ¶m_name, KDL::Tree model, std::string root, std::string tip)
Create a new camera 3d model (Kinect/Primesense).
void axis_magnitude_from_rotation(const KDL::Rotation &r, double &x, double &y, double &z)
Converts from KDL::Rotation to angle-axis-with-integrated-magnitude.
KDL::Rotation rotation_from_axis_magnitude(const double x, const double y, const double z)
Converts our angle-axis-with-integrated-magnitude representation to a KDL::Rotation.
virtual std::string getName() const
Get the name of this model (as provided in the YAML config)
bool getFrame(const std::string name, KDL::Frame &offset) const
Get the offset for a frame calibration.
INLINE Rall1d< T, V, S > acos(const Rall1d< T, V, S > &x)
void GetQuaternion(double &x, double &y, double &z, double &w) const
virtual std::vector< geometry_msgs::PointStamped > project(const robot_calibration_msgs::CalibrationData &data, const CalibrationOffsetParser &offsets)
Compute the updated positions of the observed points.
const std::string & getName() const
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Model of a kinematic chain. This is the basic instance where we transform the world observations into...
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
double positionFromMsg(const std::string &name, const sensor_msgs::JointState &msg)