- 设置gcs_link相关
auto gcs_link = MAVConnInterface::open_url("udp-b://@");
mavlink::common::msg::HEARTBEAT hb{};
gcs_link->send_message_ignore_drop(hb);
- 在mavros中send_message_ignore_drop 会调用fcu_link
UAS_FCU(&mav_uas) = fcu_link;
- gcs_link的时候,调用的是fcu_link发送
if (gcs_link) {
gcs_link->connect([this, fcu_link](const mavlink_message_t *msg, const Framing framing) {
this->last_message_received_from_gcs = ros::Time::now();
fcu_link->send_message_ignore_drop(msg);
});
gcs_link_diag.set_connection_status(true);
}
- ros发送消息给QGC
https://github.com/mavlink/mavros/issues/574
#include
#include
#include
#include
uint8_t system_id = 1;
uint8_t component_id = 1;
uint8_t type = 1;
uint8_t autopilot = 0;
uint8_t base_mode = 128;
uint32_t custom_mode = 0;
uint8_t system_status = 0;
float alt_monotonic = 10.0;
float alt_amsl = 100;
float alt_local = 10.0;
float alt_relative = 10.0;
float alt_terrain = 10;
float bottom_clearance = 0;
int main(int argc, char **argv){
mavlink_message_t msg_heartbeat;
mavlink_msg_heartbeat_pack(system_id, component_id, &msg_heartbeat, type, autopilot, base_mode, custom_mode, system_status);
mavros_msgs::Mavlink ml_heartbeat;
mavros_msgs::mavlink::convert(msg_heartbeat, ml_heartbeat);
mavlink_message_t msg_altitude;
mavros_msgs::Mavlink ml_altitude;
ros::init(argc, argv, "telemetry_publisher");
ros::NodeHandle n;
ros::Publisher example_pub = n.advertise<mavros_msgs::Mavlink>("/mavlink/from", 1000);
ros::Rate loop_rate(1);
while (ros::ok())
{
uint64_t time_stamp = ros::Time::now().nsec;
mavlink_msg_altitude_pack(system_id, component_id, &msg_altitude, time_stamp, alt_monotonic, alt_amsl, alt_local, alt_relative, alt_terrain, bottom_clearance);
mavros_msgs::mavlink::convert(msg_altitude, ml_altitude);
example_pub.publish(ml_heartbeat);
example_pub.publish(ml_altitude);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}

- 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