-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
61 lines (52 loc) · 1.78 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdio.h> // Standard input/output definitions
#include "include/multithreaded_interface.h"
void new_msg_callback(mavlink_message_t message)
{
if (message.msgid == 0)
{
cout << "Received HB" << endl;
mavlink_heartbeat_t heartbeat_msg;
mavlink_msg_heartbeat_decode(&message, &heartbeat_msg);
//printf("[compid sysid] = [%d %d] \n", message.compid, message.sysid);
}
else if (message.msgid == 32)
{
//cout << "Got Local Position Ned" << endl;
mavlink_local_position_ned_t local_position_ned_msg;
mavlink_msg_local_position_ned_decode(&message, &local_position_ned_msg);
}
else if (message.msgid == 30)
{
//cout << "Got Attitude msg" << endl;
mavlink_attitude_t attitude_msg;
mavlink_msg_attitude_decode(&message, &attitude_msg);
}
}
void decode_last_attitude_msg(MultithreadedInterface *mti)
{
auto search = mti->last_messages.find(MAVLINK_MSG_ID_ATTITUDE);
if (search != mti->last_messages.end())
{
mavlink_attitude_t att;
mavlink_msg_attitude_decode(&(search->second), &att);
printf("[Roll Pitch Yaw] = [%f %f %f] \n", att.roll, att.pitch, att.yaw);
}
else
{
std::cout << "Attitude Message Not found\n";
}
}
int main()
{
SerialPort serial_port("/dev/ttyUSB0", 115200);
MultithreadedInterface mti(serial_port);
//UdpDevice udp_device("127.0.0.1", 14560);
//to connect to mavproxy do the following
//mavproxy.py --master=udpout:127.0.0.1:14560 --out=udpout:127.0.0.1:14561
//MultithreadedInterface mti(udp_device);
mti.bind_new_msg_callback(new_msg_callback);
cout << "Bound Message CallBack" << endl;
this_thread::sleep_for(chrono::milliseconds(10000));
mti.shutdown();
return 0;
}