An onboard system for controlling flight of an unmanned aerial vehicle, comprising: a flight management system configured for controlling flight of the unmanned aerial vehicle; a mission control module configured to manage the mission by issuing commands addressed to the flight management system for guiding the unmanned aerial vehicle to perform a mission; a safety module configured to issue commands addressed to the flight management system for guiding the unmanned aerial vehicle to continue flying safely in a safe mode; a communication control component which is switchable between a mission state in which the flight management system receives communication of commands from the mission control module and a safety state in which the flight management system receives communication of commands from the safety module; a monitor module configured to determine whether a trigger condition warranting a change in mode from a mission mode to a safe mode is present or not and to cause the communication control component to switch from the mission state to the safety state when the trigger condition is present; a plurality of flight status sensors; and a sensor connected to send data to the monitor module regarding a position of an object, wherein the flight management system comprises a vehicle state estimator that receives data from the flight status sensors and communicates vehicle state estimates, including at least a vehicle position and speed, to the monitor module, the monitor module being further configured to calculate a position of the object relative to the unmanned aerial vehicle, and to determine that the trigger condition is present when a position of an object relative to the unmanned aerial vehicle violates a distance constraint. a flight management system configured for controlling flight of the unmanned aerial vehicle; a mission control module configured to manage the mission by issuing commands addressed to the flight management system for guiding the unmanned aerial vehicle to perform a mission; a safety module configured to issue commands addressed to the flight management system for guiding the unmanned aerial vehicle to continue flying safely in a safe mode; a communication control component which is switchable between a mission state in which the flight management system receives communication of commands from the mission control module and a safety state in which the flight management system receives communication of commands from the safety module; a monitor module configured to determine whether a trigger condition warranting a change in mode from a mission mode to a safe mode is present or not and to cause the communication control component to switch from the mission state to the safety state when the trigger condition is present; a plurality of flight status sensors; and a sensor connected to send data to the monitor module regarding a position of an object, wherein the flight management system comprises a vehicle state estimator that receives data from the flight status sensors and communicates vehicle state estimates, including at least a vehicle position and speed, to the monitor module, the monitor module being further configured to calculate a position of the object relative to the unmanned aerial vehicle, and to determine that the trigger condition is present when a position of an object relative to the unmanned aerial vehicle violates a distance constraint.