57 if (cache.size() == 0)
60 unsigned int num_channels = cache.back().channels_.size();
63 allocateImages(snapshot.num_scans, snapshot.readings_per_scan, num_channels);
65 vector<double> cur_positions;
69 unsigned int after_index = 0;
70 for (
unsigned int i=0; i<snapshot.num_scans; i++)
72 for (
unsigned int j=0; j<snapshot.readings_per_scan; j++)
75 while(after_index < cache.size() && cache[after_index].header.stamp < pixel_time)
77 assert(after_index < cache.size());
78 assert(after_index > 0);
81 ros::Duration interp_diff = cache[after_index].header.stamp - cache[after_index-1].header.stamp;
82 if (interp_diff > max_interp)
84 ROS_WARN(
"Interpolating between elems that are [%.2fs] apart. Probably dopped some messages. Going to ignore this snapshot", interp_diff.
toSec());
91 for (
unsigned int k=0;k<num_channels;k++)
92 images[k](i,j)[0] = cur_positions[k];
94 ros::Time scan_start_time = snapshot.scan_start[i];
95 ros::Time scan_end_time = snapshot.scan_start[i] +
ros::Duration(snapshot.time_increment * (snapshot.readings_per_scan-1));
97 for (
unsigned int k=0; k<num_channels; k++)
99 float start_pos = images[k](i,0)[0];
100 float end_pos = images[k](i,snapshot.readings_per_scan-1)[0];
101 float vel = (end_pos - start_pos) / (scan_end_time-scan_start_time).toSec();
103 float* vel_ptr = &images[k](i,0)[1];
104 for (
unsigned int j=0; j<snapshot.readings_per_scan; j++)
149 cv::Mat_<cv::Vec2f> image = getJointImage(i);
151 for (
int i=0; i<image.rows; i++)
153 for (
int j=0; j<image.cols; j++)
155 printf(
"%5.2f ", image(i,j)[0]);
163 FILE* file = fopen(filename.c_str(),
"w");
166 printf(
"About to write to file %s\n", filename.c_str());
168 cv::Mat_<cv::Vec2f> image = getJointImage(i);
170 for (
int i=0; i<image.rows; i++)
172 for (
int j=0; j<image.cols; j++)
174 fprintf(file,
"% 3.2f ", image(i,j)[0]);
185 vector<double>& result)
194 ROS_ERROR(
"Couldn't find elem before time");
200 ROS_ERROR(
"Couldn't find elem after time");
205 ROS_ERROR(
"# of joints has changed in the middle of a run");
212 ROS_ERROR(
"Error performing interpolation");
221 vector<double>& result)
223 vector<double> start_positions;
224 vector<double> end_positions;
227 success = interpPosition(start, cache, start_positions);
230 ROS_ERROR(
"Error extracting start position");
234 success = interpPosition(end, cache, end_positions);
237 ROS_ERROR(
"Error extracting start position");
241 if (start_positions.size() != end_positions.size())
243 ROS_ERROR(
"# of joints has changed during run. Can't compute velocity between samples");
247 const unsigned int N = start_positions.size();
250 for (
unsigned int i=0; i<N; i++)
251 result[i] = (end_positions[i] - start_positions[i]) / (end-start).toSec();
258 images.resize(channels);
260 cv::Size image_size = cv::Size(width, height);
262 for (
unsigned int i=0; i<channels; i++)
263 images[i] = cv::Mat_<cv::Vec2f>(image_size);
268 return images[index];
bool computeVelocity(const ros::Time &start, const ros::Time &end, const settlerlib::SortedDeque< joint_states_settler::DeflatedJointStates > &cache, std::vector< double > &result)
static bool interp(const Deflated &before, const Deflated &after, const ros::Time &target, std::vector< double > &result)
void displayImage(unsigned int i)
void allocateImages(unsigned int height, unsigned int width, unsigned int channels)
bool getElemAfterTime(const ros::Time &time, M &out) const
std::vector< double > channels_
bool getElemBeforeTime(const ros::Time &time, M &out) const
void writeImage(unsigned int i, const std::string &filename)
bool update(const calibration_msgs::DenseLaserSnapshot &snapshot, const settlerlib::SortedDeque< joint_states_settler::DeflatedJointStates > &cache, const ros::Duration &max_interp=ros::Duration(.25))
bool interpPosition(const ros::Time &target, const settlerlib::SortedDeque< joint_states_settler::DeflatedJointStates > &cache, std::vector< double > &result)
cv::Mat_< cv::Vec2f > getJointImage(unsigned int index) const