{"id":1013,"date":"2023-06-16T22:53:50","date_gmt":"2023-06-16T14:53:50","guid":{"rendered":"http:\/\/www.autouav.net.cn\/?p=1013"},"modified":"2023-06-16T22:59:52","modified_gmt":"2023-06-16T14:59:52","slug":"ardupilot-copter%e4%bb%a3%e7%a0%81%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.autouav.net.cn\/?p=1013","title":{"rendered":"Ardupilot Copter\u4ee3\u7801\u89e3\u6790"},"content":{"rendered":"<p><code>void Copter::get_scheduler_tasks(const AP_Scheduler::Task *&amp;tasks, uint8_t &amp;task_count, uint32_t &amp;log_bit)<br \/>\n{<br \/>\ntasks = &amp;scheduler_tasks[0]; <\/code><code><br \/>\ntask_count = ARRAY_SIZE(scheduler_tasks);<br \/>\nlog_bit = MASK_LOG_PM;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u662fArduPilot\u7684Copter\u7c7b\u4e2d\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u83b7\u53d6\u8c03\u5ea6\u5668\u4efb\u52a1\u7684\u4fe1\u606f\u3002\u5177\u4f53\u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><code>tasks<\/code>\u662f\u4e00\u4e2a\u6307\u5411<code>AP_Scheduler::Task<\/code>\u7ed3\u6784\u4f53\u6570\u7ec4\u7684\u6307\u9488\uff0c\u7528\u4e8e\u5b58\u50a8\u8c03\u5ea6\u5668\u4efb\u52a1\u7684\u4fe1\u606f\u3002\u901a\u8fc7<code>tasks = &amp;scheduler_tasks[0];<\/code>\u5c06<code>scheduler_tasks<\/code>\u6570\u7ec4\u7684\u5730\u5740\u8d4b\u503c\u7ed9<code>tasks<\/code>\u6307\u9488\uff0c\u4ece\u800c\u83b7\u53d6\u4efb\u52a1\u6570\u7ec4\u7684\u8d77\u59cb\u5730\u5740\u3002<\/li>\n<li><code>task_count<\/code>\u662f\u4e00\u4e2auint8_t\u7c7b\u578b\u7684\u5f15\u7528\uff0c\u7528\u4e8e\u5b58\u50a8\u4efb\u52a1\u6570\u91cf\u3002\u901a\u8fc7<code>task_count = ARRAY_SIZE(scheduler_tasks);<\/code>\u5c06<code>scheduler_tasks<\/code>\u6570\u7ec4\u7684\u5927\u5c0f\u8d4b\u503c\u7ed9<code>task_count<\/code>\uff0c\u4ece\u800c\u83b7\u53d6\u4efb\u52a1\u6570\u7ec4\u7684\u5143\u7d20\u6570\u91cf\u3002<\/li>\n<li><code>log_bit<\/code>\u662f\u4e00\u4e2auint32_t\u7c7b\u578b\u7684\u5f15\u7528\uff0c\u7528\u4e8e\u5b58\u50a8\u65e5\u5fd7\u4f4d\u63a9\u7801\u3002\u901a\u8fc7<code>log_bit = MASK_LOG_PM;<\/code>\u5c06<code>MASK_LOG_PM<\/code>\u7684\u503c\u8d4b\u503c\u7ed9<code>log_bit<\/code>\uff0c\u4ece\u800c\u83b7\u53d6\u65e5\u5fd7\u4f4d\u63a9\u7801\u7684\u6570\u503c\u3002<\/li>\n<\/ul>\n<p>\u8be5\u51fd\u6570\u7684\u76ee\u7684\u662f\u5c06\u8c03\u5ea6\u5668\u4efb\u52a1\u7684\u4fe1\u606f\u8fd4\u56de\u7ed9\u8c03\u7528\u65b9\uff0c\u4ee5\u4f9b\u5176\u4ed6\u64cd\u4f5c\u6216\u65e5\u5fd7\u8bb0\u5f55\u4f7f\u7528\u3002<\/p>\n<p><code>\/\/ Main loop - 400hz<br \/>\nvoid Copter::fast_loop()<br \/>\n{<br \/>\n\/\/ update INS immediately to get current gyro data populated<br \/>\nins.update();<\/code><\/p>\n<p>\/\/ run low level rate controllers that only require IMU data<br \/>\nattitude_control-&gt;rate_controller_run();<\/p>\n<p>\/\/ send outputs to the motors library immediately<br \/>\nmotors_output();<\/p>\n<p>\/\/ run EKF state estimator (expensive)<br \/>\n\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nread_AHRS();<\/p>\n<p>#if FRAME_CONFIG == HELI_FRAME<br \/>\nupdate_heli_control_dynamics();<br \/>\n#if MODE_AUTOROTATE_ENABLED == ENABLED<br \/>\nheli_update_autorotation();<br \/>\n#endif<br \/>\n#endif \/\/HELI_FRAME<\/p>\n<p>\/\/ Inertial Nav<br \/>\n\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nread_inertia();<\/p>\n<p>\/\/ check if ekf has reset target heading or position<br \/>\ncheck_ekf_reset();<\/p>\n<p>\/\/ run the attitude controllers<br \/>\nupdate_flight_mode();<\/p>\n<p>\/\/ update home from EKF if necessary<br \/>\nupdate_home_from_EKF();<\/p>\n<p>\/\/ check if we&#8217;ve landed or crashed<br \/>\nupdate_land_and_crash_detectors();<\/p>\n<p>#if HAL_MOUNT_ENABLED<br \/>\n\/\/ camera mount&#8217;s fast update<br \/>\ncamera_mount.update_fast();<br \/>\n#endif<\/p>\n<p>\/\/ log sensor health<br \/>\nif (should_log(MASK_LOG_ANY)) {<br \/>\nLog_Sensor_Health();<br \/>\n}<\/p>\n<p>AP_Vehicle::fast_loop();<br \/>\n}<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u662fArduPilot\u7684Copter\u7c7b\u4e2d\u7684<code>fast_loop()<\/code>\u51fd\u6570\uff0c\u4e3b\u8981\u7528\u4e8e\u6267\u884c\u4e3b\u5faa\u73af\u4e2d\u7684\u9ad8\u9891\u7387\u4efb\u52a1\u3002\u4e0b\u9762\u662f\u6bcf\u4e2a\u6b65\u9aa4\u7684\u529f\u80fd\u8bf4\u660e\uff1a<\/p>\n<ol>\n<li><code>ins.update()<\/code>\uff1a\u7acb\u5373\u66f4\u65b0INS\uff08\u60ef\u6027\u5bfc\u822a\u7cfb\u7edf\uff09\u4ee5\u83b7\u53d6\u5f53\u524d\u7684\u9640\u87ba\u4eea\u6570\u636e\u3002<\/li>\n<li><code>attitude_control-&gt;rate_controller_run()<\/code>\uff1a\u8fd0\u884c\u53ea\u9700\u8981IMU\u6570\u636e\u7684\u4f4e\u7ea7\u901f\u7387\u63a7\u5236\u5668\u3002<\/li>\n<li><code>motors_output()<\/code>\uff1a\u7acb\u5373\u5c06\u8f93\u51fa\u53d1\u9001\u7ed9\u7535\u673a\u5e93\u3002<\/li>\n<li><code>read_AHRS()<\/code>\uff1a\u8fd0\u884cEKF\uff08\u6269\u5c55\u5361\u5c14\u66fc\u6ee4\u6ce2\u5668\uff09\u72b6\u6001\u4f30\u8ba1\u5668\u3002<\/li>\n<li><code>update_heli_control_dynamics()<\/code>\uff08\u4ec5\u9002\u7528\u4e8e\u76f4\u5347\u673a\uff09\uff1a\u66f4\u65b0\u76f4\u5347\u673a\u63a7\u5236\u52a8\u529b\u5b66\u3002<\/li>\n<li><code>heli_update_autorotation()<\/code>\uff08\u4ec5\u9002\u7528\u4e8e\u76f4\u5347\u673a\uff09\uff1a\u66f4\u65b0\u76f4\u5347\u673a\u81ea\u8f6c\u3002<\/li>\n<li><code>read_inertia()<\/code>\uff1a\u60ef\u6027\u5bfc\u822a\u66f4\u65b0\u3002<\/li>\n<li><code>check_ekf_reset()<\/code>\uff1a\u68c0\u67e5EKF\u662f\u5426\u91cd\u7f6e\u76ee\u6807\u822a\u5411\u6216\u4f4d\u7f6e\u3002<\/li>\n<li><code>update_flight_mode()<\/code>\uff1a\u66f4\u65b0\u98de\u884c\u6a21\u5f0f\u3002<\/li>\n<li><code>update_home_from_EKF()<\/code>\uff1a\u4eceEKF\u66f4\u65b0Home\u4f4d\u7f6e\u3002<\/li>\n<li><code>update_land_and_crash_detectors()<\/code>\uff1a\u66f4\u65b0\u7740\u9646\u548c\u78b0\u649e\u68c0\u6d4b\u5668\u3002<\/li>\n<li><code>camera_mount.update_fast()<\/code>\uff08\u5982\u679c\u542f\u7528\u76f8\u673a\u6302\u8f7d\uff09\uff1a\u76f8\u673a\u6302\u8f7d\u7684\u5feb\u901f\u66f4\u65b0\u3002<\/li>\n<li><code>Log_Sensor_Health()<\/code>\uff1a\u8bb0\u5f55\u4f20\u611f\u5668\u5065\u5eb7\u72b6\u6001\u3002<\/li>\n<li><code>AP_Vehicle::fast_loop()<\/code>\uff1a\u6267\u884c\u7236\u7c7bAP_Vehicle\u7684<code>fast_loop()<\/code>\u51fd\u6570\u3002<\/li>\n<\/ol>\n<p>\u8be5\u51fd\u6570\u5728\u4e3b\u5faa\u73af\u4e2d\u4ee5400Hz\u7684\u9891\u7387\u8fd0\u884c\uff0c\u7528\u4e8e\u5904\u7406\u5b9e\u65f6\u7684\u98de\u884c\u63a7\u5236\u4efb\u52a1\uff0c\u5305\u62ec\u59ff\u6001\u63a7\u5236\u3001\u72b6\u6001\u4f30\u8ba1\u3001\u5bfc\u822a\u66f4\u65b0\u7b49\u3002\u4e0d\u540c\u7684\u98de\u884c\u5668\u7c7b\u578b\uff08\u5982\u76f4\u5347\u673a\uff09\u53ef\u80fd\u4f1a\u6709\u4e00\u4e9b\u7279\u5b9a\u7684\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>void Copter::get_scheduler_tasks(const AP_Scheduler::Task *&amp;tasks, uint8_t &amp;task_count, uint&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1013","post","type-post","status-publish","format-standard","hentry","category-uav"],"_links":{"self":[{"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1013"}],"version-history":[{"count":4,"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1017,"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions\/1017"}],"wp:attachment":[{"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.autouav.net.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}