battery.cpp
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 chargeCurrent;
00011 } __attribute__((packed));
00012 
00013 volatile bool g_done = false;
00014 
00015 void onLogData(uint32_t time_in_ms, struct log* data)
00016 {
00017   std::cout << data->pm_vbat << std::endl;
00018   g_done = true;
00019 }
00020 
00021 int main(int argc, char **argv)
00022 {
00023 
00024   std::string uri;
00025   std::string defaultUri("radio://0/80/2M/E7E7E7E7E7");
00026 
00027   namespace po = boost::program_options;
00028 
00029   po::options_description desc("Allowed options");
00030   desc.add_options()
00031     ("help", "produce help message")
00032     ("uri", po::value<std::string>(&uri)->default_value(defaultUri), "unique ressource identifier")
00033   ;
00034 
00035   try
00036   {
00037     po::variables_map vm;
00038     po::store(po::parse_command_line(argc, argv, desc), vm);
00039     po::notify(vm);
00040 
00041     if (vm.count("help")) {
00042       std::cout << desc << "\n";
00043       return 0;
00044     }
00045   }
00046   catch(po::error& e)
00047   {
00048     std::cerr << e.what() << std::endl << std::endl;
00049     std::cerr << desc << std::endl;
00050     return 1;
00051   }
00052 
00053   try
00054   {
00055     Crazyflie cf(uri);
00056     std::cout << cf.vbat() << std::endl;
00057     // cf.logReset();
00058     // cf.requestLogToc();
00059 
00060     // std::unique_ptr<LogBlock<struct log> > logBlock;
00061     // std::function<void(uint32_t, struct log*)> cb = std::bind(&onLogData, std::placeholders::_1, std::placeholders::_2);
00062 
00063     // logBlock.reset(new LogBlock<struct log>(
00064     //   &cf,{
00065     //     {"pm", "vbat"},
00066     //     // {"pm", "chargeCurrent"}
00067     //   }, cb));
00068     // logBlock->start(10); // 100ms
00069 
00070     // while (!g_done) {
00071     //   cf.sendPing();
00072     //   std::this_thread::sleep_for(std::chrono::milliseconds(10));
00073     // }
00074 
00075     return 0;
00076   }
00077   catch(std::exception& e)
00078   {
00079     std::cerr << e.what() << std::endl;
00080     return 1;
00081   }
00082 }


crazyflie_tools
Author(s): Wolfgang Hoenig
autogenerated on Sun Oct 8 2017 02:48:04