msp_connection_test.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <MSP.hpp>
00003 #include <msp_msg.hpp>
00004 
00005 #include <chrono>
00006 
00007 int main(int argc, char *argv[]) {
00008     const std::string device = (argc>1) ? std::string(argv[1]) : "/dev/ttyUSB0";
00009     const uint baudrate = (argc>2) ? std::stoul(argv[2]) : 115200;
00010 
00011     msp::MSP msp(device, baudrate);
00012     msp.setWait(1);
00013 
00014     // try connecting until first package is received
00015     {
00016     std::cout<<"Waiting for flight controller to become ready..."<<std::endl;
00017     auto start = std::chrono::steady_clock::now();
00018     msp::msg::Ident ident;
00019     if(msp.request_wait(ident, 10)) {
00020         auto end = std::chrono::steady_clock::now();
00021         std::cout<<"MSP version "<<(int)ident.version<<" ready after: "<<std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count()<<" ms"<<std::endl;
00022     }
00023     else {
00024         std::cout << "error getting MSP version" << std::endl;
00025     }
00026     }
00027 
00028     // test update rate for reading Gyro messages
00029     {
00030     const unsigned int max_msg = 1000;
00031     unsigned int n_msg = 0;
00032     auto start = std::chrono::steady_clock::now();
00033     while(n_msg!=max_msg) {
00034         msp::msg::ImuRaw status;
00035         msp.request_block(status);
00036         n_msg++;
00037     }
00038     auto end = std::chrono::steady_clock::now();
00039 
00040     auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
00041 
00042     std::cout<<"read "<<max_msg<<" messages in: "<<duration<<" ms"<<std::endl;
00043     std::cout<<"messages per second: "<<max_msg/(duration/1000.0)<<" Hz"<<std::endl;
00044     }
00045 
00046     return 0;
00047 }


msp
Author(s): Christian Rauch
autogenerated on Mon Oct 9 2017 03:02:13