|
mavlink库用的inav2.1.0里面现成的。
Tower用的4.0。
手上的arduino pro mini 运行内存太小,跑消息发送轻轻松松,但消息接收用到的crc校验就把2k的内存干的干干净净,一点不剩。
既然内存不够也无心折腾下去,贴出代码给有需要的人参考吧。
测试发送的消息有:心跳,姿态,系统状态,hud,位置信息。
说实话mavlink库用起来还真是简单方便。
arduino pro mini D4,D5 做软串口接蓝牙透传模块
mavlink_test.ino源码如下
#include "MAVLink/common/mavlink.h"
#include <SoftwareSerial.h>
SoftwareSerial mav_serial(5, 4); // RX, TX
mavlink_message_t msg;
uint8_t system_id = 1;
void setup() {
mav_serial.begin(57600);
}
void loop() {
// incoming heartbeat
mavlink_heartbeat_t heartbeat = {2,MAV_TYPE_FIXED_WING,MAV_AUTOPILOT_GENERIC,MAV_MODE_FLAG_STABILIZE_ENABLED,MAV_STATE_ACTIVE,1};
mavlink_msg_heartbeat_encode(system_id, 1, &msg, &heartbeat);//MAV_COMP_ID_SYSTEM_CONTROL
mavlinkSendMessage();
// incoming non-targetted message
mavlink_attitude_t attitude = {millis(),0.5,0.5,0.5,0,0,0};
mavlink_msg_attitude_encode(system_id, 1, &msg, &attitude);
mavlinkSendMessage();
uint32_t sensors = 35843;
sensors |= 4100;//mag
sensors |= 8200;//baro
sensors |= 16416;//gps
mavlink_sys_status_t sys_status = {sensors, sensors, sensors&1023, 500, 3900, -1, 0, 0, 0, 0, 0, 0, 80};
mavlink_msg_sys_status_encode(system_id, 1, &msg, &sys_status);
mavlinkSendMessage();
mavlink_vfr_hud_t hud = {50,60,1000,70,80,90};
mavlink_msg_vfr_hud_encode(system_id, 1, &msg, &hud);
mavlinkSendMessage();
//mavlink_set_home_position_t homepos = {27.9512732214701*1e7,109.59983276588443*1e7,1000,0,0,0};
//mavlink_msg_set_home_position_decode(&msg, &homepos);
//mavlinkSendMessage();
mavlink_gps_raw_int_t gps = {millis(), 27.9512732214701*1e7, 109.59983276588443*1e7, 1000, 0, 0, 100, 180, 3, 17};
mavlink_msg_gps_raw_int_encode(system_id, 1, &msg, &gps);
mavlinkSendMessage();
mavlink_global_position_int_t pos = {millis(), 27.953519313498994*1e7, 109.5980625079346*1e7, 1000, 1000, 0, 0, 0, 180};
mavlink_msg_global_position_int_encode(system_id, 1, &msg, &pos);
mavlinkSendMessage();
//mavlink_gps_global_origin_t opos = {27.9512732214701*1e7,109.59983276588443*1e7,1000};
//mavlink_msg_gps_global_origin_encode(system_id, 1, &msg, &opos);
//mavlinkSendMessage();
delay(100);
}
static void mavlinkSendMessage(void)
{
uint8_t mavBuffer[MAVLINK_MAX_PACKET_LEN];
int msgLength = mavlink_msg_to_send_buffer(mavBuffer, &msg);
for (int i = 0; i < msgLength; i++) {
mav_serial.write(mavBuffer);
}
}
|
评分
-
查看全部评分
欢迎继续阅读楼主其他信息
|