Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import sleep, time
- from pymavlink import mavutil
- import math
- # Create the connection
- connection_one = mavutil.mavlink_connection('udpin:127.0.0.1:14550', source_system=2)
- connection_two = mavutil.mavlink_connection('udpin:127.0.0.1:15550', source_system=3)
- connection_three = mavutil.mavlink_connection('udpin:127.0.0.1:16550', source_system=4)
- # Wait a heartbeat before sending commands
- connection_one.wait_heartbeat()
- connection_two.wait_heartbeat()
- connection_three.wait_heartbeat()
- start_time = time()
- def time_since_boot_ms():
- return (time() * 1000 - start_time * 1000)
- ang_vel = (2 * math.pi / 30) # rad / sec
- dt = 1 # sec
- start_angle = [0, math.pi / 2, math.pi]
- radius = [10000, 8000, 10000]
- def xy_on_circle(center, radius, theta_rad):
- x = radius * math.cos(theta_rad)
- y = radius * math.sin(theta_rad)
- x += center[0]
- y += center[1]
- return (x, y)
- def theta_now(start_angle, ang_vel):
- return start_angle + (ang_vel * time_since_boot_ms() / 1000)
- while True:
- theta = theta_now(start_angle[0], ang_vel) # radians
- center = (-353633600, 1491632350) # lat lon
- latlon = xy_on_circle(center, radius[0], theta)
- connection_one.mav.global_position_int_send(
- int(time_since_boot_ms()),
- int(latlon[0]),
- int(latlon[1]),
- int(684.9 * 1000), # mm alt amsl
- 100 * 1000, # relalt mm UP!
- 0, # vx
- 0, # vy
- 0, # vz
- int(math.degrees(theta + (math.pi / 2)) * 100) % (36000)# heading
- )
- theta = theta_now(start_angle[1], ang_vel) # radians
- center = (-353654700, 1491662400) # lat lon
- latlon = xy_on_circle(center, radius[1], theta)
- connection_two.mav.global_position_int_send(
- int(time_since_boot_ms()),
- int(latlon[0]),
- int(latlon[1]),
- int(684.9 * 1000), # mm alt amsl
- 100 * 1000, # relalt mm UP!
- 0, # vx
- 0, # vy
- 0, # vz
- int(math.degrees(theta + (math.pi / 2)) * 100) % (36000) # heading
- )
- theta = theta_now(start_angle[2], ang_vel) # radians
- center = (-353602800, 1491661300) # lat lon
- latlon = xy_on_circle(center, radius[2], theta)
- connection_three.mav.global_position_int_send(
- int(time_since_boot_ms()),
- int(latlon[0]),
- int(latlon[1]),
- int(684.9 * 1000), # mm alt amsl
- 100 * 1000, # relalt mm UP!
- 0, # vx
- 0, # vy
- 0, # vz
- int(math.degrees(theta + (math.pi / 2)) * 100) % (36000)# heading
- )
- sleep(dt)
Add Comment
Please, Sign In to add comment