log.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <thread>
3 
4 #include <boost/program_options.hpp>
5 #include <crazyflie_cpp/Crazyflie.h>
6 
7 void onLogCustom(uint32_t time_in_ms, std::vector<double>* values, void* /*userData*/)
8 {
9  std::cout << time_in_ms;
10  for (double v : *values) {
11  std::cout << "," << v;
12  }
13  std::cout << std::endl;
14 }
15 
16 int main(int argc, char **argv)
17 {
18 
19  std::string uri;
20  std::string defaultUri("radio://0/80/2M/E7E7E7E7E7");
21  std::vector<std::string> vars;
22  uint32_t period;
23 
24  namespace po = boost::program_options;
25 
26  po::options_description desc("Allowed options");
27  desc.add_options()
28  ("help", "produce help message")
29  ("var", po::value<std::vector<std::string>>(&vars)->multitoken(), "variable names to log")
30  ("period", po::value<uint32_t>(&period)->default_value(10), "sampling period in ms")
31  ("uri", po::value<std::string>(&uri)->default_value(defaultUri), "unique ressource identifier")
32  ;
33 
34  try
35  {
36  po::variables_map vm;
37  po::store(po::parse_command_line(argc, argv, desc), vm);
38  po::notify(vm);
39 
40  if (vm.count("help")) {
41  std::cout << desc << "\n";
42  return 0;
43  }
44  }
45  catch(po::error& e)
46  {
47  std::cerr << e.what() << std::endl << std::endl;
48  std::cerr << desc << std::endl;
49  return 1;
50  }
51 
52  try
53  {
54  Crazyflie cf(uri);
55  cf.requestLogToc();
56 
57  std::function<void(uint32_t, std::vector<double>*, void*)> cb = std::bind(&onLogCustom, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
58  LogBlockGeneric logBlock(&cf, vars, nullptr, cb);
59  logBlock.start(period / 10);
60 
61  while (true) {
62  cf.sendPing();
63  std::this_thread::sleep_for(std::chrono::milliseconds(10));
64  }
65  }
66  catch(std::exception& e)
67  {
68  std::cerr << e.what() << std::endl;
69  return 1;
70  }
71 }
void requestLogToc(bool forceNoCache=false)
Definition: Crazyflie.cpp:586
uint8_t error
const T value
Definition: crtp.h:26
void sendPing()
Definition: Crazyflie.cpp:264
void onLogCustom(uint32_t time_in_ms, std::vector< double > *values, void *)
Definition: log.cpp:7
uint8_t period
Definition: crtp.h:445
void start(uint8_t period)
int main(int argc, char **argv)
Definition: log.cpp:16


crazyflie_tools
Author(s): Wolfgang Hoenig
autogenerated on Mon Sep 28 2020 03:40:15