fcu_test.cpp
Go to the documentation of this file.
00001 #include <FlightController.hpp>
00002 #include <iostream>
00003 #include <msp_msg.hpp>
00004 
00005 class App {
00006 public:
00007     std::string name;
00008 
00009     App(const std::string name) { this->name = name; }
00010 
00011     void onIdent(const msp::msg::Ident& ident) { std::cout << ident; }
00012 
00013     void onStatus(const msp::msg::Status& status) { std::cout << status; }
00014 
00015     void onImu(const msp::msg::RawImu& imu_raw) { std::cout << imu_raw; }
00016 
00017     void onServo(const msp::msg::Servo& servo) { std::cout << servo; }
00018 
00019     void onMotor(const msp::msg::Motor& motor) { std::cout << motor; }
00020 
00021     void onRc(const msp::msg::Rc& rc) { std::cout << rc; }
00022 
00023     void onAttitude(const msp::msg::Attitude& attitude) {
00024         std::cout << attitude;
00025     }
00026 
00027     void onAltitude(const msp::msg::Altitude& altitude) {
00028         std::cout << altitude;
00029     }
00030 
00031     void onAnalog(const msp::msg::Analog& analog) { std::cout << analog; }
00032 
00033     void onRcTuning(const msp::msg::RcTuning& rc_tuning) {
00034         std::cout << rc_tuning;
00035     }
00036 
00037     void onPID(const msp::msg::Pid& pid) { std::cout << pid; }
00038 
00039     void onBox(const msp::msg::ActiveBoxes& box) { std::cout << box; }
00040 
00041     void onMisc(const msp::msg::Misc& misc) { std::cout << misc; }
00042 
00043     void onMotorPins(const msp::msg::MotorPins& motor_pins) {
00044         std::cout << motor_pins;
00045     }
00046 
00047     void onBoxNames(const msp::msg::BoxNames& box_names) {
00048         std::cout << box_names;
00049     }
00050 
00051     void onPidNames(const msp::msg::PidNames& pid_names) {
00052         std::cout << pid_names;
00053     }
00054 
00055     void onBoxIds(const msp::msg::BoxIds& box_ids) { std::cout << box_ids; }
00056 
00057     void onServoConf(const msp::msg::ServoConf& servo_conf) {
00058         std::cout << servo_conf;
00059     }
00060 
00061     void onDebugMessage(const msp::msg::DebugMessage& debug_msg) {
00062         std::cout << "#Debug message:" << std::endl;
00063         std::cout << debug_msg.debug_msg << std::endl;
00064     }
00065 
00066     void onDebug(const msp::msg::Debug& debug) { std::cout << debug; }
00067 
00068 private:
00069 };
00070 
00071 int main(int argc, char* argv[]) {
00072     const std::string device =
00073         (argc > 1) ? std::string(argv[1]) : "/dev/ttyUSB0";
00074     const size_t baudrate = (argc > 2) ? std::stoul(argv[2]) : 115200;
00075 
00076     fcu::FlightController fcu;
00077     fcu.setLoggingLevel(msp::client::LoggingLevel::INFO);
00078     // wait for connection
00079     fcu.connect(device, baudrate);
00080 
00081     App app("MultiWii");
00082 
00083     fcu.subscribe<msp::msg::RawImu>(
00084         [](const msp::msg::RawImu& imu) {
00085             std::cout << msp::msg::ImuSI(
00086                 imu, 512.0, 1.0 / 4.096, 0.92f / 10.0f, 9.80665f);
00087         },
00088         0.1);
00089 
00090     // define subscriptions with specific period
00091     fcu.subscribe(&App::onIdent, &app, 10);
00092     fcu.subscribe(&App::onStatus, &app, 1);
00093 
00094     // using class method callback
00095     // fcu.subscribe(&App::onImu, &app, 0.1);
00096 
00097     fcu.subscribe(&App::onServo, &app, 0.1);
00098     fcu.subscribe(&App::onMotor, &app, 0.1);
00099     fcu.subscribe(&App::onRc, &app, 0.1);
00100     // TODO: RawGPS
00101     // TODO: CompGPS
00102     fcu.subscribe(&App::onAttitude, &app);
00103     fcu.subscribe(&App::onAltitude, &app);
00104     fcu.subscribe(&App::onAnalog, &app, 10);
00105     fcu.subscribe(&App::onRcTuning, &app, 20);
00106     fcu.subscribe(&App::onPID, &app, 20);
00107     fcu.subscribe(&App::onBox, &app, 1);
00108     fcu.subscribe(&App::onMisc, &app, 1);
00109     fcu.subscribe(&App::onMotorPins, &app, 20);
00110     fcu.subscribe(&App::onBoxNames, &app, 1);
00111     fcu.subscribe(&App::onPidNames, &app, 20);
00112     // TODO: WayPoint
00113     fcu.subscribe(&App::onBoxIds, &app, 1);
00114     fcu.subscribe(&App::onServoConf, &app, 20);
00115     // TODO: NavStatus
00116     // TODO: NavConfig
00117     fcu.subscribe(&App::onDebugMessage, &app, 1);
00118     fcu.subscribe(&App::onDebug, &app, 1);
00119 
00120     // Ctrl+C to quit
00121     std::cin.get();
00122 }


msp
Author(s): Christian Rauch
autogenerated on Thu Jun 20 2019 19:40:38