00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00036
00037 #include <laser_joint_processor/laser_joint_processor.h>
00038
00039 using namespace laser_joint_processor;
00040 using namespace std;
00041
00042 LaserJointProcessor::LaserJointProcessor()
00043 {
00044
00045 }
00046
00047 void LaserJointProcessor::setCacheSize(unsigned int max_size)
00048 {
00049 joint_state_cache_.setMaxSize(max_size);
00050 }
00051
00052 void LaserJointProcessor::setJointNames(const std::vector<std::string>& joint_names)
00053 {
00054 joint_names_ = joint_names;
00055 deflater_.setDeflationJointNames(joint_names);
00056 }
00057
00058 bool LaserJointProcessor::addJointState(const sensor_msgs::JointStateConstPtr& joint_state)
00059 {
00060 joint_states_settler::DeflatedJointState deflated;
00061 deflater_.deflate(joint_state, deflated);
00062
00063 joint_state_cache_.add(deflated);
00064
00065 return true;
00066 }
00067
00068 bool LaserJointProcessor::isSnapshotEarly(const calibration_msgs::DenseLaserSnapshot& snapshot) const
00069 {
00070 ROS_DEBUG("Checking if snapshot is early:");
00071 if (joint_state_cache_.size() == 0)
00072 {
00073 ROS_DEBUG(" cache is empty, so snapshot is definitely early");
00074 return true;
00075 }
00076 if (snapshot.scan_start.size() == 0)
00077 ROS_FATAL("Received malformed DenseLaserSnapshot. (scan_start.size() == 0)");
00078 ros::Time snapshot_end = snapshot.scan_start.back() + ros::Duration(snapshot.time_increment*(snapshot.num_scans-1));
00079
00080 ros::Time cache_front = joint_state_cache_.front().header.stamp;
00081 ros::Time cache_back = joint_state_cache_.back().header.stamp;
00082 ROS_DEBUG(" Newest elem in cache (back): %u.%u", cache_back.sec, cache_back.nsec);
00083 ROS_DEBUG(" Oldest elem in cache (front): %u.%u", cache_front.sec, cache_front.nsec);
00084 ROS_DEBUG(" End of snapshot: %u.%u", snapshot_end.sec, snapshot_end.nsec);
00085 ros::Duration diff = snapshot_end - cache_back;
00086 ROS_DEBUG(" cache_back - snapshot_end: %.2f", diff.toSec());
00087
00088 return diff >= ros::Duration(0,0);
00089 }
00090
00091 bool LaserJointProcessor::isSnapshotLate(const calibration_msgs::DenseLaserSnapshot& snapshot) const
00092 {
00093 ROS_DEBUG("Checking if snapshot is late:");
00094 if (joint_state_cache_.size() == 0)
00095 {
00096 ROS_DEBUG(" cache is empty, so snapshot isn't late yet");
00097 return false;
00098 }
00099
00100 if (snapshot.scan_start.size() == 0)
00101 ROS_FATAL("Received malformed DenseLaserSnapshot. (scan_start.size() == 0)");
00102 ros::Time snapshot_start = snapshot.scan_start.front();
00103 ros::Time cache_front = joint_state_cache_.front().header.stamp;
00104 ros::Time cache_back = joint_state_cache_.back().header.stamp;
00105
00106 ros::Duration diff = snapshot_start - cache_front;
00107
00108 ROS_DEBUG(" Newest elem in cache (back): %u.%u", cache_back.sec, cache_back.nsec);
00109 ROS_DEBUG(" Oldest elem in cache (front): %u.%u", cache_front.sec, cache_front.nsec);
00110 ROS_DEBUG(" Start of snapshot: %u.%u", snapshot_start.sec, snapshot_start.nsec);
00111 ROS_DEBUG(" cache_front - snapshot_start: %.2f", diff.toSec());
00112
00113 return diff <= ros::Duration(0,0);
00114 }
00115
00116 bool LaserJointProcessor::processLaserData( const calibration_msgs::DenseLaserSnapshot& snapshot,
00117 const calibration_msgs::CalibrationPattern& features,
00118 calibration_msgs::JointStateCalibrationPattern& result,
00119 const ros::Duration& max_interp)
00120 {
00121
00122 const unsigned int num_joints = joint_names_.size();
00123
00124 const unsigned int P = features.image_points.size();
00125
00126 result.object_points = features.object_points;
00127 result.joint_points.clear();
00128 result.joint_points.resize(P);
00129
00130 bool success;
00131 success = imager_.update(snapshot, joint_state_cache_, max_interp);
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 if (!success)
00168 {
00169 ROS_ERROR("imager_.update failed");
00170 return false;
00171 }
00172
00173 for (unsigned int j=0; j<num_joints; j++)
00174 {
00175
00176 vector<float> positions;
00177 vector<float> velocities;
00178 interp_.interp(features.image_points, imager_.getJointImage(j),
00179 positions, velocities);
00180
00181 for (unsigned int i=0; i<P; i++)
00182 {
00183 result.joint_points[i].name.push_back(joint_names_[j]);
00184 result.joint_points[i].position.push_back(positions[i]);
00185 result.joint_points[i].velocity.push_back(velocities[i]);
00186 result.joint_points[i].effort.push_back(1234);
00187 }
00188 }
00189
00190 vector<float> laser_angles;
00191 vector<float> laser_ranges;
00192
00193 success = interpSnapshot(features.image_points, snapshot, laser_angles, laser_ranges);
00194 if (!success)
00195 {
00196 ROS_ERROR("interpSnapshot failed");
00197 return false;
00198 }
00199
00200 for (unsigned int i=0; i<P; i++)
00201 {
00202 result.joint_points[i].name.push_back("laser_angle_joint");
00203 result.joint_points[i].position.push_back(laser_angles[i]);
00204 result.joint_points[i].velocity.push_back(0);
00205 result.joint_points[i].effort.push_back(1234);
00206
00207 result.joint_points[i].name.push_back("laser_range_joint");
00208 result.joint_points[i].position.push_back(laser_ranges[i]);
00209 result.joint_points[i].velocity.push_back(0);
00210 result.joint_points[i].effort.push_back(1234);
00211 }
00212
00213 result.header.stamp = snapshot.header.stamp;
00214
00215 return true;
00216 }
00217
00218
00219
00220