Pixhawk 传感器信号传递

  • 内容
  • 评论
  • 相关
  1. 文件一

路径

将注释的

#define USERHOOK_INIT userhook_init();                      // for code to be run once at startup

#define USERHOOK_FASTLOOP userhook_FastLoop();            // for code to be run at 100hz

#define USERHOOK_50HZLOOP userhook_50Hz();                  // for code to be run at 50hz

#define USERHOOK_MEDIUMLOOP userhook_MediumLoop();        // for code to be run at 10hz

#define USERHOOK_SLOWLOOP userhook_SlowLoop();            // for code to be run at 3.3hz

#define USERHOOK_SUPERSLOWLOOP userhook_SuperSlowLoop();  // for code to be run at 1hz

其注释去掉

 

  1. 文件二

void Copter::userhook_50Hz() 函数

 

添加代码

// put your 50Hz code here

 

int getData = 0;//存放临时接收的数据

int i = 0;

char str[10];

static unsigned char str1[8];//用于接收4个温度变量,16位数据

int x1 = 0;

static unsigned char strcon = 0;

static char timer=0;//加一定时器,超过时间清楚接收数据

 

getData = hal.uartE->read();

 

if(timer > 0)

{

timer++;

if (timer >= 10)

{

timer = 0;

strcon = 0;

}

}

if ( getData >= 0)

{

timer = 1;    //开启接收定时器

str1[strcon] = getData;

strcon++;

if (strcon >= 8)

{

 

//接收到的数值赋给g.tempture[]数组

strcon = 0;

x1 = 0;

x1 = ((unsigned int) (str1[1] << 8));

x1 |= str1[0];

g.tempture[0] = x1;

 

x1 = 0;

x1 = ((unsigned int) (str1[3] << 8));

x1 |= str1[2];

g.tempture[1] = x1;

 

x1 = 0;

x1 = ((unsigned int) (str1[5] << 8));

x1 |= str1[4];

g.tempture[2] = x1;

 

x1 = 0;

x1 = ((unsigned int) (str1[7] << 8));

x1 |= str1[6];

g.tempture[3] = x1;

 

}

 

}

 

g.tempture[0] = 0x5;

g.tempture[1] = 0x5;

g.tempture[2] = 0x5;

g.tempture[3] = 0x5;

 

 

g.testG = 2;

 

 

注:这里的全局变量名称仅供测试使用

 

其变量应声明在

文件内

 

如:

 

 

 

 

文件三.

 

void NOINLINE Copter::send_radio_out(mavlink_channel_t chan)

 

函数,修改内部代码为

 

mavlink_msg_servo_output_raw_send(

chan,

micros(),

0,     // port

/*hal.rcout->read(0),

hal.rcout->read(1),

hal.rcout->read(2),

hal.rcout->read(3),

hal.rcout->read(4),

hal.rcout->read(5),

hal.rcout->read(6),

hal.rcout->read(7)*/

g.testG,

g.tempture[1],

g.tempture[2],

g.tempture[3],

0x04,

0x05,

0x06,

0x07

);

 

 

其全局函数应与之前声明对应。

评论

0条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注