log.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <thread>
00003 
00004 #include <boost/program_options.hpp>
00005 #include <crazyflie_cpp/Crazyflie.h>
00006 
00007 void onLogCustom(uint32_t time_in_ms, std::vector<double>* values, void* /*userData*/)
00008 {
00009   std::cout << time_in_ms;
00010   for (double v : *values) {
00011     std::cout << "," << v;
00012   }
00013   std::cout << std::endl;
00014 }
00015 
00016 int main(int argc, char **argv)
00017 {
00018 
00019   std::string uri;
00020   std::string defaultUri("radio://0/80/2M/E7E7E7E7E7");
00021   std::vector<std::string> vars;
00022   uint32_t period;
00023 
00024   namespace po = boost::program_options;
00025 
00026   po::options_description desc("Allowed options");
00027   desc.add_options()
00028     ("help", "produce help message")
00029     ("var", po::value<std::vector<std::string>>(&vars)->multitoken(), "variable names to log")
00030     ("period", po::value<uint32_t>(&period)->default_value(10), "sampling period in ms")
00031     ("uri", po::value<std::string>(&uri)->default_value(defaultUri), "unique ressource identifier")
00032   ;
00033 
00034   try
00035   {
00036     po::variables_map vm;
00037     po::store(po::parse_command_line(argc, argv, desc), vm);
00038     po::notify(vm);
00039 
00040     if (vm.count("help")) {
00041       std::cout << desc << "\n";
00042       return 0;
00043     }
00044   }
00045   catch(po::error& e)
00046   {
00047     std::cerr << e.what() << std::endl << std::endl;
00048     std::cerr << desc << std::endl;
00049     return 1;
00050   }
00051 
00052   try
00053   {
00054     Crazyflie cf(uri);
00055     cf.requestLogToc();
00056 
00057     std::function<void(uint32_t, std::vector<double>*, void*)> cb = std::bind(&onLogCustom, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
00058     LogBlockGeneric logBlock(&cf, vars, nullptr, cb);
00059     logBlock.start(period / 10);
00060 
00061     while (true) {
00062       cf.sendPing();
00063       std::this_thread::sleep_for(std::chrono::milliseconds(10));
00064     }
00065   }
00066   catch(std::exception& e)
00067   {
00068     std::cerr << e.what() << std::endl;
00069     return 1;
00070   }
00071 }


crazyflie_tools
Author(s): Wolfgang Hoenig
autogenerated on Wed Jun 12 2019 19:20:48