{"action":"created","issue":{"url":"https://api.github.com/repos/dronecore/DroneCore/issues/291","repository_url":"https://api.github.com/repos/dronecore/DroneCore","labels_url":"https://api.github.com/repos/dronecore/DroneCore/issues/291/labels{/name}","comments_url":"https://api.github.com/repos/dronecore/DroneCore/issues/291/comments","events_url":"https://api.github.com/repos/dronecore/DroneCore/issues/291/events","html_url":"https://github.com/dronecore/DroneCore/issues/291","id":300624228,"number":291,"title":"Can't arm immediately after instantiating Action plugin","user":{"login":"shakthi-prashanth-m","id":26615772,"avatar_url":"https://avatars2.githubusercontent.com/u/26615772?v=4","gravatar_id":"","url":"https://api.github.com/users/shakthi-prashanth-m","html_url":"https://github.com/shakthi-prashanth-m","followers_url":"https://api.github.com/users/shakthi-prashanth-m/followers","following_url":"https://api.github.com/users/shakthi-prashanth-m/following{/other_user}","gists_url":"https://api.github.com/users/shakthi-prashanth-m/gists{/gist_id}","starred_url":"https://api.github.com/users/shakthi-prashanth-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shakthi-prashanth-m/subscriptions","organizations_url":"https://api.github.com/users/shakthi-prashanth-m/orgs","repos_url":"https://api.github.com/users/shakthi-prashanth-m/repos","events_url":"https://api.github.com/users/shakthi-prashanth-m/events{/privacy}","received_events_url":"https://api.github.com/users/shakthi-prashanth-m/received_events","type":"User","site_admin":false},"labels":[{"id":629977269,"url":"https://api.github.com/repos/dronecore/DroneCore/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":22,"created_at":"2018-02-27T13:14:11Z","updated_at":"2018-02-28T22:10:13Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I got confused about why does my application fails to arm many times.\r\nI reported this to @julianoes recently. Me & @Rjasuja were debugging and concluded that `Telemetry::health_all_ok()` should be called more than once to get proper health status (_partly correct_).\r\n\r\nHowever, this was not the root cause of the issue.\r\nConsider below pieces of code fragments.\r\n\r\nBelow code **fails** to arm:\r\n```\r\nauto action = std::make_shared<Action>(&device);\r\n\r\nauto arm_result = action->arm();\r\naction_error_exit(arm_result, \"Arming failed: \");\r\n```\r\n\r\nBut this **does** arm:\r\n```\r\nauto action = std::make_shared<Action>(&device);\r\n\r\nsleep_for(seconds(1)); // wait for 1 second to receive Landing state of the device.\r\n\r\nauto arm_result = action->arm();\r\naction_error_exit(arm_result, \"Arming failed: \");\r\n```\r\n\r\nWe better document this to user. Or Did I misunderstand something ?"},"comment":{"url":"https://api.github.com/repos/dronecore/DroneCore/issues/comments/369400776","html_url":"https://github.com/dronecore/DroneCore/issues/291#issuecomment-369400776","issue_url":"https://api.github.com/repos/dronecore/DroneCore/issues/291","id":369400776,"user":{"login":"hamishwillee","id":5368500,"avatar_url":"https://avatars2.githubusercontent.com/u/5368500?v=4","gravatar_id":"","url":"https://api.github.com/users/hamishwillee","html_url":"https://github.com/hamishwillee","followers_url":"https://api.github.com/users/hamishwillee/followers","following_url":"https://api.github.com/users/hamishwillee/following{/other_user}","gists_url":"https://api.github.com/users/hamishwillee/gists{/gist_id}","starred_url":"https://api.github.com/users/hamishwillee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hamishwillee/subscriptions","organizations_url":"https://api.github.com/users/hamishwillee/orgs","repos_url":"https://api.github.com/users/hamishwillee/repos","events_url":"https://api.github.com/users/hamishwillee/events{/privacy}","received_events_url":"https://api.github.com/users/hamishwillee/received_events","type":"User","site_admin":false},"created_at":"2018-02-28T22:10:13Z","updated_at":"2018-02-28T22:10:13Z","author_association":"CONTRIBUTOR","body":"@shakthi-prashanth-m @JonasVautherin \r\n\r\n> I think it should be fine. If user want to understand why was **command denied**, he may install Telemetry plugin and perform health check, etc. Sounds good ?\r\n\r\nSo yes to the broad point that `is_armable()` in the Action plugin is just binary information, and that getting detailed information on why something is not arming requires loading Telemetry module. \r\n- the `is_armable()` must be 100% reliable. If this passes, the only reason arming should fail would be a subsequent change in state - ie a failsafe engaged between is_armable being true, and arm being received.\r\n- It must be possible to find out all blocking reasons, including land state or non-initialisation - is this the case? \r\n\r\nSo this code looks good ...\r\n```cpp\r\nwhile (!action->is_armable()) {\r\n   std::cout << \"Waiting for to arm...\" << std::endl;\r\n   //Here you could check Telemetry to find out why things are failing\r\n   sleep_for(seconds(1));\r\n}\r\n// Arm vehicle\r\nstd::cout << \"Arming...\" << std::endl;\r\nauto arm_result = action->arm();\r\nhandle_action_err_exit(arm_result, \"Arming failed: \"); //Could also check to find out why\r\nstd::cout << \"Armed.\" << std::endl;\r\n```\r\nBut generally you should not get the following log (a command denied) because `is_armable` has returned true. \r\n```\r\nDiscovered device with UUID: 4294967298\r\nWaiting for to arm...\r\nArming...\r\n[03:50:24|Warn ] command temporarily rejected (176). (mavlink_commands.cpp:143)\r\nArming failed: Command denied\r\n```\r\n\r\nSo I wouldn't have:\r\n\r\n> The vehicle might reject commands while it is initializing, and if you want to know when it is ready, you get this information from the telemetry.\"\r\n\r\nas it implies that you have to check on telemetry to know **when** things are ready, but in fact you only check on telemetry to find out **why* it is not ready. Perhaps:\r\n\r\n> The vehicle might reject commands while it is initializing. You should check the is_armable() state to determine when it is ready to arm. If you wish to understand what condition the vehicle is waiting on then you can get this information from the telemetry.\"\r\n\r\n"}}
{"actor":{"display_login":"hamishwillee"}}