- get_virtual_target(lower_bound_x: float, lower_bound_y: float, side_length: float) DronePosition: ΒΆ
This function creates a new random virtual target inside the specified working field.
- Args:
lower_bound_x: The x-coordinate of the lower bound of the working field.
lower_bound_y: The y-coordinate of the lower bound of the working field.
side_length: The side length of the working field.
- Returns:
A models.DronePosition object that represents the new virtual target.
Example:
>>> from models.swarm import Swarm
>>> from models.droneposition import DronePosition, m_to_deg
>>> from utils.get_virtual_target import get_virtual_target
>>>
>>> swarm = Swarm()
>>> lower_bound_x = 0.0
>>> lower_bound_y = 0.0
>>> side_length = 1000.0
>>>
>>> virtual_target = get_virtual_target(lower_bound_x, lower_bound_y, side_length)
>>>
>>> print(virtual_target)
DronePosition(latitude_deg=50.0, longitude_deg=0.0, absolute_altitude_m=490.0)
import random
from models.swarm import Swarm
from models.droneposition import DronePosition, m_to_deg
def get_virtual_target(lower_bound_x: float, lower_bound_y: float, side_length: float) -> DronePosition:
virtual_target = DronePosition(0,0,0)
# Update the position based on random velocity
new_latitude = lower_bound_x + random.randint(0, side_length-1)
new_longitude = lower_bound_y + random.randint(0, side_length-1)
virtual_target.latitude_deg = m_to_deg(new_latitude)
virtual_target.longitude_deg = m_to_deg(new_longitude)
virtual_target.absolute_altitude_m = 490
return virtual_target