uav.vehicles.UAV#
Attributes#
Classes#
Abstract base class for UAV control and interfacing with PX4 via ROS 2. |
Functions#
|
Module Contents#
- _NAV_STATE_NAMES#
- class UAV(node: rclpy.node.Node, DEBUG=False, camera_offsets=[0, 0, 0], vehicle_name: str = 'uav')#
Bases:
vehicle_common.vehicle.VehicleAbstract base class for UAV control and interfacing with PX4 via ROS 2. Subclasses: VTOL, Multicopter
- node#
- DEBUG = False#
- flight_check = False#
- emergency_landing = False#
- failsafe = False#
- failsafe_px4 = False#
- failsafe_trigger = False#
- vehicle_status = None#
- vehicle_attitude = None#
- arm_state = None#
- system_id = 1#
- component_id = 1#
- max_acceleration = 0.01#
- default_velocity = 5.0#
- camera_offsets = [0, 0, 0]#
- origin_set = False#
- roll = None#
- pitch = None#
- yaw = None#
- attempted_takeoff = False#
- local_origin = None#
- gps_origin = None#
- global_position = None#
- local_position = None#
- arm()#
Send an arm command to the UAV.
- set_origin()#
- distance_to_waypoint(coordinate_system, waypoint) float#
Calculate the distance to the current waypoint.
- hover()#
- stop() None#
- disarm(force=False)#
Send a disarm command to the UAV.
- engage_offboard_mode()#
Switch to offboard mode.
- takeoff(takeoff_height=5.0)#
Command the UAV to take off to the specified altitude. This uses a NAV_TAKEOFF command; actual behavior depends on PX4 mode.
- land()#
Command the UAV to land.
- drop_payload()#
- pickup_payload()#
- disable_servo()#
- publish_position_setpoint(coordinate, relative=False, lock_yaw=False)#
Publish the trajectory setpoint.
- Parameters:
coordinate (tuple) – (x, y, z) in the local frame.
relative (bool) – If True, the position is relative to the current local position.
lock_yaw (bool) – If True, maintain current yaw instead of recalculating (prevents spinning when hovering).
- calculate_yaw(x: float, y: float) float#
Calculate the yaw angle to point towards the next waypoint.
- abstractmethod _calculate_velocity(target_pos: tuple, lock_yaw: bool) list#
Calculate velocity vector for trajectory setpoint. Must be implemented by subclasses (VTOL, Multicopter).
- Parameters:
target_pos – (x, y, z) target position in local frame
lock_yaw – Whether yaw is locked (hovering)
- Returns:
[vx, vy, vz] velocity list in m/s
- publish_offboard_control_heartbeat_signal()#
Publish the offboard control mode.
- gps_distance_3d(lat1, lon1, alt1, lat2, lon2, alt2)#
Calculate the 3D distance in feet between two GPS points, including altitude.
- Parameters:
lat1 (float) – Latitude of the first point in decimal degrees.
lon1 (float) – Longitude of the first point in decimal degrees.
alt1 (float) – Altitude of the first point in feet above sea level.
lat2 (float) – Latitude of the second point in decimal degrees.
lon2 (float) – Longitude of the second point in decimal degrees.
alt2 (float) – Altitude of the second point in feet above sea level.
- Returns:
The 3D distance between the two points in feet.
- Return type:
float
- gps_to_local(target)#
Convert target GPS coordinates to local NED coordinates.
- Parameters:
target (tuple) – (target_lat, target_lon, target_alt)
ref (tuple) – (ref_lat, ref_lon, ref_alt) from the local position message
- Returns:
- (x, y, z) in the local frame where:
x is North (meters), y is East (meters), z is Down (meters)
- Return type:
tuple
- uav_to_local(point, relative=False)#
Converts a point in the UAV’s local frame to the global frame.
- Parameters:
point – A tuple (point_x, point_y, point_z) in the UAV’s local frame.
relative – If True, the point is relative to the current local position.
- Returns:
A tuple (goal_x, goal_y, goal_z) representing the point in the global frame.
- local_to_gps(local_pos)#
Convert a local NED coordinate to a GPS coordinate.
- Parameters:
local_pos (tuple) – (x, y, z) in meters, where: x: North displacement, y: East displacement, z: Down displacement.
ref_gps (tuple) – (lat, lon, alt) of the reference point (takeoff) in degrees and meters.
- Returns:
(lat, lon, alt) GPS coordinate corresponding to local_pos.
- Return type:
tuple
- get_gps()#
- get_local_position()#
- _calculate_proportional_velocity(direction: numpy.ndarray, distance: float) list#
Calculate velocity using proportional control to prevent oscillation. Velocity smoothly decreases as distance to target decreases.
- Parameters:
direction (np.ndarray) – Unit direction vector [dx, dy, dz]
distance (float) – Distance to target in meters
- Returns:
[vx, vy, vz] velocity vector in m/s
- Return type:
list
- _send_vehicle_command(command: int, params: dict = {}, target_system=None, target_component=None, source_system=None, source_component=None, from_external=True)#
Publish a VehicleCommand message to instruct PX4 to perform an action.
- _vehicle_status_callback(msg: px4_msgs.msg.VehicleStatus)#
- _attitude_callback(msg: px4_msgs.msg.VehicleAttitude)#
- _global_position_callback(msg: px4_msgs.msg.VehicleGlobalPosition)#
- _vehicle_gps_callback(msg: px4_msgs.msg.SensorGps)#
- _vehicle_local_position_callback(msg: px4_msgs.msg.VehicleLocalPosition)#
- _initialize_publishers_and_subscribers()#
Initialize ROS 2 publishers and subscribers.