dronekit / dronekit-python

DroneKit-Python library for communicating with Drones via MAVLink.
https://readthedocs.org/projects/dronekit-python/
Apache License 2.0
1.63k stars 1.45k forks source link

Front View Velocity Control #851

Open alvinxiii opened 6 years ago

alvinxiii commented 6 years ago

Currently, I'm facing a problem which is unable to control the drone's movement via the view from the camera. With OpenCV image processing technique, Im able to draw a blue circle on the screen. The (x,y) coordinates of the blue circle is extracted and I wish to tell drone to follow these coordinates movements. Is this a correct way to navigate the drone (frontview)?.

horizontal_fov = 118.2 * math.pi/180
vertical_fov = 69.5 * math.pi/180
horizontal_resolution = 1024
vertical_resolution = 600

def send_ned_velocity(velocity_x, velocity_y, velocity_z, duration):
    """
    Move vehicle in direction based on specified velocity vectors.
    """
    msg = vehicle.message_factory.set_position_target_local_ned_encode(
        0,       # time_boot_ms (not used)
        0, 0,    # target system, target component
        mavutil.mavlink.MAV_FRAME_LOCAL_NED, # frame
        0b0000111111000111, # type_mask (only speeds enabled)
        0, 0, 0, # x, y, z positions (not used)
        (velocity_x-horizontal_resolution/2)*horizontal_fov/horizontal_resolution,
        (velocity_y-vertical_resolution/2)*vertical_fov/vertical_resolution, 0,
        0, 0, 0, # x, y, z acceleration (not supported yet, ignored in GCS_Mavlink)
        0, 0)    # yaw, yaw_rate (not supported yet, ignored in GCS_Mavlink)

    # send command to vehicle on 1 Hz cycle
    for x in range(0,duration):
        vehicle.send_mavlink(msg)
        time.sleep(1)
kaangoksal commented 6 years ago

Do you get any reactions from the drone? What is your flight mode?