fcu_test.cpp
Go to the documentation of this file.
1 #include <FlightController.hpp>
2 #include <iostream>
3 #include <msp_msg.hpp>
4 
5 class App {
6 public:
7  std::string name;
8 
9  App(const std::string name) { this->name = name; }
10 
11  void onIdent(const msp::msg::Ident& ident) { std::cout << ident; }
12 
13  void onStatus(const msp::msg::Status& status) { std::cout << status; }
14 
15  void onImu(const msp::msg::RawImu& imu_raw) { std::cout << imu_raw; }
16 
17  void onServo(const msp::msg::Servo& servo) { std::cout << servo; }
18 
19  void onMotor(const msp::msg::Motor& motor) { std::cout << motor; }
20 
21  void onRc(const msp::msg::Rc& rc) { std::cout << rc; }
22 
23  void onAttitude(const msp::msg::Attitude& attitude) {
24  std::cout << attitude;
25  }
26 
27  void onAltitude(const msp::msg::Altitude& altitude) {
28  std::cout << altitude;
29  }
30 
31  void onAnalog(const msp::msg::Analog& analog) { std::cout << analog; }
32 
33  void onRcTuning(const msp::msg::RcTuning& rc_tuning) {
34  std::cout << rc_tuning;
35  }
36 
37  void onPID(const msp::msg::Pid& pid) { std::cout << pid; }
38 
39  void onBox(const msp::msg::ActiveBoxes& box) { std::cout << box; }
40 
41  void onMisc(const msp::msg::Misc& misc) { std::cout << misc; }
42 
43  void onMotorPins(const msp::msg::MotorPins& motor_pins) {
44  std::cout << motor_pins;
45  }
46 
47  void onBoxNames(const msp::msg::BoxNames& box_names) {
48  std::cout << box_names;
49  }
50 
51  void onPidNames(const msp::msg::PidNames& pid_names) {
52  std::cout << pid_names;
53  }
54 
55  void onBoxIds(const msp::msg::BoxIds& box_ids) { std::cout << box_ids; }
56 
57  void onServoConf(const msp::msg::ServoConf& servo_conf) {
58  std::cout << servo_conf;
59  }
60 
61  void onDebugMessage(const msp::msg::DebugMessage& debug_msg) {
62  std::cout << "#Debug message:" << std::endl;
63  std::cout << debug_msg.debug_msg << std::endl;
64  }
65 
66  void onDebug(const msp::msg::Debug& debug) { std::cout << debug; }
67 
68 private:
69 };
70 
71 int main(int argc, char* argv[]) {
72  const std::string device =
73  (argc > 1) ? std::string(argv[1]) : "/dev/ttyUSB0";
74  const size_t baudrate = (argc > 2) ? std::stoul(argv[2]) : 115200;
75 
78  // wait for connection
79  fcu.connect(device, baudrate);
80 
81  App app("MultiWii");
82 
84  [](const msp::msg::RawImu& imu) {
85  std::cout << msp::msg::ImuSI(
86  imu, 512.0, 1.0 / 4.096, 0.92f / 10.0f, 9.80665f);
87  },
88  0.1);
89 
90  // define subscriptions with specific period
91  fcu.subscribe(&App::onIdent, &app, 10);
92  fcu.subscribe(&App::onStatus, &app, 1);
93 
94  // using class method callback
95  // fcu.subscribe(&App::onImu, &app, 0.1);
96 
97  fcu.subscribe(&App::onServo, &app, 0.1);
98  fcu.subscribe(&App::onMotor, &app, 0.1);
99  fcu.subscribe(&App::onRc, &app, 0.1);
100  // TODO: RawGPS
101  // TODO: CompGPS
102  fcu.subscribe(&App::onAttitude, &app);
103  fcu.subscribe(&App::onAltitude, &app);
104  fcu.subscribe(&App::onAnalog, &app, 10);
105  fcu.subscribe(&App::onRcTuning, &app, 20);
106  fcu.subscribe(&App::onPID, &app, 20);
107  fcu.subscribe(&App::onBox, &app, 1);
108  fcu.subscribe(&App::onMisc, &app, 1);
109  fcu.subscribe(&App::onMotorPins, &app, 20);
110  fcu.subscribe(&App::onBoxNames, &app, 1);
111  fcu.subscribe(&App::onPidNames, &app, 20);
112  // TODO: WayPoint
113  fcu.subscribe(&App::onBoxIds, &app, 1);
114  fcu.subscribe(&App::onServoConf, &app, 20);
115  // TODO: NavStatus
116  // TODO: NavConfig
117  fcu.subscribe(&App::onDebugMessage, &app, 1);
118  fcu.subscribe(&App::onDebug, &app, 1);
119 
120  // Ctrl+C to quit
121  std::cin.get();
122 }
Value< std::string > debug_msg
Definition: msp_msg.hpp:4910
void onImu(const msp::msg::RawImu &imu_raw)
Definition: fcu_test.cpp:15
std::string name
Definition: fcu_test.cpp:7
void onIdent(const msp::msg::Ident &ident)
Definition: fcu_test.cpp:11
int main(int argc, char *argv[])
Definition: fcu_test.cpp:71
void onMotorPins(const msp::msg::MotorPins &motor_pins)
Definition: fcu_test.cpp:43
void onAltitude(const msp::msg::Altitude &altitude)
Definition: fcu_test.cpp:27
void onPID(const msp::msg::Pid &pid)
Definition: fcu_test.cpp:37
void onRc(const msp::msg::Rc &rc)
Definition: fcu_test.cpp:21
void onRcTuning(const msp::msg::RcTuning &rc_tuning)
Definition: fcu_test.cpp:33
void onDebug(const msp::msg::Debug &debug)
Definition: fcu_test.cpp:66
void onAttitude(const msp::msg::Attitude &attitude)
Definition: fcu_test.cpp:23
void onServo(const msp::msg::Servo &servo)
Definition: fcu_test.cpp:17
void onPidNames(const msp::msg::PidNames &pid_names)
Definition: fcu_test.cpp:51
void setLoggingLevel(const msp::client::LoggingLevel &level)
Set the verbosity of the output.
void onDebugMessage(const msp::msg::DebugMessage &debug_msg)
Definition: fcu_test.cpp:61
void onBoxIds(const msp::msg::BoxIds &box_ids)
Definition: fcu_test.cpp:55
void onBox(const msp::msg::ActiveBoxes &box)
Definition: fcu_test.cpp:39
void onMisc(const msp::msg::Misc &misc)
Definition: fcu_test.cpp:41
void onStatus(const msp::msg::Status &status)
Definition: fcu_test.cpp:13
void onMotor(const msp::msg::Motor &motor)
Definition: fcu_test.cpp:19
bool connect(const std::string &device, const size_t baudrate=115200, const double &timeout=0.0, const bool print_info=false)
Connects to a physical flight controller, which includes connecting the internal Client object and qu...
Requests (1xx)
Definition: msp_msg.hpp:2590
std::shared_ptr< msp::client::SubscriptionBase > subscribe(void(C::*callback)(const T &), C *context, const double tp=0.0)
Register callback function that is called when type is received.
void onAnalog(const msp::msg::Analog &analog)
Definition: fcu_test.cpp:31
App(const std::string name)
Definition: fcu_test.cpp:9
Definition: fcu_test.cpp:5
void onBoxNames(const msp::msg::BoxNames &box_names)
Definition: fcu_test.cpp:47
void onServoConf(const msp::msg::ServoConf &servo_conf)
Definition: fcu_test.cpp:57


msp
Author(s): Christian Rauch
autogenerated on Tue Oct 6 2020 03:38:57