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


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