mdFlexControl

来自microdrones-asia
跳转到: 导航, 搜索
mdFlexControl
有了microdrones最新的mdFlexControl SDK,您可以接入您自己的传感器及促动机。所有重要的飞行器参数都可以拿到:电池电压、飞行时间、姿态、高度、速度、GPS位置,还有更多。
mdFlexControl硬件是经专门设计来满足用户要接入硬件的需求,并且同时支持多项任务。应用程序可以作为不同的任务用我们的资源来运行。所有的任务优先级相同,但是可以选择执行的时间先后。
mdFlexControl应用是用C语言编写的(标准C99)。
可以执行达三个独立的apps。它们可以作为不同的任务用我们的资源来运行。所有的任务优先级相同,但是可以选择执行的时间先后。
FlexControl 应用 文件名 编辑存储器 数据存储器 默认时间段
App1 (Task1) fc_task1.bin 32 kByte 32 kByte 5 ms
App2 (Task2) fc_task2.bin 16 kByte 16 kByte 10 ms
App3 (Task3) fc_task3.bin 16 kByte 16 kByte 20 ms
各种任务之间可以相互暂停、恢复甚至是终止,总体来说,所有的任务之间互不影响,但是有以下的几种方式控制所有的任务并且进行任务间的通讯。
  • 共享内存实现任务间的数据转换
  • 三个事件对象可以用作任务同步
  • 暂停、恢复及终止可以用作任务控制
三个独立的文件对象提供文件输入/输出。用户数据可以写到文件内,或者从文件中读取。文件大小可达4G。


目录

API 简介

主应用程序提供一个含有100项功能的强大软件库。所有的库功能均以前缀fc_命名。
由于RAM是一个宝贵的资源,主机库功能是被调用的,而不是把相同功能集成到apps里面。这使得编辑容量非常小,只有一点儿的速度延误,而且我们说的是每调用一个功能才不到1毫秒的延误,因此这个延误是可忽略的。
知道这点以后,我们就清楚为什么即使是数学算法功能也要通过调用主机库功能来实现了。如果使用普通的库功能,可能会导致大的代码膨胀,因为大多数的功能要求大的代码尺寸。

Here comes the first “Hello world” – what else …

#pragma location = ".program_start"
void main(void)
{
  fc_uart_open(UART1, 115200, UART_PA_NONE, UART_DB8, UART_SB1);
  fc_puts(UART1, "*** Hello from FlexControl Task1\r\n");
  fc_suspend(TASK1);
}

第一行#pragma location = “.program_start”不是很重要的,因为它只是确认主功能()在程序入口位置。否则就不能预测链接程序会放到哪个位置。

与标准C99有一个区别就是:在声明中,您不能初始化一个变量!初始化后,必须在程序中完成。

// This is not allowed
int my_var = 1234;
// This is ok
int my_var;
#pragma location = “.program_start”
void main (void)
{
  my_var = 1234;
}

该项限制的原因同样是编码大小的效率。如果使用整个低级别的初始化程序,那么将近一半的代码内存会被低级别代码占用。 初始化常数是有效的,因为它不是放置在数据存储器中。

// This is ok
const int my_const_var = 1234;

所有的应用都在一个低功耗的ARM Cortex M4 DSC上运行,其中有一个浮点运算单元(FPU)制作单精度计算。双精度计算的速度要慢很多。为了保持高性能运作,只要可以都必须避免双精度计算。 使用浮点常量的时候要小心。浮点文字的默认类型是双重的。必须明确选择使用带f后缀浮点常量的浮文字。

float f;
// Causes a double-to-float conversion before assigning f.
f = 1.5;
// Ok
f = 1.5f;
// Causes a double precision multiplication and a double-to-float conversion before assigning f.
f = 25.0 * 12.5;
// Ok
f = 25.0f * 12.5f;


Data Types

FlexControl定义部分数据类型。有标准C数据输入或者FlexControl数据输入可供选择使用。整个文档会使用FlexControl数据录入。

typedef signed char S08;
typedef unsigned char U08;
typedef signed short S16;
typedef unsigned short U16;
typedef signed int S32;
typedef unsigned int U32;
typedef signed long long S64;
typedef unsigned long long U64;
typedef U08* pU08;
typedef S08* pS08;
typedef U16* pU16;
typedef S16* pS16;
typedef U32* pU32;
typedef S32* pS32;
typedef U64* pU64;
typedef S64* pS64;
typedef float* pFLOAT;
typedef double* pDOUBLE;
typedef U08 BOOL;

Tasks

用于任务控制的任务功能,使用TASK1, TASK2 或者 TASK3来执行特定任务。

fc_delay()

void fc_delay (U32 dly)
延迟执行当前任务特定时间,该任务只会被暂时挂起,并把控制给到其他的任务,而不是禁用该应用程序。

            Param1: The delay in milliseconds.
Return: None.
Example: fc_delay(500);


fc_suspend()

void fc_suspend (U32 task_id)
暂停指定的任务,该任务将会停留在暂停状态,直到另一个任务通过使用fc_resume()功能将该任务唤醒为止。

            Param1: The task ID of the task to be suspended. Use either TASK1, TASK2 or TASK3.
Return: None.
Example: fc_suspend(TASK2);


fc_resume()

void fc_resume (U32 task_id)
恢复指定的任务。用fc_suspend()功能挂起的任务将会恢复操作。

            Param1: The task ID of the task to be resumed. Use either TASK1, TASK2 or TASK3.
Return: None.
Example: fc_resume(TASK2);


fc_terminate()

void fc_terminate (U32 task_id)
终止指定的任务。该任务会从任务列表中删除,并且调用该功能后不会再获得任何进程时间。

            Param1: The task ID of the task to be terminated. Use either TASK1, TASK2 or TASK3.
Return: None.
Example: fc_terminate(TASK2);


fc_mem_set()

void fc_mem_set (U32 location, U32 value)
设置指定共享内存位置的数值,共享内存大小为256x32-bit。

            Param1: The location of the shared memory. Must be 0..255.
  Param2: The new value of shared memory location.
Return: None.
Example: fc_mem_set (0, 1023);


fc_mem_get()

U32 fc_mem_get (U32 location)
获取指定共享内存位置的数值,共享内存大小为256x32-bit。

            Param1: The location of the shared memory. Must be 0..255.
Return: The value of the specified shared memory location.
Example: U32 mem;
mem = fc_mem_get (0);



Events

有三个事件对象可以用于同步任务。使用EVENT1, EVENT2 或者 EVENT3来指定事件。

fc_event_wait()

void fc_event_wait (U32 event_id)
等待被指定的时间。当前任务将会被挂起直到另一个任务用fc_event_set()功能设置该事件位置。

            Param1: The event ID to wait for. Use either EVENT1, EVENT2 or EVENT3.
Return: None.
Example: fc_event_wait(EVENT1);


fc_event_wait_timed()

void fc_event_timed (U32 event_id, U32 timeout)
等待指定事件被设置到特定时间内。当前任务会被挂起直到下一个任务被设置,或者超时。

            Param1: The event ID to wait for. Use either EVENT1, EVENT2 or EVENT3.
  Param2: The timeout (ms) when the task shall continue without the event being set.
Return: None.
Example: fc_event_wait_timed(EVENT1, 1000);


fc_event_set()

void fc_event_set (U32 event_id)
设置指定事件,所有的任务等待该任务恢复并重设。

            Param1: The event ID to wait for. Use either EVENT1, EVENT2 or EVENT3.
Return: None.
Example: fc_event_set(EVENT1);



Put

所有输入的功能可以被写入一下任意一个设备中:

  • UART1
  • UART2
  • UART3
  • FILE1
  • FILE2
  • FILE3

所有数值输入功能(fc_puti(), fc_putx(), fc_putf())用ASCII格式写入数字。

fc_putc()

void fc_putc (U32 device, char c)
把字符C写入选定的设备

            Param1: Select one of the devices as described before.
  Param2: Character to write.
Return: None.
Example: fc_putc(UART1, 65);


fc_puts()

void fc_puts (U32 device, char* s)
把字符串s写入选定的设备。

            Param1: Select one of the devices as described before.
  Param2: String to write.
Return: None.
Example: fc_puts(UART1, “String”);


fc_puti()

void fc_puti (U32 device, S32 value, U32 digits)
把32位带符号整数写入选定的设备。

            Param1: Select one of the devices as described before.
  Param2: Signed integer value to write.
  Param3: Number of digits to format the output (0 = no format).
Return: None.
Example: fc_puti(UART1, 1234, 0);


fc_putx()

void fc_putx (U32 device, U32 value, U32 format)
把一个十六进制值写入选定的设备。

            Param1: Select one of the devices as described before.
  Param2: Value to write.
  Param3: Hexadecimal format. Use either
  • HEX_08 for 8-bit format (examples: 08, 5A, FD)
  • HEX_16 for 16-bit format (examples: 0008, 005A, 00FD)
  • HEX_32 for 32-bit format (examples: 00000008, 0000005A, 000000FD)
Return: None.
Example: fc_putx(UART1, 0xABCD, HEX_16);


fc_putf()

void fc_putf (U32 device, float value, U32 decimals, U32 digits)
把一个浮点值写入选定的设备。

            Param1: Select one of the devices as described before.
  Param2: Float value to write.
  Param3: Number of decimal digits.
  Param4: Number of digits to format the output (0 = minimum).
Return: None.
Example: fc_putf(UART1, 1.234f, 3, 6);



File

有三个文件目标来支持文档输入和输出。使用FILE1, FILE2或者 FILE3来指定文件目标。所有的文件名一定要用8.3格式,不支持长的文件名。

fc_fopen_write()

U32 fc_fopen_write (U32 file, char* fname)
打开一个指定的文档用于写访问。fc_put() 和 fc_fwrite()功能可以用于写入数据到文件。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
  Param2: File name in 8.3 format.
Return: FC_OK on success, FC_ERR_OPEN on any error.
Example: fc_fopen_write(FILE1, “test.txt”);


fc_fopen_read()

U32 fc_fopen_read (U32 file, char* fname)
打开特定文件用于读访问。fc_get() 和 fc_fread()功能可以用于读取文件的数据。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
  Param2: File name in 8.3 format.
Return: FC_OK on success, FC_ERR_OPEN on any error.
Example: fc_fopen_read(FILE1, “test.txt”);


fc_fgetc()

U32 fc_fgetc (U32 file, char* c)
从特定文件读取字符。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
  Param2: Pointer to a character variable.
Return: FC_OK on success, FC_ERR_READ on any error.
Example: char c;
fc_fgetc(FILE1, &c);


fc_fgets()

U32 fc_fgets (U32 file, char* s, U32 max_len)
从指定的文件中读取一个字符串。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
  Param2: Pointer to a character array.
  Param3: Maximal string length to read. If the string to read is longer than max_len, then the read process is stopped.
Return: FC_OK on success, FC_ERR_READ on any error.
Example: char s[80];

fc_fgets(FILE1, (char*)&s, 80);


fc_fbuffer()

pU08 fc_fbuffer (U32 file)
每个文件目标有一个专门的文件缓冲区。该功能返回指定文件对象缓冲区的指向。使用fc_fread()后该缓冲区可以用于获取数据,也可用于fc_fwrite()写入文件前设置数据。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
Return: Pointer to the file buffer on success, a NULL pointer on any error.
Example: pU08 addr;

addr = fc_fbuffer(FILE1);


fc_fread()

U32 fc_fread (U32 file, U32 bytes_to_read, pU32 bytes_read)
该功能可以从文件中读取达256b的内容,因此也使用了相关的文件缓冲区。用fc_fbuffer()获取文件缓冲区的相应指针。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
  Param2: Number of bytes to read (1.. 256).
  Param3: The number of bytes which were read from file.
Return: FC_OK on success, FC_ERR_READ on any error.
Example: U32 result;
U32 bytes_read;

result = fc_fread(FILE1, 80, &bytes_read);


fc_fwrite()

U32 fc_fwrite (U32 file, U32 bytes_to_write, pU32 bytes_written)
该功能可以写入达256b到文件内,因此也使用了相应的文件缓冲区。在此之前,必须写入合适的数据到文件缓冲区。使用fc_fbuffer()获取文件缓冲区的相应指针。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
  Param2: Number of bytes to write (1.. 256).
  Param3: The number of bytes which were written to file.
Return: FC_OK on success, FC_ERR_WRITE on any error.
Example: U32 result;
U32 bytes_written;

result = fc_write (FILE1, 80, &bytes_written);


fc_feof()

U32 fc_feof (U32 file)
检查文件结束条件的指定文档。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
Return: 1 if condition is true, 0 if condition is false.
Example: if (fc_feof(FILE1) == true)
{
  // Do something
}


fc_fclose()

void fc_fclose (U32 file)
关闭指定文档。

            Param1: File ID. Use either FILE1, FILE2 or FILE3.
Return: None.
Example: fc_fclose(FILE1);


fc_ini_read_key()

U32 fc_ini_read_key (char* ss, char* ks, U32 kvt, void* kvp, void* dvp)
读取初始文档钥匙。一般来说“fc_setup.ini”文档是在SD卡中的。除了一些预定义的数值,您还可以用自己设置的数据来扩展该文档。该部分的字符串必须在括号中,如“[MY_SECTION]”。一个钥匙字符串是不带括号,如“TEST_INT”。您可以对所有字符串使用大写或小写字母。该部分看起来可能像这样:

[MY_SECTION]
TEST_INT = 1234
TEST_FLOAT = 123.456
TEST_STR = ini string
            Param1: Section String “ss” to specify the section which must be placed in brackets.
  Param2: Key String “ks” to specify the key.
  Param3: Key Value Type specifies the data type. Use either
  • INI_STR (for String Data Type)
  • INI_S32 (for Integer Data Type)
  • INI_U32 (for Unsigned Integer Data Type)
  • INI_FLOAT (for Float Data Type)
  • INI_DOUBLE (for Double Data Type)
  Param4: Key Value Pointer. This is a pointer to a variable for storing the result.
  Param5: Default Value Pointer. This is a pointer to a default value which is used if reading fails.
Return: FC_OK on success, FC_ERR_READ on any error.
Example: const S32 INI_DEFAULT = -1;
U32 result;
U32 bytes_read;
S32 ini_value;

result = fc_ini_read_key(“[my_section]”, “my_value”, INI_S32, (void*)&ini_value, (void*)&INI_DEFAULT);


I/O

模拟输入、数字输入、数字输出、数字电源输出、LED灯、舵机的功能。

fc_ain()

U32 fc_ain (U32 chn)
以12位分辨率读取模拟输入的数位值。0至3V3的输入电压转换成0至4095之间的数值。Read the digital value of an analog input with a 12-bit resolution. An input voltage in the range of 0..3V3 is converted to a value in the range of 0..4095.

            Param1: Channel number to read. Use either AIN1, AIN2, AIN3 or AIN4 to select the channel.
Return: Digital value of the selected analog channel.
Example: U32 analog_value;
analog_value = fc_ain (AIN1);


fc_din()

U32 fc_din (U32 chn)
读取所选通道的数字输入。外加电压电平可能高达24V。高态过渡电压为> 1.8V。Read the digital input of the selected channel. The applied voltage level may be up to 24V. The transition voltage to high state is > 1.8V.

            Param1: Channel number to read. Use either DIN1, DIN2, DIN3 or DIN4 to select the channel.
Return: 1 if the digital input is high, 0 if the input is low.
Example: if (fc_din(DIN1) == false)
{
  // Do something
}


fc_dout()

void fc_dout (U32 chn, U32 state)
改变数字输出的状态。状态IO_CLR将清除输出,IO_SET将设置输出,IO_TGL将切换输出。该状态下的电压电平为3V3。最大源电流可能不超过20mA。 Change the state of the digital output. The state IO_CLR will clear the output, IO_SET will set the output, IO_TGL will toggle the output. The voltage level is 3V3 for this state. The maximal source current may not exceed 20mA.

            Param1: Channel number. Use either DOUT1, DOUT2, DOUT3 or DOUT4 to select the channel.
  Param2: I/O State. Use either IO_CLR, IO_SET or IO_TGL.
Return: None.
Example: fc_dout(DOUT1, IO_SET);


fc_dpout()

void fc_dpout (U32 chn, U32 state)
改变数字电源输出的状态。状态IO_CLR将清除输出,IO_SET将设置输出,IO_TGL将切换输出。最大漏极电流可能不超过1A。 Change the state of the digital power output. The state IO_CLR will clear the output, IO_SET will set the output, IO_TGL will toggle the output. The maximal drain current may not exceed 1A.

            Param1: Channel number. Use either DPOUT1, DPOUT2, DPOUT3 or DPOUT4 to select the channel.
  Param2: I/O State. Use either IO_CLR, IO_SET or IO_TGL.
Return: None.
Example: fc_dpout(DPOUT1, IO_SET);


fc_led()

void fc_led (U32 led, U32 state)
改变指定LED的状态。LED1为红色,LED2为绿色,LED3为黄色。Change the state of the specified LED. LED1 is red, LED2 is green and LED3 is yellow.

            Param1: LED number. Use either LED1, LED2 or LED3 to select the LED.
  Param2: I/O State. Use either IO_CLR, IO_SET or IO_TGL.
Return: None.
Example: fc_led (LED1, IO_SET);


fc_servo_get()

S08 fc_servo_get (U32 servo)
读取所选舵机的实际位置(百分数)。Read the actual position of the selected servo in percent.

            Param1: Servo number. Use either SERVO1 or SERVO2 to select the servo.
Return: Actual servo position in percent (-100..+100, 0 = zero position).
Example: S08 servo1;

servo1 = fc_servo_get (SERVO1);


fc_servo_set()

void fc_servo_set (U32 servo, S08 pos)
设置所选舵机的实际位置(百分数)。Set the actual position of the selected servo in percent.

            Param1: Servo number. Use either SERVO1 or SERVO2 to select the servo.
  Param2: New servo position in percent(-100..+100, 0 = zero position).
Return: None.
Example: fc_servo_set(SERVO1, 50);



UART

UART函数为异步串行通讯提供支持。

fc_uart_open()

U32 fc_uart_open (U32 device, U32 baudrate, U32 parity, U32 data_bits, U32 stop_bits)
打开选定的串行通讯UART

            Param1: Select UART. Use either UART1, UART2 or UART3.
  Param2: Select baudrate (300..230400).
  Param3: Select parity. Use either UART_PA_NONE, UART_PA_EVEN or UART_PA_ODD.
  Param4: Select data bits. Use either UART_DB8 or UART_DB9.
  Param5: Select stop bits. Use either UART_SB0P5, UART_SB1, UART_SB1P5 or UART_SB2.
Return: FC_OK on success, FC_ERR_OPEN on any error.
Example: U32 result;

result = fc_uart_open(UART1, 115200, UART_PA_NONE, UART_DB8, UART_SB1);


fc_uart_register_rx()

U32 fc_uart_register_rx (U32 device, U32 callback)
注册一个接收来自所选UART全部字节的回调函数

            Param1: Select UART (UART1, UART2 or UART3)
  Param2: A pointer to a callback function void callback(char c).
Return: FC_OK on success, FC_ERR_REGISTER on any error.
Example: void uart1_cb(char c)
{
  fc_putc(UART1, c);
}

fc_uart_register_rx(UART1, (U32)&uart1_cb);



I²C

I2C函数为双线式通讯提供支持。

fc_i2c_open()

U32 fc_i2c_open (U32 speed)
以所选速度打开双线式通讯的I2C接口。

            Param1: Select I2C speed (I2C_400K, I2C_300K, I2C_200K, I2C_100K).
Return: FC_OK on success, FC_ERR_OPEN on any error.
Example: fc_i2c_open(I2C_400K);


fc_i2c_set_speed()

void fc_i2c_set_speed (U32 speed)
设置I2C接口的速度。

            Param1: Select I2C speed (I2C_400K, I2C_300K, I2C_200K, I2C_100K).
Return: None.
Example: fc_i2c_set_speed (I2C_400K);


fc_i2c_start()

void fc_i2c_start (void)
I2C接口应用起始状态。

            Param1: None.
Return: None.
Example: fc_i2c_start ();


fc_i2c_stop()

void fc_i2c_stop (void)
I2C接口应用停止状态。

            Param1: None.
Return: None.
Example: fc_i2c_stop ();


fc_i2c_read_byte()

U08 fc_i2c_read_byte (BOOL ack)
读取I2C接口的一个字节。

            Param1: Flag if an acknowledge bit shall be sent.
Return: The byte read from I2C interface.
Example: U08 i2c_result;

i2c_result = fc_i2c_read_byte (TRUE);


fc_i2c_write_byte()

U32 fc_i2c_write_byte (U08 byte)
在I2C接口写入一个字节。

            Param1: The byte to be sent.
Return: FC_OK on success, FC_ERR_WRITE on any error.
Example: fc_i2c_write_byte (0xAA);


fc_i2c_receive()

U32 fc_i2c_receive (U08 slave_addr, U08 byte_addr, U08 data_bytes, pU08 rx_buffer_ptr)
接收来自I2C接口的多个字节。

            Param1: The slave address.
  Param2: The byte address to start reading.
  Param3: The number of bytes to receive.
  Param4: The pointer to byte buffer which receives the bytes.
Return: FC_OK on success, FC_ERR_READ on any error.
Example: U08 rx_buffer[8];

fc_i2c_receive (0xEA, 0x00, 8, &rx_buffer);


fc_i2c_transmit()

U32 fc_i2c_transmit (U08 slave_addr, U08 byte_addr, U08 data_bytes, pU08 tx_buffer_ptr)
向I2C接口传输多个字节。

            Param1: The slave address.
  Param2: The byte address to start writing.
  Param3: The number of bytes to transmit.
  Param4: The pointer to byte buffer to write from.
Return: FC_OK on success, FC_ERR_WRITE on any error.
Example: U08 tx_buffer[4];

tx_buffer[0] = 1;
tx_buffer[1] = 2;
tx_buffer[2] = 3;
tx_buffer[3] = 4;
fc_i2c_transmit (0xEA, 0x01, 4, &tx_buffer);



SPI

SPI功能为高速同步通讯提供支持。

fc_spi_open()

U32 fc_spi_open (U32 baud_rate, U32 cpol, U32 cpha)
以所选速度打开同步通讯的SPI接口。

            Param1: Select one of these baud rates
  • SPI_SPEED_42M (42 MHz)
  • SPI_SPEED_21M (21 MHz)
  • SPI_SPEED_10P5M (10.5 MHz)
  • SPI_SPEED_5P25M (5.25 MHz)
  • SPI_SPEED_2P625M (2.625 MHz)
  • SPI_SPEED_1P312M (1.312 MHz)
  • SPI_SPEED_0P656M (0.656 MHz)
  • SPI_SPEED_0P328M (0.328 MHz)
  Param2: Select idle clock polarity (0 = low on idle, 1 = high on idle).
  Param3: Select clock phase (0 = data capture on first clock, 1 = data capture on second clock).
Return: FC_OK on success, FC_ERR_OPEN on any error.
Example: fc_spi_open(SPI_SPEED_10P5M, 0, 0);


fc_spi_transfer()

U08 fc_spi_transfer (U08 byte)
向/从SPI接口发送和接收一个字节。

            Param1: Byte to send.
Return: Received byte.
Example: U08 rx_byte;

rx_byte = fc_spi_transfer (0xAA);


fc_spi_select()

void fc_spi_select (void)
选择SPI从属通道(打下)。

            Param1: None.
Return: None.
Example: fc_spi_select();


fc_spi_deselect()

void fc_spi_deselect (void)
取消SPI从属通道的选择(打上)。

            Param1: None.
Return: None.
Example: fc_spi_deselect();



CAN

该功能用于支持CAN通讯。 CAN信息结构用于接收和传递信息。

//访问CAN数据的不同数据类型
typedef union uCAN_DATA
{
  U08 U08[8]; // Access to U08
  S08 S08[8]; // Access to S08
  U16 U16[4]; // Access to U16
  S16 S16[4]; // Access to S16
  U32 U32[2]; // Access to U32
  S32 S32[2]; // Access to S32
  float fp[2]; // Access to float
} tCAN_DATA;

typedef struct sCAN_MESSAGE
{
  U32 id; // 11 or 29-bit identifier
  U08 rtr; // DATA_FRAME or REMOTE_FRAME
  U08 ide; // STANDARD or EXTENDED
  U08 dlc; // BYTES_0..BYTES_8
  U08 filter_match_index;
  tCAN_DATA data;
} tCAN_MESSAGE;

fc_can_open()

U32 fc_can_open (U32 speed)
以指定速度打开CAN接口。

            Param1: CAN Speed. Use either CAN_1000KB, CAN_500KB, CAN_250KB or CAN_125KB
Return: FC_OK on success, FC_ERR_OPEN on any error.
Example: fc_can_open (CAN_1000KB);


fc_can_set_id_len()

void fc_can_set_id_len (U32 id_len)
设置识别码的长度。标准的11字节识别码采用CAN_ID_STD,扩展的29字节识别码采用CAN_ID_EXT。

            Param1: Identifier length. Use either CAN_ID_STD or CAN_ID_EXT.
Return: None.
Example: fc_can_set_id_len (CAN_ID_STD);


fc_can_set_filter()

void fc_can_set_filter (U32 start_id, U32 end_id)
设置接收识别码的范围。

            Param1: Identifier start address.
  Param2: Identifier end address.
Return: None.
Example: fc_can_set_filter(0x1000, 0x8000);


fc_can_msg_available()

U32 fc_can_msg_available (void)
检查是否有符合fc_can_set_filter() 设置的地址范围的信息。如果有一个或以上的信息,可以通过fc_can_get_msg()函数读取。

            Param1: None.
Return: Number of messages available. Can be 0..3.
Example: U32 can_msg;

can_msg = fc_can_msg_available ();


fc_can_get_msg()

void fc_can_get_msg (tCAN_MESSAGE* msg)
读取一个CAN信息。

            Param1: Pointer to a tCAN_MESSAGE structure.
Return: None.
Example: tCAN_MASSAGE can_msg;

fc_can_get_msg (&can_msg);


fc_can_send_msg()

void fc_can_send_msg (tCAN_MESSAGE* msg)
发送一个CAN信息。

            Param1: Pointer to a tCAN_MESSAGE structure.
Return: None.
Example: tCAN_MASSAGE can_msg;

// Setup can_msg members here
fc_can_send_msg (&can_msg);



Machine

通过机器函数,可检索所有重要的机器数值和状态。

fc_get_att_pitch()

float fc_att_pitch (void)
获得机器的实际俯仰角度。

            Param1: None.
Return: Pitch angle in radians.
Example: float pitch_deg;

pitch_deg = fc_rad2deg(fc_att_pitch());


fc_get_att_roll()

float fc_att_roll (void)
获得机器的实际滚转角度。

            Param1: None.
Return: Roll angle in radians.
Example: float roll_deg;

roll_deg = fc_rad2deg(fc_att_roll());


fc_get_att_yaw()

float fc_att_yaw (void)
获得机器的实际偏航角度。

            Param1: None.
Return: Yaw angle in radians.
Example: float yawl_deg;

yaw_deg = fc_rad2deg(fc_att_yaw());


fc_get_battery()

float fc_get_battery (void)
获得电池电压。

            Param1: None.
Return: Battery voltage in V.
Example: float batt;

batt = fc_get_battery ();


fc_get_distance()

float fc_get_distance (void)
获得离起飞点的实际距离。

            Param1: None.
Return: Distance in meter.
Example: float dist;

dist = fc_get_distance();


fc_get_flags()

U32 fc_get_flag (void)
获得所有重要的系统标记。

            Param1: None.
Return: 32-bit encodes flags.
Example: U32 flags;

flags = fc_get_flags();


fc_get_ftime()

U32 fc_get_ftime (void)
获得实际飞行时间。

            Param1: None.
Return: Flight time in seconds.
Example: U32 ftime;

ftime = fc_get_ftime();


fc_get_gps_lat()

float fc_get_gps_lat (void)
获得实际GPS纬度值(度)。

            Param1: None.
Return: GPS latitude in degrees.
Example: float lat;

lat = fc_get_gps_lat();


fc_get_gps_lon()

float fc_get_gps_lon (void)
获得实际GPS经度值(度)。

            Param1: None.
Return: GPS longitude in meters.
Example: float lon;

lon = fc_get_gps_lon();


fc_get_inflight()

U32 fc_get_inflight (void)
获得机器是否在飞行中的状态信息。

            Param1: None.
Return: 1 if in flight, 0 if not.
Example: if (fc_get_inflight() == TRUE)
{
  // Do something
}


fc_get_operating_mode()

U32 fc_get_operating_mode (void)
获得实际工作模式。可为以下三种不同过滤模式之一:

  • INS_ONLY (if magnetometer is invalid, regardless if GPS is valid)
  • INS_MAG (if magnetometer is valid and GPS is invalid)
  • INS_MAG_GPS (if magnetometer is valid and GPS is valid)
            Param1: None.
Return: INS_ONLY, INS_MAG, INS_MAG_GPS.
Example: if (fc_get_operating_mode() == INS_ONLY)
{
  // Do something
}


fc_get_speed()

float fc_get_speed (void)
获得实际飞行速度。

            Param1: None.
Return: Flight speed in m/s.
Example: float speed;

speed = fc_get_speed();


fc_get_altitude()

float fc_get_altitude (void)
获得实际高度。

            Param1: None.
Return: Flight altitude in m.
Example: float alt;

alt = fc_get_altitude();


fc_get_rc()

S08 fc_get_rc (U32 chn)
获得指定RC通道的实际值(百分比)。

            Param1: RC channel. Use either one of these channels: RC_THROTTLE, RC_ROLL, RC_PITCH, RC_YAW, RC_AUX_E, RC_AUX_F, RC_SW_G, RC_SW_H, RC_SW_I.
Return: -100..+100, 0 = zero position
Example: if (fc_get_rc(RC_AUX_F) > 75)
{
  // Do something
}


fc_get_sys_time()

U32 fc_get_sys_time (void)
获得运行时间。

            Param1: None.
Return: System Time in milli-seconds.
Example: U32 sys_time;

sys_time = fc_get_sys_time();


fc_get_utc_time()

U32 fc_get_utc_time (void)
获得UTC时间。

            Param1: None.
Return: UTC time.
Example: U32 utc_time;

utc_time = fc_get_utc_time();


fc_get_utc_date()

U32 fc_get_utc_date (void)
获得UTC日期。

            Param1: None.
Return: UTC date.
Example: U32 utc_date;

utc_date = fc_get_utc_date();



Math

所有数学函数都默认为单精度(浮点)。双精度函数也可使用。在函数名后面加上’’’d’’’即可调用双精度函数。
比如,fc_sin()调用单精度计算,fc_sind()调用双精度计算。
双精度计算所需的计算能力比单精度函数大。如果可能,强烈建议使用单精度函数' 如果有输入参数在范围之外的,所有函数将归零。

fc_acos()

float fc_acos(float x)
返回x的反余弦(弧度)

            Param1: The value x must be within the range of -1 to +1 (inclusive).
Return: Arc cosine of x in radians. The returned value is in the range of 0 to pi (inclusive).
Example: float acos;

acos = fc_acos(0.5f);


fc_asin()

float asin (float x)
返回x的反正弦(弧度)。

            Param1: The value x must be within the range of -1 to +1 (inclusive).
Return: Arc sine of x in radians. The returned value is in the range of –pi/2 to +pi/2 (inclusive).
Example: float asin;

asin = fc_ asin(0.5f);


fc_atan()

float fc_atan (float x)
返回x的反正切(弧度)。

            Param1: The value x has no range.
Return: The arc tangent of x in radians. The returned value is in the range of –pi/2 to +pi/2 (inclusive).
Example: float atan;

atan = fc_atan(0.5f);


fc_atan2()

float fc_atan2 (float x, float y)
返回x的反正切(弧度)。

            Param1: The values x and y cannot be zero.
Return: The arc tangent in radians of y / x based on the signs of both values to determine the correct quadrant.
Example: float atan2;

atan2 = fc_atan2(0.5f);


fc_ceil()

float fc_ceil (float x)
返回大于或等于x的最小整数值。

            Param1: There is no range limit on x.
Return: The smallest integer value greater than or equal to x.
Example: S32 ceil;

ceil = fc_ceil(123.5f);


fc_cos()

float fc_cos (float x)
返回弧度角度x的余弦。

            Param1: There is no range limit on x.
Return: Range of -1 to +1 (inclusive).
Example: float cos;

cos = fc_ cos(0.5f);


fc_deg2rad()

float fc_deg2rad (float x)
返回角度x的弧度。

            Param1: Angle in degrees.
Return: Angle in radians.
Example: float deg;

deg = fc_ deg2rad (45.0f);


fc_exp()

float fc_exp (float x)
Return the value of e raised to the xth power.

            Param1: There is no range limit on x.
Return: There is no range limit on the return value.
Example: float exp;

exp = fc_ exp (2.0f);


fc_fabs()

float fc_fabs (float x)
返回x的绝对值。负数变成正数。

            Param1: There is no range limit on x.
Return: There is no range limit on the return value.
Example: float abs;

abs = fc_ fabs (-0.5f);


fc_floor()

float fc_floor (float x)
返回小于或等于x的最大整数值。

            Param1: There is no range limit on x.
Return: There is no range limit on the return value.
Example: S32 floor;

floor = fc_ floor(123.5f);


fc_fmod()

float fc_fmod (float x, float y)
返回x除以y的余数。

            Param1: There is no range limit on x.
  Param2: Must not be 0, otherwise the function returns 0.
Return: There is no range limit on the return value.
Example: float mod;

mod = fc_ fmod(5.0f, 3.0f);


fc_log()

float fc_log (float x)
返回x的自然对数(以e为底的对数)。

            Param1: There is no range limit on x.
Return: There is no range limit on the return value.
Example: float log;

log = fc_ log(5.5f);


fc_log10()

float fc_log10 (float x)
返回x的常用对数(以10为底的对数)

            Param1: There is no range limit on x.
Return: There is no range limit on the return value.
Example: float log10;

log10 = fc_ log10(0.5f);


fc_pow()

float fc_pow (float x, float y)
Return x raised to the power of y.

            Param1: May not be negative if y is a fractional value.
  Param2: If <= 0 then x cannot be zero.
Return: There is no range limit on the return value.
Example: float pow;

pow = fc_ pow(2.5f, 2.5f);


fc_rad2deg()

float fc_rad2deg (float x)
返回角度度数。

            Param1: Angle x in radians.
Return: Angle in degrees.
Example: float deg;

deg = fc_ rad2deg(0.5f);


fc_sinh()

float fc_sinh (float x)
返回双曲正弦x。

            Param1: There is no range limit on x.
Return: There is no range limit on the return value.
Example: float sinh;

sinh = fc_ sinh(0.5f);


fc_sqrt()

float fc_sqrt (float x)
返回x的平方根。

            Param1: Cannot be negative.
Return: Is always positive.
Example: float sqrt;

sqrt = fc_ sqrt(2.5f);


fc_tan()

float fc_tan (float x)
返回弧度角度x的正切。

            Param1: There is no range limit on x.
Return: There is no range limit on the return value.
Example: float tan;

tan = fc_ tan (0.5f);


fc_tanh()

float fc_tanh (float x)
返回x的双曲正切。

            Param1: There is no range limit on x.
Return: Range of -1 to +1 (inclusive).
Example: float tanh;

tanh = fc_tanh(0.5f);



个人工具
名字空间
变换
操作
导航
工具箱