【文章內(nèi)容簡介】
updates */ for (。) { /* wait for updates or a 1second timeout */ struct pollfd fds[3] = { { .fd = sub_red, .events = POLLIN }, { .fd = sub_green, .events = POLLIN }, { .fd = sub_blue, .events = POLLIN } }。 int ret = poll(fds, 3, 1000)。 /* check for a timeout */ if (ret == 0) { puts(timeout)。 = ++timeouts。 orb_publish(ORB_ID(color_timeouts), pub_timeouts, amp。cu)。 /* check for color updates */ } else { if (fds[0].revents amp。 POLLIN) { orb_copy(ORB_ID(color_red), sub_red, amp。cu)。 printf(red is now %d\n, )。 } if (fds[1].revents amp。 POLLIN) { orb_copy(ORB_ID(color_green), sub_green, amp。cu)。 printf(green is now %d\n, )。 } if (fds[2].revents amp。 POLLIN) { orb_copy(ORB_ID(color_blue), sub_blue, amp。cu)。 printf(blue is now %d\n, )。 } } }}限制更新速率:一個訂閱者可能想要限制它們接收的topic的更新速率,這個可以通過下面的函數(shù)實現(xiàn):/** * Set the minimum interval between which updates are seen for a subscription. * * If this interval is set, the subscriber will not see more than one update * within the period. * * Specifically, the first time an update is reported to the subscriber a timer * is started. The update will continue to be reported via poll and orb_check, but * once fetched via orb_copy another update will not be reported until the timer * expires. * * This feature can be used to pace a subscriber that is watching a topic that * would otherwise update too quickly. * * @param handle A handle returned from orb_subscribe. * @param interval An interval period in milliseconds. * @return OK on success, ERROR otherwise with ERRNO set accordingly. */extern int orb_set_interval(int handle, unsigned interval)。速率限制是針對某一個特定的訂閱者的,單個topic可以對多個訂閱者有多種限制速率。添加一個uORB topic和mavlink解析程序參考鏈接:步驟一:添加一個uORB topic在src/modules/uORB/topics文件夾下添加一個新的名為“”的頭文件,其內(nèi)容如下:ifndef TOPIC_CA_TRAJECTORY_MSG_Hdefine TOPIC_CA_TRAJECTORY_MSG_Hinclude include ..//** global 39。actuator output is live39。 control. */struct ca_traj_struct_s { uint64_t timestamp。 uint64_t time_start_usec。 /// starting time of the trajectory. uint64_t time_stop_usec。 /// stopping time of the trajectory. float coefficients[28]。 /// coefficients of the polynomial trajectory. uint16_t seq_id。 /// sequence id of the sent trajectory piece.}。ORB_DECLARE(ca_trajectory_msg)。endif編輯src/modules/uORB/:include topics/ORB_DEFINE(ca_trajectory_msg, struct ca_traj_struct_s)。步驟二:添加一個mavlink解析程序這將會將一個輸入的mavlink消息解析并傳入uORB topic中。假設(shè)mavlink消息和uORB topic有著相同的結(jié)構(gòu)。(注意:下文列出的示例程序中,行首出現(xiàn)“+”表示在原程序中添加該行,“”表示刪除原程序中該行)編輯src/modules/mavlink/include +include 在src/modules/mavlink/:+include uORB/topics/在src/modules/mavlink/:+include uORB/topics/+void handle_message_ca_trajectory_msg(mavlink_message_t *msg)。+orb_advert_t _ca_traj_msg_pub。在src/modules/mavlink/:系統(tǒng)啟動控制 參考鏈接:PX4的啟動是由位于“/etc/”下的啟動腳本(startup script)來控制的,這個腳本位于被編譯到固件中的ROM文件系統(tǒng)中。這個腳本檢測可用的硬件,加載硬件驅(qū)動,并且根據(jù)你的設(shè)置啟動系統(tǒng)正常運行所需的所有app(任務(wù)軟件,包括位置和姿態(tài)估計,位置和姿態(tài)控制,遙測等)。所有屬于自動啟動程序的腳本文件可以在固件源程序的如下目錄中找到:ROMFS/px4fmu_mon/ .這個rcS腳本執(zhí)行如下步驟:1. 掛載SD卡;2. 如果SD中有etc/,則按照該啟動腳本文件進(jìn)行啟動;3. 如果SD卡中沒有etc/,下面的自動啟動程序?qū)粓?zhí)行:a) 如果SYS_AUTOSTART變量被設(shè)置為一個有效的配置,預(yù)定義的模型配置(predefined model configuration)之一將會被加載。模型設(shè)置包含一系列的環(huán)境變量,后面將會詳細(xì)列出。b) 如果SD卡中有etc/,它將被執(zhí)行。這個文件允許對部分或者整個預(yù)定義的模型配置參數(shù)進(jìn)行覆蓋。c) 實際的啟動app將會根據(jù)模型配置定義的環(huán)境變量被執(zhí)行。d) 如果SD卡中etc/,它將被執(zhí)行。這個文件允許在自動啟動程序被執(zhí)行完成后啟動用戶的app(如遙測)。注意:在SD卡中創(chuàng)建etc/rc/txt文件將會使得被編譯在固件內(nèi)部的啟動文件不再執(zhí)行。由于創(chuàng)建這個文件后你必須親自啟動所有的基本系統(tǒng)進(jìn)程,所以除非你是知道自己在做什么的高級用戶,否則請不要創(chuàng)建這個文件。在大多數(shù)情況下,你只需要通過創(chuàng)建etc/(或者)etc/(這樣就不需要擔(dān)心會影響到系統(tǒng)必備程序的啟動)。注意:啟動腳本文件中每行最多允許有80個字符。任何超過80個字符的行都有可能造成啟動出錯。預(yù)編譯模型配置(Predefined Model Configurations):下面是針對一些可以買到的ARF/RTF模型的預(yù)定義的模型配置。要使用這些模型配置中的一個,只需要設(shè)置環(huán)境變量SYS_AUTOSTAET = AUTOSTART_ID。如果要將與機架相關(guān)的參數(shù)(如姿態(tài)控制參數(shù):MC_XXX)設(shè)置為該模型配置默認(rèn)的參數(shù),將參數(shù)SYS_AUTOCONFIG = 1。保存參數(shù)并重新啟動飛控。這些配置參數(shù)將生效,然后SYS_AUTOCONFIG將自動變回0。選擇的模型配置可以通過etc/。下表是Autostart ID與模型的對應(yīng)關(guān)系:Autostart IDModel1001HILQuadcopter X1003HILQuadcopter +3031Phantom FPV Flying Wing3033Wing Wing (aka Z84) Flying Wing3034FX79 Buffalo Flying Wing4008 mechanical frame4010DJI Flamewheel F330 Quadcopter4011DJI Flamewheel F450 Quadcopter10015Team Blacksheep Discovery Quadcopter100163DR Iris Quadcopter配置變量(Configuration Variables):下表中列出的變量定義哪個app會被啟動,哪個硬件將被使用,以及一些別的參數(shù)。它們可以通過SD卡中的etc/。如果SYS_AUTOSTART變量被設(shè)置為一個有效的配置,etc/,比如設(shè)置PWM范圍。Environment variablePossible values(default is underlined)DescriptionVEHICLE_TYPEmc= multicopter,fw= fixed wing,none= nonflying configuration without controllers runningType of vehicleMIXERFor multicopters:FMU_quad_x,FMU_quad_+,FMU_quad_w,FMU_hex_x,FMU_hex_+, …Mixer to use. See section 39。Output mixers39。 below.For fixed wings:FMU_AERT,FMU_AET,FMU_QUSE_IOyes,noIf the PX4IO should be used. Set tonoif using standalone PX4FMUv1 setup.OUTPUT_MODEio,fmu,mkblctrlControl output mode, default value depends onUSE_IOvariable.PWM_OUTPUTSList of channels, .1234,default isnoneChannels the following PWM parameters get applied to.Please note that certain channels are grouped and need to be changed together as documentedhere!PWM_RATEFrequency in Hz,default is50PWM output rate. To improve ESC latency on multicopter setups, it39。s remended to use 400 Hz if ESCs support it.PWM_DISARMEDSignal length in microseconds,default is0PWM output value for disarmed state.0(default value) means no PWM signal, it39。s safe, but many ESC models will beep “no signal” after disarm, so it can be set to lower limit of PWM rangePWM_MINSignal length in microseconds,default is1000PWM value for minimum throttle. Multicopter propsMUSTspin at low idle speed。 this is necessary to prevent full stop of props during flight and warn that the system is armed!PWM_MAXSignal length in microseconds,default is2000PWM valu