9 #pragma GCC diagnostic push 10 #pragma GCC diagnostic ignored "-Wold-style-cast" 11 #pragma GCC diagnostic push 12 #pragma GCC diagnostic ignored "-Wshadow" 13 #include <geometry_msgs/PoseStamped.h> 14 #include <geometry_msgs/TransformStamped.h> 17 #include <rosflight_msgs/Command.h> 18 #include <sensor_msgs/Imu.h> 19 #include <yaml-cpp/yaml.h> 20 #include <boost/foreach.hpp> 21 #include <experimental/filesystem> 22 #pragma GCC diagnostic pop 31 namespace fs = std::experimental::filesystem;
36 if (!fs::exists(filename))
38 cout <<
"unable to find parameter file " << filename << endl;
44 YAML::Node node = YAML::LoadFile(filename);
45 for (
auto it = node.begin(); it != node.end(); it++)
47 if ((*it)[
"type"].as<
int>() == 6)
49 else if ((*it)[
"type"].as<int>() == 9)
52 throw std::runtime_error(
"unrecognized parameter type");
60 std::cout <<
"Failed to Read yaml file. Could you have a syntax error?" << filename << std::endl;
63 cout <<
"loaded parameters from " << filename << endl;
69 cout <<
"USAGE: rosbag_parser [options]" 72 cout <<
"\t -h, --help\tShow this help message and exit\n";
73 cout <<
"\t -f FILENAME\tBagfile to parse\n";
74 cout <<
"\t -p FILENAME\tParameter file to load\n";
75 cout <<
"\t -s START_TIME\tstart time of bag (seconds)\n";
76 cout <<
"\t -u DURATION\tduration to run bag (seconds)\n";
77 cout <<
"\t -v Show Verbose Output\n";
81 int main(
int argc,
char *argv[])
83 string bag_filename =
"";
86 double duration = INFINITY;
87 string param_filename =
"";
106 fprintf(stderr,
"unable to load rosbag %s, %s", bag_filename.c_str(), e.what());
114 vector<const rosbag::ConnectionInfo *> connections = view.
getConnections();
115 vector<string> topics;
116 vector<string> types;
117 cout <<
"\nloaded bagfile: " << bag_filename <<
"\n===================================\n";
118 cout <<
"Topics\t\tTypes\n----------------------------\n\n" << endl;
121 topics.push_back(info->topic);
122 types.push_back(info->datatype);
123 cout << info->topic <<
"\t\t" << info->datatype << endl;
128 double end_time = start_time + duration;
133 cout <<
"Playing bag from: = " << start_time <<
"s to: " << end_time <<
"s" << endl;
141 if (!param_filename.empty())
152 fstream est_log, truth_log, imu_log, filtered_imu_log, cmd_log;
153 fs::create_directories(
"/tmp/rosflight_post_process/");
154 est_log.open(
"/tmp/rosflight_post_process/estimate.bin",
std::ofstream::out | std::ofstream::trunc);
155 truth_log.open(
"/tmp/rosflight_post_process/truth.bin",
std::ofstream::out | std::ofstream::trunc);
156 imu_log.open(
"/tmp/rosflight_post_process/imu.bin",
std::ofstream::out | std::ofstream::trunc);
157 filtered_imu_log.open(
"/tmp/rosflight_post_process/imu_filt.bin",
std::ofstream::out | std::ofstream::trunc);
158 cmd_log.open(
"/tmp/rosflight_post_process/cmd.bin",
std::ofstream::out | std::ofstream::trunc);
162 bool time_initialized =
false;
163 bool pose_initialized =
false;
167 if (m.getTime() < bag_start)
171 if (m.getTime() > bag_end)
179 string datatype = m.getDataType();
181 if (datatype.compare(
"sensor_msgs/Imu") == 0)
183 const sensor_msgs::ImuConstPtr
imu(m.instantiate<sensor_msgs::Imu>());
185 if (!time_initialized)
187 bag_start = imu->header.stamp;
189 time_initialized =
true;
193 float acc[3] = {(float)imu->linear_acceleration.x, (
float)imu->linear_acceleration.y,
194 (float)imu->linear_acceleration.z};
195 float gyro[3] = {(float)imu->angular_velocity.x, (
float)imu->angular_velocity.y, (float)imu->angular_velocity.z};
196 int64_t t_us = (imu->header.stamp - bag_start).toNSec() / 1000;
198 board.
set_imu(acc, gyro, t_us);
200 double est[8] = {(double)t_us / 1e6,
208 est_log.write((
char *)est,
sizeof(est));
210 double imud[7] = {(double)t_us / 1e6, (
double)acc[0], (double)acc[1], (
double)acc[2],
211 (double)gyro[0], (
double)gyro[1], (double)gyro[2]};
212 imu_log.write((
char *)imud,
sizeof(imud));
214 double imuf[7] = {(double)t_us / 1e6,
222 filtered_imu_log.write((
char *)imuf,
sizeof(imuf));
225 else if (datatype.compare(
"geometry_msgs/PoseStamped") == 0)
227 const geometry_msgs::PoseStampedConstPtr pose(m.instantiate<geometry_msgs::PoseStamped>());
228 double t = (pose->header.stamp - bag_start).toSec();
229 double truth[5] = {t, pose->pose.orientation.w, pose->pose.orientation.x, pose->pose.orientation.y,
230 pose->pose.orientation.z};
231 truth_log.write((
char *)truth,
sizeof(truth));
234 else if (datatype.compare(
"geometry_msgs/TransformStamped") == 0)
236 const geometry_msgs::TransformStampedConstPtr trans(m.instantiate<geometry_msgs::TransformStamped>());
237 double t = (trans->header.stamp - bag_start).toSec();
238 double truth[5] = {t, trans->transform.rotation.w, trans->transform.rotation.x, trans->transform.rotation.y,
239 trans->transform.rotation.z};
240 truth_log.write((
char *)truth,
sizeof(truth));
243 else if (datatype.compare(
"rosflight_msgs/Command") == 0)
245 const rosflight_msgs::CommandConstPtr
cmd(m.instantiate<rosflight_msgs::Command>());
246 double t = (cmd->header.stamp - bag_start).toSec();
247 double cmdarr[5] = {t, cmd->x, cmd->y, cmd->z, cmd->F};
248 cmd_log.write((
char *)cmdarr,
sizeof(cmdarr));
252 std::cout << std::endl;
254 #pragma GCC diagnostic pop
const turbomath::Vector & accLPF()
std::vector< const ConnectionInfo * > getConnections()
void open(std::string const &filename, uint32_t mode=bagmode::Read)
void set_imu(float *acc, float *gyro, uint64_t time_us)
const turbomath::Vector & bias()
bool loadParameters(const string filename, rosflight_firmware::ROSflight &RF)
const State & state() const
const turbomath::Vector & gyroLPF()
void set_time(uint64_t time_us)
turbomath::Quaternion attitude
int main(int argc, char *argv[])
bool set_param_by_name_int(const char name[PARAMS_NAME_LENGTH], int32_t value)
bool set_param_by_name_float(const char name[PARAMS_NAME_LENGTH], float value)