36 #include <multisense_ros/DeviceInfo.h> 37 #include <multisense_ros/RawCamConfig.h> 38 #include <multisense_ros/RawCamCal.h> 39 #include <multisense_ros/RawCamData.h> 40 #include <multisense_ros/RawLidarData.h> 41 #include <multisense_ros/RawLidarCal.h> 42 #include <multisense_lib/MultiSenseTypes.hh> 46 #include <dynamic_reconfigure/DoubleParameter.h> 47 #include <dynamic_reconfigure/StrParameter.h> 48 #include <dynamic_reconfigure/Reconfigure.h> 49 #include <dynamic_reconfigure/Config.h> 53 #define TOPIC_DEVICE_INFO "/multisense/calibration/device_info" 54 #define TOPIC_RAW_CAM_CAL "/multisense/calibration/raw_cam_cal" 55 #define TOPIC_RAW_CAM_CONFIG "/multisense/calibration/raw_cam_config" 56 #define TOPIC_RAW_CAM_DATA "/multisense/calibration/raw_cam_data" 57 #define TOPIC_RAW_LIDAR "/multisense/calibration/raw_lidar_data" 58 #define TOPIC_RAW_LIDAR_CAL "/multisense/calibration/raw_lidar_cal" 66 LaserHelper() : motion_started_(
false) {}
68 void callback(
const multisense_ros::RawLidarData::ConstPtr& msg)
74 if (motion_started_ || 0 == scans_.size())
75 scans_.push_back(msg);
77 if (!motion_started_) {
78 std::list<multisense_ros::RawLidarData::ConstPtr>::const_iterator it = scans_.begin();
80 if (msg->angle_start != (*it)->angle_start) {
81 motion_started_ =
true;
83 scans_.push_back(msg);
94 std::list<multisense_ros::RawLidarData::ConstPtr>::const_iterator it;
100 if (scans_.end() == it)
106 double previous_start = (*it)->angle_start / 1000000.0;
107 double total_swept = 0.0;
109 for (it = scans_.begin(); it != scans_.end(); it++) {
111 double current_start = (*it)->angle_start / 1000000.0;
112 double current_swept = current_start - previous_start;
117 while(current_swept > M_PI)
118 current_swept -= 2*M_PI;
119 while(current_swept < -M_PI)
120 current_swept += 2*M_PI;
125 total_swept += current_swept;
130 previous_start = current_start;
133 return ( fabs(total_swept) > 2.0 * M_PI);
141 bool getRotation(std::list<multisense_ros::RawLidarData::ConstPtr>& scan_collection)
148 boost::bind(&LaserHelper::callback,
this, _1));
160 scan_collection = scans_;
171 #if __cplusplus >= 201103 172 static constexpr
double SCAN_COLLECT_TIMEOUT = 20.0;
174 static const double SCAN_COLLECT_TIMEOUT = 20.0;
177 bool motion_started_;
179 std::list<multisense_ros::RawLidarData::ConstPtr> scans_;
182 void setConf(
const dynamic_reconfigure::Config& conf)
184 dynamic_reconfigure::ReconfigureRequest srv_req;
185 dynamic_reconfigure::ReconfigureResponse srv_resp;
187 srv_req.config = conf;
192 void setMotorSpeed(
double radPerSec)
194 dynamic_reconfigure::DoubleParameter double_param;
195 dynamic_reconfigure::Config conf;
197 double_param.name =
"motor_speed";
198 double_param.value = radPerSec;
199 conf.doubles.push_back(double_param);
204 void setResolution(
const std::string& res)
206 dynamic_reconfigure::StrParameter str_param;
207 dynamic_reconfigure::Config conf;
209 str_param.name =
"resolution";
210 str_param.value = res;
211 conf.strs.push_back(str_param);
225 std::string(argvPP[1]) ==
"--help" ||
226 std::string(argvPP[1]) ==
"-h") {
228 printf(
"Usage: %s <out_bag_filename>\n", argvPP[0]);
232 std::string outfile(argvPP[1]);
234 printf(
"Capturing device information... "); fflush(stdout);
235 multisense_ros::DeviceInfo::ConstPtr device_info = ros::topic::waitForMessage<multisense_ros::DeviceInfo>(
TOPIC_DEVICE_INFO, nh);
237 printf(
" Error capturing DeviceInfo. Exiting\n");
240 printf(
" Success\n");
242 switch(device_info->imagerType) {
245 printf(
"Imager type is CMV2000; setting resolution to 1024x544x128... ");
246 setResolution(
"1024x544x128");
250 printf(
"Imager type is CMV4000; setting resolution to 1024x1024x128... ");
251 setResolution(
"1024x1024x128");
254 printf(
"Imager type is not recognized; not setting resolution... ");
255 printf(
" Error setting imager resolution. Exiting\n");
261 printf(
"Capturing lidar calibration... ");
262 multisense_ros::RawLidarCal::ConstPtr lidar_cal = ros::topic::waitForMessage<multisense_ros::RawLidarCal>(
TOPIC_RAW_LIDAR_CAL, nh);
264 printf(
" Error capturing RawLidarCal. Exiting\n");
267 printf(
" Success\n");
269 printf(
"Capturing camera calibration... "); fflush(stdout);
270 multisense_ros::RawCamCal::ConstPtr cam_cal = ros::topic::waitForMessage<multisense_ros::RawCamCal>(
TOPIC_RAW_CAM_CAL, nh);
272 printf(
" Error capturing RawCamCal. Exiting\n");
275 printf(
" Success\n");
277 printf(
"Capturing camera config... "); fflush(stdout);
278 multisense_ros::RawCamConfig::ConstPtr cam_config = ros::topic::waitForMessage<multisense_ros::RawCamConfig>(
TOPIC_RAW_CAM_CONFIG, nh);
280 printf(
" Error capturing RawCamConfig. Exiting\n");
283 printf(
" Success\n");
285 printf(
"Capturing a single left-rectified/disparity image pair... "); fflush(stdout);
286 multisense_ros::RawCamData::ConstPtr cam_data = ros::topic::waitForMessage<multisense_ros::RawCamData>(
TOPIC_RAW_CAM_DATA, nh);
288 printf(
" Error capturing RawCamData. Exiting\n");
291 printf(
" Success\n");
293 printf(
"Capturing a full rotation of lidar scans... "); fflush(stdout);
295 setMotorSpeed(0.785);
297 LaserHelper laser_helper;
298 std::list<multisense_ros::RawLidarData::ConstPtr> raw_lidar_data;
300 if (
false == laser_helper.getRotation(raw_lidar_data)) {
301 printf(
" Error capturing RawLidarData...\n");
304 printf(
" Captured %zu lidar scans\n", raw_lidar_data.size());
311 printf(
"Saving data to file [%s]\n", outfile.c_str());
321 std::list<multisense_ros::RawLidarData::ConstPtr>::const_iterator it;
322 for (it = raw_lidar_data.begin(); it != raw_lidar_data.end(); it++)
326 printf(
" Success\n");
static CRL_CONSTEXPR uint32_t IMAGER_TYPE_CMV4000_COLOR
void open(std::string const &filename, uint32_t mode=bagmode::Read)
static CRL_CONSTEXPR uint32_t IMAGER_TYPE_CMV2000_GREY
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
#define TOPIC_DEVICE_INFO
bool call(const std::string &service_name, MReq &req, MRes &res)
int main(int argc, char **argvPP)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define TOPIC_RAW_CAM_DATA
#define TOPIC_RAW_LIDAR_CAL
static CRL_CONSTEXPR uint32_t IMAGER_TYPE_CMV4000_GREY
void setCallbackQueue(CallbackQueueInterface *queue)
#define TOPIC_RAW_CAM_CAL
#define TOPIC_RAW_CAM_CONFIG
ROSTIME_DECL const Time TIME_MIN
static CRL_CONSTEXPR uint32_t IMAGER_TYPE_CMV2000_COLOR