Go to the documentation of this file.00001 #include <iostream>
00002 #include <chrono>
00003 #include <thread>
00004
00005 #include <boost/program_options.hpp>
00006 #include <crazyflie_cpp/Crazyflie.h>
00007
00008 struct log {
00009 float pm_vbat;
00010 float pm_extVbat;
00011 float pm_extCurr;
00012
00013 } __attribute__((packed));
00014
00015 volatile bool g_done = false;
00016
00017 void onLogData(uint32_t , struct log* data)
00018 {
00019
00020 std::cout << data->pm_extVbat << std::endl;
00021
00022 g_done = true;
00023 }
00024
00025 int main(int argc, char **argv)
00026 {
00027
00028 std::string uri;
00029 std::string defaultUri("radio://0/80/2M/E7E7E7E7E7");
00030 bool external;
00031
00032 namespace po = boost::program_options;
00033
00034 po::options_description desc("Allowed options");
00035 desc.add_options()
00036 ("help", "produce help message")
00037 ("uri", po::value<std::string>(&uri)->default_value(defaultUri), "unique ressource identifier")
00038 ("external", po::value<bool>(&external)->default_value(false), "measure external voltage")
00039 ;
00040
00041 try
00042 {
00043 po::variables_map vm;
00044 po::store(po::parse_command_line(argc, argv, desc), vm);
00045 po::notify(vm);
00046
00047 if (vm.count("help")) {
00048 std::cout << desc << "\n";
00049 return 0;
00050 }
00051 }
00052 catch(po::error& e)
00053 {
00054 std::cerr << e.what() << std::endl << std::endl;
00055 std::cerr << desc << std::endl;
00056 return 1;
00057 }
00058
00059 try
00060 {
00061 Crazyflie cf(uri);
00062
00063 if (!external) {
00064 std::cout << cf.vbat() << std::endl;
00065 } else {
00066 cf.logReset();
00067 cf.requestLogToc();
00068
00069 std::unique_ptr<LogBlock<struct log> > logBlock;
00070 std::function<void(uint32_t, struct log*)> cb = std::bind(&onLogData, std::placeholders::_1, std::placeholders::_2);
00071
00072 logBlock.reset(new LogBlock<struct log>(
00073 &cf,{
00074 {"pm", "vbat"},
00075 {"pm", "extVbat"},
00076 {"pm", "extCurr"}
00077
00078 }, cb));
00079 logBlock->start(10);
00080
00081 while (!g_done) {
00082 cf.sendPing();
00083 std::this_thread::sleep_for(std::chrono::milliseconds(10));
00084 }
00085 }
00086
00087 return 0;
00088 }
00089 catch(std::exception& e)
00090 {
00091 std::cerr << e.what() << std::endl;
00092 return 1;
00093 }
00094 }