So I sort of managed to get the copter to do a circle in guided mode (on Gazebo / ROS SITL).
This is the code:
def fly_in_circles (centre, radius, loops = 1):
print ('Circling')
points = 24 # specified points in circle
bearing_step = 360/points
print ('centre: '+str(centre))
for loop in range (0, loops):
print("starting loop")
for point in range (1, points+1):
bearing = point*bearing_step
print("Bearing ok")
target_coordinates = radius.destination(point = centre, bearing = bearing) #geopy .destination: destination point using a starting point, bearing and a distance. This method works for non-abstract distances only.
print ('target_cooordinate: '+str(target_coordinates))
x = int((target_coordinates.latitude) *1e7)
y = int((target_coordinates.longitude) *1e7)
z = int((takeoff_height))
print('X = '+str(x)+' Y = ' +str(y)+' Z = ' +str(z))
go_msg = vehicle.message_factory.set_position_target_global_int_encode(
0,
0, 0,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
0b0000111111111000, # use position
x, y, z, #X, Y, Z Positions in WGS84 frame in 1e7 * meters
0,0,0,
0,0,0,
0,0)
vehicle.send_mavlink(go_msg)
print ("Heading to loc")
time.sleep (2)
My concern is that as the circle radius gets smaller the 2 second wait becomes more prominent, in fact below a certain distance between points you can see the drone “slowing down”. There is also the assumption that the message gets uploaded and executed, but I don’t know how to verify this between steps and whether there is a need to resend the same message in case for some reason one step does not get executed (?). I wish I could do without the 2 second wait and have it replaced with something more “robust”.
I am also conscious of the fact that the GPS is not as accurate in real life as it is in the simulation so the circle is likely to be more of a random-shaped polygon.
I’d like to know what the opinion of others is regarding my method here.