for this code
from dronekit import connect, VehicleMode
from pymavlink import mavutil
import time

# Set up connection to the telemetry device
connection_string = '/dev/ttyUSB0' # Replace with the connection string for your telemetry device
connection = mavutil.mavlink_connection(connection_string, baud=57600)

# Set the system ID and component ID for each drone
master_sysid = 1
master_compid = 1
follower_sysid = 2
follower_compid = 1

# Connect to the master drone
master_vehicle = connect(connection_string, wait_ready=True, system=master_sysid, vehicle_class=None)

# Connect to the follower drone
follower_vehicle = connect(connection_string, wait_ready=True, system=follower_sysid, vehicle_class=None)

# Set the mode of each drone to GUIDED
master_vehicle.mode = VehicleMode("GUIDED")
follower_vehicle.mode = VehicleMode("GUIDED")

# Define a function to send a set position command to the master drone
def send_position(master_vehicle, lat, lon, alt):
    msg = master_vehicle.message_factory.set_position_target_global_int_encode(
        0,
        master_compid,
        0b0000111111111000, # Position type mask
        int(lat * 1e7),
        int(lon * 1e7),
        int(alt * 1000),
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
    )
    master_vehicle.send_mavlink(msg)
    master_vehicle.flush()

# Define a function to get the current position of the follower drone
def get_follower_position(follower_vehicle):
    lat = follower_vehicle.location.global_frame.lat
    lon = follower_vehicle.location.global_frame.lon
    alt = follower_vehicle.location.global_frame.alt
    return lat, lon, alt

# Set the target position for the master drone
target_lat = 47.6205 # Replace with the target latitude
target_lon = -122.3493 # Replace with the target longitude
target_alt = 50 # Replace with the target altitude

# Send the target position to the master drone
send_position(master_vehicle, target_lat, target_lon, target_alt)

# Loop until the follower drone reaches the target position
while True:
    follower_lat, follower_lon, follower_alt = get_follower_position(follower_vehicle)
    if abs(follower_lat - target_lat) < 0.0001 and abs(follower_lon - target_lon) < 0.0001 and abs(follower_alt - target_alt) < 1:
        break
    time.sleep(1)

# Disconnect from the vehicles
master_vehicle.close()
follower_vehicle.close()


integrate it in the below code

from pymavlink import mavutil
import time

# Define a list of waypoints as (latitude, longitude, altitude) tuples
waypoints = [
    (28.5861474, 77.3421320, 10),
    (28.5859040, 77.3420736, 10)
]

# Start a connection listening on a UDP port
the_connection = mavutil.mavlink_connection('/dev/ttyUSB0', baud=57600)


# Set mode to Guided
the_connection.mav.set_mode_send(
    the_connection.target_system,   # Target system ID
    mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,   # Mode flag
    4  # Guided mode
)
# Arm the drone
the_connection.mav.command_long_send(the_connection.target_system, the_connection.target_component, mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 0, 0, 0, 0, 0, 0)


# Take off the drone to  10 meters altitude
the_connection.mav.command_long_send(the_connection.target_system, the_connection.target_component, mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, 10)


def abort():
    """
    Waits for 7 seconds for the user to input 'abort'. If 'abort' is entered,
    sets the mode to RTL and disarms the motors. Otherwise, continues with the waypoint.
    """
    print("Type 'abort' to return to Launch and disarm motors.")
    start_time = time.monotonic()
    while time.monotonic() - start_time < 7:
        user_input = input("Time left: {} seconds\n".format(int(7 - (time.monotonic() - start_time))))


        if user_input.lower() == "abort":
            print("Returning to Launch and disarming motors...")

            # sets the mode to return to launch(RTL)
            the_connection.mav.set_mode_send(
                the_connection.target_system,   # Target system ID
                mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,   # Mode flag
                6  # RTL
            )
            # disarms the drone
            the_connection.mav.command_long_send(
                the_connection.target_system,   # Target system ID
                the_connection.target_component,   # Target component ID
                mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM,   # Command ID
                0,   # Confirmation
                0,   # Arm (0) or disarm (1)
                0,   # Unused parameters
                0,
                0,
                0,
                0,
                0
            )
            return True
    return False



# below commented code does not work in drone !
# mode = the_connection.mode_mapping()[the_connection.flightmode]

mode = 4
print(f"{mode}")


while mode == 4:
    time.sleep(10)
    # Loop through each waypoint and send MAVLink commands
    for i, wp in enumerate(waypoints):
        print("Going to waypoint", i+1)
        if abort():
            exit()
        else:
            the_connection.mav.send(mavutil.mavlink.MAVLink_set_position_target_global_int_message(
                10,  # Time boot_ms 
                the_connection.target_system,
                the_connection.target_component,
                mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
                int(0b110111111000),  # Use only lat, long, alt fields (position masking accuracy parameter)
                int(wp[0] * 10 ** 7),  # Latitude in degrees * 10^7
                int(wp[1] * 10 ** 7),  # Longitude in degrees * 10^7
                wp[2],  # Altitude in meters
                0,  # No velocity control
                0,  # No acceleration control
                0, 
                0, 
                0,
                0,
                0,
                0  # No yaw, yaw_rate, or type_mask control
            ))

            if abort():
                exit()
            
            time.sleep(5)

    # Set mode to Return to Launch
    the_connection.mav.set_mode_send(
        the_connection.target_system,   # Target system ID
        mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,   # Mode flag
        6  # RTL
    )

    # disarming the drone
    the_connection.mav.command_long_send(
        the_connection.target_system,   # Target system ID
        the_connection.target_component,   # Target component ID
        mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM,   # Command ID
        0,   
        0,   # Arm (0) or disarm (1)
        0,   
        0,
        0,
        0,
        0,
        0
    )
    

# Close the MAVLink connection
the_connection.close()