- Document I
route
Annotate
#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
Its comments are removed
- Document II
void Copter::userhook_50Hz () Function
Add Code
// put your 50Hz code here
int getData = 0;// Store temporarily received data
int i = 0;
char str[10];
static unsigned char str1[8];// Used to receive 4 temperature variables, 16 bit data
int x1 = 0;
static unsigned char strcon = 0;
static char timer=0;// Add a timer to receive data clearly when the time exceeds
getData = hal.uartE->read();
if (timer > 0)
{
timer++;
if (timer >= 10)
{
timer = 0;
strcon = 0;
}
}
if ( getData >= 0)
{
timer = 1; //Turn on the receiving timer
str1[strcon] = getData;
strcon++;
if (strcon >= 8)
{
//The received value is assigned to the g.tempture [] array
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;
Note: The global variable name here is only for testing
Its variables should be declared in
In file
For example:
Document 3
void NOINLINE Copter::send_radio_out (mavlink_channel_t chan)
Function, modify the internal code to
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
);
Its global function should correspond to the previous declaration.