Qualcomm Navigator Flight Control Interface
2.0
|
Interface to the Qualcomm Navigator Flight Controller. More...
#include <flight_control_interface.hpp>
Public Types | |
enum | Permissions { Permissions::READ_WRITE, Permissions::READ_ONLY } |
Defines the permissions of an instance of FlightControlInterface. More... | |
enum | Return { Return::SUCCESS, Return::FAILURE, Return::NOT_CONNECTED, Return::ALREADY_CONNECTED, Return::TRAJ_NOT_OPTIMIZED, Return::TRAJ_NOT_FEASIBLE, Return::ACTION_PREEMPTED, Return::NO_LOCK } |
Return codes for FlightControlInterface. More... | |
enum | Action { Action::NONE, Action::TAKEOFF, Action::GO_TO_WAYPOINT, Action::EXECUTE_MISSION, Action::LAND } |
Enum used for possible actions. More... | |
Public Member Functions | |
FlightControlInterface (const Permissions &requested_access) | |
Constructs an instance of FlightControlInterface. More... | |
~FlightControlInterface () noexcept | |
Destructor of FlightControlInterface. More... | |
Return | configure_tx (const TxConfig &tx_config) |
Specify configuration options for sending commands to Qualcomm Navigator. More... | |
Return | configure_rx (const RxConfig &rx_config) |
Specify configuration options for receiving data from Qualcomm Navigator. More... | |
void | wait_for_configure () const noexcept |
Block until FlightControlInterface has been configured. More... | |
Return | connect () |
Establish connection to Qualcomm Navigator. More... | |
Return | disconnect () noexcept |
End connection to Qualcomm Navigator. More... | |
Return | start_props () |
Blocking call to start the propellers. More... | |
Return | stop_props () |
Blocking call to stop the propellers. More... | |
Return | takeoff (const TakeoffConfig &takeoff_config) |
Blocking call to takeoff. More... | |
Return | takeoff () |
Return | takeoff_nb (const TakeoffConfig &takeoff_config) |
Non-blocking call to takeoff. More... | |
Return | takeoff_nb () |
Return | land (const LandingConfig &landing_config) |
Blocking call to land. More... | |
Return | land () |
Return | land_nb (const LandingConfig &landing_config) |
Non-blocking call to land. More... | |
Return | land_nb () |
Return | go_to_waypoint (const Waypoint &waypoint) |
Blocking call to go to specified waypoint. More... | |
Return | go_to_waypoint_nb (const Waypoint &waypoint) |
Non-blocking call to go to specified waypoint. More... | |
Return | configure_planner (const PlannerConfig &config) |
Specify the configuration options for the planner. More... | |
Return | preload_waypoints (const std::vector< Waypoint > &waypoints) |
Load a vector of waypoints. More... | |
Return | compute_trajectory (StateVector starting_state) |
Compute a trajectory through the given waypoints. More... | |
Return | execute_mission (const double t_start=0) |
Execute the trajectory-following mission. More... | |
Return | execute_mission_nb (const double t_start=0) |
Non-blocking call to execute the trajectory-following mission. More... | |
void | wait_on_action () const noexcept |
Wait for the currently-executing action to complete. More... | |
Permissions | get_permissions () const noexcept |
Return the permissions of this object. More... | |
Return | get_last_action_result () const noexcept |
Get the result of the most recently executed action. More... | |
Action | get_last_action () const noexcept |
Get the most recently executed action. More... | |
Action | get_current_action () const noexcept |
Get the currently-executing action. More... | |
Return | get_current_trajectory (std::vector< snav_traj_gen::SnavTrajectory > &traj) const |
Get the current trajectory. More... | |
Return | get_last_optimized_trajectory (std::vector< snav_traj_gen::SnavTrajectory > &traj) const |
Get the last optimized trajectory. More... | |
Return | get_waypoints (std::vector< Waypoint > &waypoints) const |
Get the input waypoints. More... | |
Return | get_optimized_waypoints (std::vector< Waypoint > &waypoints) const |
Get the optimized waypoints. More... | |
Planner::Status | get_planner_status () const |
Get the current status of the Planner. More... | |
float | get_trajectory_time () const |
Get the current trajectory time. More... | |
Return | set_waypoint_frame_tf (const Eigen::Quaternionf &q_pw, const Eigen::Vector3f &t_pw) |
Updates the transform between ReferenceFrame::WAYPOINT and its parent. More... | |
Return | get_waypoint_frame_tf (Eigen::Quaternionf &q_pw, Eigen::Vector3f &t_pw) const |
Get the transform between ReferenceFrame::WAYPOINT and its parent. More... | |
Return | set_tx_command (const TxCommand &command) |
Directly set the command being sent to the flight controller. More... | |
SnavCachedData | get_snav_cached_data () const |
Get a copy of the latest data from the cache. More... | |
StateVector | get_estimated_state (const SnavCachedData &snav_data) const |
Get the estimated state as a StateVector with respect to ReferenceFrame::WAYPOINT from the SnavCachedData structure. More... | |
StateVector | get_desired_state (const SnavCachedData &snav_data) const |
Get the desired state as a StateVector with respect to ReferenceFrame::WAYPOINT from the SnavCachedData structure. More... | |
Return | convert_velocity_to_rc_command (const std::array< float, 3 > velocity, const float yaw_rate, RcCommand &rc_command) |
Convert metric velocity command into an RcCommand suitable for sending to the flight controller based on the configured mode. More... | |
Static Public Member Functions | |
static void | preempt_current_action () |
Send preempt signal to currently-executing action. | |
static void | set_verbosity (bool verbose) |
Set verbosity of FlightControlInterface. More... | |
static bool | tx_ok () |
Whether or not write access to Qualcomm Navigator is ok. | |
static bool | rx_ok () |
Whether or not read access to Qualcomm Navigator is ok. | |
static bool | ok () |
Whether or not read and write access to Qualcomm Navigator is ok. | |
static std::string | get_return_as_string (Return ret_code) |
Convert a Return code to a string. More... | |
Interface to the Qualcomm Navigator Flight Controller.
FlightControlInterface is a thread-safe C++ wrapper around the Qualcomm Navigator API that makes it easier to accomplish some high-level actions like taking off and going to waypoints. It handles basic error checking so that the developer does not have to implement as much logic to check aspects of the flight controller's state during runtime, leading to safer API programs.
|
strong |
|
strong |
Defines the permissions of an instance of FlightControlInterface.
An instance with READ_WRITE permissions can both send commands to and receive data from Qualcomm Navigator, whereas an instance with READ_ONLY permissions can only receive data from Qualcomm Navigator.
Only one instance of FlightControlInterface in a given process can obtain READ_WRITE permissions. This is intended to be a safety mechanism, since commands should only come from a single source.
|
strong |
Return codes for FlightControlInterface.
These return codes define whether or not a function executed successfully and, in the event of failure, why the failure occurred.
|
explicit |
Constructs an instance of FlightControlInterface.
[in] | requested_permissions | Specifies desired permissions of this instance. Only one FlightControlInterface instance can be granted write permissions. |
std::runtime_error | If unable to initialize SnavCachedData (usually means that flight controller is not responding) |
std::logic_error | If requested Permissions::READ_WRITE but an object with write permissions has already been created |
|
noexcept |
Destructor of FlightControlInterface.
Before object destruction, disconnect() is called if it was not called previously.
Return snav_fci::FlightControlInterface::compute_trajectory | ( | StateVector | starting_state | ) |
Compute a trajectory through the given waypoints.
[in] | starting_state | State represented with respect to ReferenceFrame::WAYPOINT used as first constraint of trajectory |
std::logic_error | If any precondition is violated |
std::logic_error | If waypoint timestamps are not monotonically increasing |
std::runtime_error | If trajectory generation fails |
Return snav_fci::FlightControlInterface::configure_planner | ( | const PlannerConfig & | config | ) |
Specify the configuration options for the planner.
If this function is not called, default options are used.
[in] | config | Defines options used by the planner |
Specify configuration options for receiving data from Qualcomm Navigator.
If this function is not called, default options are used.
[in] | rx_config | Defines options used in receiving data |
std::logic_error | If any precondition is violated |
Specify configuration options for sending commands to Qualcomm Navigator.
If this function is not called, default options are used.
[in] | tx_config | Defines options used in sending commands |
std::logic_error | If any precondition is violated |
std::runtime_error | If given config is impossible to achieve |
Return snav_fci::FlightControlInterface::connect | ( | ) |
Establish connection to Qualcomm Navigator.
Opens a persistent connection between the FlightControlInterface object and Qualcomm Navigator.
Return snav_fci::FlightControlInterface::convert_velocity_to_rc_command | ( | const std::array< float, 3 > | velocity, |
const float | yaw_rate, | ||
RcCommand & | rc_command | ||
) |
Convert metric velocity command into an RcCommand suitable for sending to the flight controller based on the configured mode.
This function only works for closed-loop position control modes.
[in] | velocity | Desired velocity in meters per second with respect to ReferenceFrame::ESTIMATION |
[in] | yaw_rate | Desired yaw rate in radians per second with respect to ReferenceFrame::ESTIMATION |
[out] | rc_command | Resulting rc command ready to be sent to the flight controller |
std::logic_error | If any precondition is violated |
|
noexcept |
End connection to Qualcomm Navigator.
Return snav_fci::FlightControlInterface::execute_mission | ( | const double | t_start = 0 | ) |
Execute the trajectory-following mission.
Causes the vehicle to execute the planned trajectory through the given waypoints. If no trajectory has been planned, one will be generated and consequently executed.
[in] | t_start | Optional parameter defining the absolute start time for the mission in seconds according to the system-wide real time wall clock. Set t_start equal to zero for the mission to start immediately. If t_start is not zero, it must specify a moment in time in the future. t_start is used to establish time zero for "trajectory time," accessible via get_trajectory_time(). |
std::logic_error | If any precondition is violated |
std::logic_error | If waypoint timestamps are not monotonically increasing |
std::runtime_error | If trajectory generation fails |
std::runtime_error | If tx/rx connection is lost |
std::invalid_argument | If t_start is negative or corresponds to a time in the past |
Return snav_fci::FlightControlInterface::execute_mission_nb | ( | const double | t_start = 0 | ) |
Non-blocking call to execute the trajectory-following mission.
This is a non-blocking version of execute_mission().
|
noexcept |
Get the currently-executing action.
Return snav_fci::FlightControlInterface::get_current_trajectory | ( | std::vector< snav_traj_gen::SnavTrajectory > & | traj | ) | const |
Get the current trajectory.
[out] | traj | The current trajectory, possibly composed of multiple segments each defined by a SnavTrajectory object, which has been optimized and satisfies the constraints enforced by the Planner. This is valid only if function returns Return::SUCCESS |
StateVector snav_fci::FlightControlInterface::get_desired_state | ( | const SnavCachedData & | snav_data | ) | const |
Get the desired state as a StateVector with respect to ReferenceFrame::WAYPOINT from the SnavCachedData structure.
[in] | snav_data | Structure containing data from the cache |
StateVector snav_fci::FlightControlInterface::get_estimated_state | ( | const SnavCachedData & | snav_data | ) | const |
Get the estimated state as a StateVector with respect to ReferenceFrame::WAYPOINT from the SnavCachedData structure.
[in] | snav_data | Structure containing data from the cache |
|
noexcept |
Get the most recently executed action.
|
noexcept |
Get the result of the most recently executed action.
Return snav_fci::FlightControlInterface::get_last_optimized_trajectory | ( | std::vector< snav_traj_gen::SnavTrajectory > & | traj | ) | const |
Get the last optimized trajectory.
The last optimized trajectory may be different from the current trajectory if the last optimized trajectory failed to satisfy the constraints enforced by the Planner.
[out] | traj | The last optimized trajectory, possibly composed of multiple segments each defined by a SnavTrajectory object, which has been optimized but does not necessarily satisfy the constraints enforced by the Planner. Only valid if function returns Return::SUCCESS. |
Return snav_fci::FlightControlInterface::get_optimized_waypoints | ( | std::vector< Waypoint > & | waypoints | ) | const |
Get the optimized waypoints.
The optimized waypoints are different from the input waypoints in that they are an augmented set of the input waypoints. For example, the optimized waypoints contain at least one extra waypoint prepended to the start of the vector containing the current state. Further, they contain the higher derivatives computed from the optimization.
[out] | waypoints | Vector of optimized waypoints used by planner |
|
noexcept |
Return the permissions of this object.
Planner::Status snav_fci::FlightControlInterface::get_planner_status | ( | ) | const |
Get the current status of the Planner.
|
static |
Convert a Return code to a string.
[in] | ret_code | Return code to convert to string |
SnavCachedData snav_fci::FlightControlInterface::get_snav_cached_data | ( | ) | const |
Get a copy of the latest data from the cache.
std::logic_error | If any precondition is violated |
float snav_fci::FlightControlInterface::get_trajectory_time | ( | ) | const |
Get the current trajectory time.
Trajectory time is relative to the current trajectory. The start of the trajectory corresponds to time zero.
Return snav_fci::FlightControlInterface::get_waypoint_frame_tf | ( | Eigen::Quaternionf & | q_pw, |
Eigen::Vector3f & | t_pw | ||
) | const |
Get the transform between ReferenceFrame::WAYPOINT and its parent.
[out] | q_pq | Quaternion representing the orientation of ReferenceFrame::WAYPOINT with respect to its parent |
[out] | t_pw | Vector from the origin of the parent frame to the origin of ReferenceFrame::WAYPOINT represented with respect to the parent frame |
Get the input waypoints.
[out] | waypoints | Vector of input waypoints used by planner |
Blocking call to go to specified waypoint.
[in] | waypoint | Specifies the destination waypoint represented with respect to ReferenceFrame::WAYPOINT |
std::logic_error | If any precondition is violated |
std::runtime_error | If tx/rx connection is lost |
Non-blocking call to go to specified waypoint.
This is a non-blocking version of go_to_waypoint().
Return snav_fci::FlightControlInterface::land | ( | const LandingConfig & | landing_config | ) |
Blocking call to land.
This function commands the vehicle to descend until reaching the ground, at which point it attempts to stop the propellers via stop_props().
[in] | landing_config | Specifies parameters for landing |
std::logic_error | If any precondition is violated |
std::runtime_error | If tx/rx connection is lost |
Return snav_fci::FlightControlInterface::land | ( | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Return snav_fci::FlightControlInterface::land_nb | ( | const LandingConfig & | landing_config | ) |
Non-blocking call to land.
This is a non-blocking version of land().
Return snav_fci::FlightControlInterface::land_nb | ( | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Return snav_fci::FlightControlInterface::preload_waypoints | ( | const std::vector< Waypoint > & | waypoints | ) |
Load a vector of waypoints.
[in] | waypoints | Waypoints to pass to planner. |
std::logic_error | If any precondition is violated |
Directly set the command being sent to the flight controller.
This function sets the command being sent to the flight controller in the tx thread. Calling this function will only have an impact if the tx thread is configured for sending this type of command.
[in] | command | Command to be sent to the flight controller |
std::logic_error | If any precondition is violated |
|
inlinestatic |
Set verbosity of FlightControlInterface.
By default, verbosity of FlightControlInterface is set to true. When true, FlightControlInterface emits informational messages to std::out and error messages to std::cerr.
[in] | verbose | Desired verbosity of FlightControlInterface |
Return snav_fci::FlightControlInterface::set_waypoint_frame_tf | ( | const Eigen::Quaternionf & | q_pw, |
const Eigen::Vector3f & | t_pw | ||
) |
Updates the transform between ReferenceFrame::WAYPOINT and its parent.
FlightControlInterface expects waypoints to be given with respect to ReferenceFrame::WAYPOINT. The transformation between ReferenceFrame::WAYPOINT and its parent, defined by TxConfig::waypoint_frame_parent, is initialized to identity rotation and zero translation.
[in] | q_pw | Quaternion representing the orientation of ReferenceFrame::WAYPOINT with respect to its parent |
[in] | t_pw | Vector from the origin of the parent frame to the origin of ReferenceFrame::WAYPOINT represented with respect to the parent frame |
Return snav_fci::FlightControlInterface::start_props | ( | ) |
Blocking call to start the propellers.
In general, favor calling takeoff(), which automatically calls start_props() at the appropriate time, instead of manually calling this function.
std::logic_error | If any precondition is violated |
std::runtime_error | If tx/rx connection is lost |
std::runtime_error | If unable to start props |
Return snav_fci::FlightControlInterface::stop_props | ( | ) |
Blocking call to stop the propellers.
In general, favor calling land(), which automatically calls stop_props() at the appropriate time, instead of manually calling this function.
std::logic_error | If any precondition is violated |
std::runtime_error | If tx/rx connection is lost |
std::runtime_error | If unable to stop props |
Return snav_fci::FlightControlInterface::takeoff | ( | const TakeoffConfig & | takeoff_config | ) |
Blocking call to takeoff.
This function attempts to spin the propellers via start_props() and to take off to a specified height above the ground.
[in] | takeoff_config | Specifies parameters for takeoff |
std::logic_error | If any precondition is violated |
std::runtime_error | If tx/rx connection is lost |
Return snav_fci::FlightControlInterface::takeoff | ( | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Return snav_fci::FlightControlInterface::takeoff_nb | ( | const TakeoffConfig & | takeoff_config | ) |
Non-blocking call to takeoff.
This is a non-blocking version of takeoff().
Return snav_fci::FlightControlInterface::takeoff_nb | ( | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
noexcept |
Block until FlightControlInterface has been configured.
This function can be used in a multithreaded architecture to synchronize multiple FlightControlInterface objects before calling connect() to ensure that the object with Permissions::READ_WRITE has an opportunity to set the desired configuration. This is necessary because it would otherwise be possible for an object with Permissions::READ_ONLY to spawn the rx thread prior to the rx configuration being set from a separate thread.
|
noexcept |
Wait for the currently-executing action to complete.
Blocks until the currently-executing action completes. The result of the action can be obtained via get_last_action_result().