Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior of MoveToPositionAsync #1643,how to solve it? #1677

Closed
kalading2 opened this issue Jan 4, 2019 · 22 comments · Fixed by #3545
Closed

Incorrect behavior of MoveToPositionAsync #1643,how to solve it? #1677

kalading2 opened this issue Jan 4, 2019 · 22 comments · Fixed by #3545
Labels

Comments

@kalading2
Copy link

kalading2 commented Jan 4, 2019

The arrival of the target will vary considerably with speed.
The UE4 coordinate is converted to the ned coordinate using tolocalned, but the arrival of the target point will vary greatly with the speed.I don't know why?


image

@lovettchris
Copy link
Member

Might help to post your settings.json file so we know what type of drone you are flying and how it was configured. When I try the PX4 drone with this script:

for i in range(100):
    time.sleep(3)      
    pos = client.simGetGroundTruthKinematics().position
    print("{:.3f},{:.3f},{:.3f}".format(pos.x_val, pos.y_val, pos.z_val))
    client.enableApiControl(True)
    client.moveToPositionAsync(-5,0,z,1).join()
    pos = client.simGetGroundTruthKinematics().position
    print("{:.3f},{:.3f},{:.3f}".format(pos.x_val, pos.y_val, pos.z_val))
    time.sleep(3)
    pos = client.simGetGroundTruthKinematics().position
    print("{:.3f},{:.3f},{:.3f}".format(pos.x_val, pos.y_val, pos.z_val))
    client.enableApiControl(True)
    client.moveToPositionAsync(5,0,z,1).join()
    pos = client.simGetGroundTruthKinematics().position
    print("{:.3f},{:.3f},{:.3f}".format(pos.x_val, pos.y_val, pos.z_val))

it seems to fly ok, here's the position reported:

image

@majouda7
Copy link

majouda7 commented Jan 8, 2019

I have experienced exactly the same issue (I posted it in Incorrect behavior of MoveToPositionAsync #1643).
My setting.json file looks like this:

{
"SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md",
"SettingsVersion": 1.2,
"SimMode": "Multirotor",
"Vehicles": {
"SimpleFlight": {
"VehicleType": "SimpleFlight",
"AutoCreate": true,
"Sensors": {
"LidarSensor1": {
"SensorType": 6,
"Enabled": true,
"Range": 100,
"NumberOfChannels": 2,
"RotationsPerSecond": 10,
"PointsPerSecond": 100000,
"X": 0,
"Y": 0,
"Z": -0.8,
"Roll": 0,
"Pitch": 0,
"Yaw": 0,
"VerticalFOVUpper": 0,
"VerticalFOVLower": 0,
"HorizontalFOVStart": 0,
"HorizontalFOVEnd": 359,
"DrawDebugPoints": true,
"DataFrame": "SensorLocalFrame"
}
}
}
}
}

@kalading2
Copy link
Author

kalading2 commented Jan 9, 2019

@lovettchris My setting.json is the default mode,Is it my setup problem?The UE4 coordinate is converted to the Ned coordinate using ToLocalNed.
{
"SettingsVersion": 1.2,
"SimMode": "Multirotor",
"Vehicles": {
"PX4": {
"VehicleType": "PX4Multirotor",
"SerialPort": "*"
}
}
}

Is there a problem with my flight mode? I found that when my pixhawk switched to position mode, it actually switched to Altitude mode. Why can't I switch to position mode?

@saihv
Copy link
Contributor

saihv commented Jan 15, 2019

I think I have the same problem. I am trying to control multiple SimpleFlight drones with the Python API, and I am encountering errors in how MoveToPositionAsync actually moves the drones. For instance, this is a set of commands I gave the drone:

f1 = client.moveToPositionAsync(5, 0, -8, 3, vehicle_name="Drone1")
f1 = client.moveToPositionAsync(-5, 0, -8, 3, vehicle_name="Drone1")
f1 = client.moveToPositionAsync(-5, -10, -8, 3, vehicle_name="Drone1")
f1 = client.moveToPositionAsync(5, -10, -8, 3, vehicle_name="Drone1")
f1 = client.moveToPositionAsync(5, 0, -8, 3, vehicle_name="Drone1")

My world is properly aligned, so this should make the drone fly in a nicely aligned square. Instead, this is what the drone does (plotted from the airsim_rec log):

image

Unless I am doing/understanding something wrong, this seems to be a pretty major issue.

@jasonhbartlett
Copy link

Here's why my flight looks like when running that python script:
image
Could be a really long signature.
But in all seriousness, this is using PX4 SITL and the PX4 failsafe keeps kicking in. So I've got other issues. Specifically Issue #1685 :)

@lovettchris
Copy link
Member

which script? saihv's ? If so I would imagine you would need to add some .join() calls to each of his moveToPositionAsync calls.

@jasonhbartlett
Copy link

@lovettchris No, sir. The script you posted. I cannot get 2 moveToPositionAsync().Join() calls to ever work. Certainly not 3 or more. Even while putting extra client.enableApiControl(True) all over the place. No dice, I lose control to the failsafe. I'm guessing the problem is with the PX4 params. Could you or someone provide, or could ya'll add to the AirSim repo an generic PX4 params test file that could be used by a new user to help us verify our PX4 sitl setup? params that are optimized to work with all of the test Api's like HelloDrone, etc? I posted my param here: show params

@jasonhbartlett
Copy link

jasonhbartlett commented Jan 16, 2019

@lovettchris
By the way, this is what that same script looks like with SimpleFlight. It's actually damn beautiful. I need to get these same (or at least very similar) results with my PX4 sitl setup.
image
image
Here is the script: hello_drone3.py

@majouda7
Copy link

majouda7 commented Jan 16, 2019

@jasonhbartlett Did you check if the position of the drone in unreal is actually as requested? In my case, using SimpleFlight, the drone overshoots the requested position as described in #1643. This behavior varies considerably with speed. You probably won't see the problem with a low velocity say 1m/s. The problem becomes more serious starting from 5 m/s.

using @jasonhbartlett 's script hello_drone3 with 1m/s
initial postion : 0.000,0.000,-1.322
move : -5.033,1.007,-2.968
sleep 3s: -5.618,1.125,-2.997
move : 5.017,2.127,-3.018
move : -5.028,3.130,-3.018
sleep 3s : -5.643,3.185,-2.999

with 5m/s
initial position: 0.000,0.000,-1.323
move : -5.235,1.047,-2.656
sleep 3s: -9.028,1.827,-3.030
move 5.203,2.832,-2.910
move -5.147,3.834,-2.921
sleep 3s -9.740,4.051,-3.077
move 5.177,5.063,-2.919
move -5.153,6.066,-2.921
sleep 3s -9.751,6.293,-3.076

@jasonhbartlett
Copy link

Hi @majouda7
Yep, I'm getting the same results:
Running in Unity 5m/s :
image

Running in Unreal 5m/s : (Although it seemed to correct itself over time in Unreal)
image

I can chart the path in Unity.
image
I don't know how to show the trail to chart the path in Unreal. :(

@majouda7
Copy link

@jasonhbartlett, in my case the drone doesn't seem to correct itself in unreal over time. This what I get if I put a sleep after each move. It is obvious that the drone is drifting over x and y axes.
unreal_output

@lovettchris
Copy link
Member

@jasonhbartlett regarding parameters, I did put some info here moveOnPath demo. Saving all parameters would be a maintenance problem because px4 might add or change other unrelated parameters. But the ones I usually use are:

param set SYS_MC_EST_GROUP 2
param set MPC_XY_VEL_MAX 20
param set MPC_XY_CRUISE 5
param set COM_OBL_ACT 1
param set COM_OBL_RC_ACT 5
param set NAV_RCL_ACT 0
param set NAV_DLL_ACT 0

There's also some in px4_sitl. I have found a bug in airsim to do with magnetic declination, so until that is fixed I recommend flying with latitude 0.

I put my full set of params here.

Let's also rule out C++ versus python, can you run this python test script and paste the results (as text) ? Thanks.

import sys
import time

import setup_path 
import airsim

def print_position(client):    
    state = client.getMultirotorState()
    gps = state.gps_location
    print("gps location lat={}, lon={}, alt={}".format(gps.latitude, gps.longitude, gps.altitude))
    pos = state.kinematics_estimated.position
    print("local position x={}, y={}, z={}".format(pos.x_val, pos.y_val, pos.z_val))

client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

print_position(client)

landed = client.getMultirotorState().landed_state
if landed == airsim.LandedState.Landed:
    print("taking off...")
    client.takeoffAsync().join()
else:
    client.hoverAsync().join()


if client.getMultirotorState().landed_state == airsim.LandedState.Landed:
    print("take off failed, please check message log")
    sys.exit(1)


# AirSim uses NED coordinates so negative axis is up.
# z of -7 is 7 meters above the original launch point.
z = -7

# make sure we are at the start location (previous flight might have missed the landing spot by a bit.)
client.moveToPositionAsync(0,0,z,1).join()

print("flying path...")

# this method is async, but we are calling .join() so the script waits for path to complete.
for i in range(100):
    time.sleep(3)      
    pos = client.simGetGroundTruthKinematics().position
    print("{:.3f},{:.3f},{:.3f}".format(pos.x_val, pos.y_val, pos.z_val))
    client.enableApiControl(True)
    client.moveToPositionAsync(-5,0,z,1).join()
    pos = client.simGetGroundTruthKinematics().position
    print("{:.3f},{:.3f},{:.3f}".format(pos.x_val, pos.y_val, pos.z_val))
    time.sleep(3)
    pos = client.simGetGroundTruthKinematics().position
    print("{:.3f},{:.3f},{:.3f}".format(pos.x_val, pos.y_val, pos.z_val))
    client.enableApiControl(True)
    client.moveToPositionAsync(5,0,z,1).join()
    pos = client.simGetGroundTruthKinematics().position
    print("{:.3f},{:.3f},{:.3f}".format(pos.x_val, pos.y_val, pos.z_val))

client.moveToPositionAsync(0,0,-10,1).join()
print("landing")
client.landAsync().join()
print("disarming drone")
client.armDisarm(False)
client.enableApiControl(False)
print("done!")

print_position(client)

With this test script I am seeing some sort of AirSim bug where sometimes the moveToPositionAsync call terminates prematurely, possibly thinking it has already reached the intended destination, when it clearly has not. So my graph below shows this problem - it should be a sharp tooth diagram back and forth like you see it do a few times, but most of the time it gets stuck on one end or the other for a while:

image

So this will need some airsim debugging... But I did not see any "Accel #0 fail" or "Gyro #0 fail" errors. I do see lots of "Failsafe enabled:" warnings, which you can safely ignore.

@majouda7
Copy link

@lovettchris, Do you have any insights on the variation (offset) of the drone's arriving position with respect to its velocity ? Is there any plans to fix that bug?

@jasonhbartlett
Copy link

@lovettchris
I'm almost certain I'm seeing that bug you described where the moveToPositionAsync call terminates prematurely. Indeed, (after making sure the default state was changed to "Hold" for all failsafe triggers so that the drone doesn't try to "Land" or "RTH") I am seeing that exact pattern. Also getting lots of "Failsafe enabled:" warning. The drone flies back and forth but sometimes get stuck on one side or the other for a bit. After awhile, one of the moveToPositionAsync calls must get through and it is able to move across to the other side again.
Here are the results of running your python script:

Connected!
Client Ver:1 (Min Req: 1), Server Ver:1 (Min Req: 1)

gps location lat=47.6414680480957, lon=-122.1401596069336, alt=120.14900207519531
local position x=0.0, y=0.0, z=0.0
taking off...
flying path...
-0.056,-0.006,-4.939
-0.055,-0.007,-4.938
-0.226,-0.066,-5.019
-0.212,-0.073,-5.022
0.076,0.028,-5.088
-5.208,-0.109,-5.065
-4.943,-0.588,-5.054
5.077,0.023,-5.064
4.994,0.076,-5.136
-5.027,-0.068,-5.076
-4.965,-0.145,-5.103
5.090,0.064,-5.077
4.982,0.108,-5.141
1.654,0.020,-5.087
1.318,-0.527,-5.063
5.254,0.033,-5.064
5.084,0.562,-5.045
-5.044,-0.052,-5.056
-4.962,-0.093,-5.045
5.111,0.068,-5.079
4.972,0.113,-5.048
-1.006,-0.228,-5.101
-1.241,-0.614,-5.105
5.139,0.373,-5.074
4.880,0.552,-5.084
-5.121,-0.044,-5.044
-4.990,-0.094,-5.066
5.112,0.057,-5.047
5.003,0.111,-5.047
5.001,0.107,-5.047
4.844,-0.170,-5.055
5.064,-0.299,-5.101
5.066,-0.250,-5.115
5.065,-0.248,-5.116
4.847,-0.283,-5.104
4.947,-0.348,-5.075
4.989,-0.318,-5.040
4.989,-0.316,-5.040
4.773,-0.333,-5.024
4.900,-0.407,-5.081
4.900,-0.357,-5.079
-5.084,-0.113,-5.075
-4.917,-0.161,-5.110
5.120,0.050,-5.070
4.983,0.107,-5.102
0.731,-0.048,-5.016
0.413,-0.572,-5.041
5.207,0.177,-5.077
4.976,0.622,-5.029
-5.056,-0.059,-5.053
-4.965,-0.111,-5.054
5.092,0.065,-5.073
4.991,0.126,-5.104
-5.122,-0.036,-5.031
-5.005,-0.087,-5.099
5.114,0.050,-5.009
4.986,0.111,-5.025
-5.092,-0.052,-5.097
-4.964,-0.107,-5.078
-4.959,-0.093,-5.074
-4.727,0.180,-5.065
-4.963,0.309,-5.058
-4.945,0.245,-5.030
-4.944,0.244,-5.030
-4.733,0.264,-5.040
-4.848,0.324,-5.061
-4.880,0.289,-5.088
-4.879,0.288,-5.088
-4.692,0.323,-5.042
-4.742,0.350,-5.030
-4.796,0.330,-5.025
-4.795,0.328,-5.025
-4.625,0.364,-5.059
-4.723,0.425,-5.075
-4.771,0.403,-5.070
-4.770,0.400,-5.072
-4.565,0.411,-5.036
-5.087,0.188,-5.064
-5.067,0.052,-5.032
5.093,0.080,-5.032
4.941,0.128,-5.048
-5.088,-0.052,-5.037
-4.976,-0.136,-5.047
5.081,0.057,-5.086
4.988,0.132,-5.049
4.986,0.128,-5.049
4.801,-0.137,-5.046
5.006,-0.270,-5.044
4.994,-0.213,-5.074
4.991,-0.211,-5.077
4.759,-0.245,-5.073
4.865,-0.301,-5.072
4.904,-0.264,-5.073
4.903,-0.263,-5.072
4.720,-0.293,-5.060
4.807,-0.337,-5.050
4.862,-0.300,-5.030
4.861,-0.299,-5.028
4.684,-0.310,-5.045
4.829,-0.381,-5.027
4.852,-0.340,-5.031
4.851,-0.340,-5.031
4.635,-0.376,-5.040
4.754,-0.435,-5.053
4.738,-0.396,-5.064
-5.066,-0.131,-5.122
-4.931,-0.216,-5.129
-4.928,-0.208,-5.129
-4.741,0.068,-5.084
-4.964,0.192,-5.054
-4.978,0.155,-5.091
5.066,0.096,-5.092
4.927,0.166,-5.091
-5.079,-0.052,-5.066
-4.963,-0.121,-5.064
4.540,0.191,-5.047
6.054,0.196,-5.082
-4.659,-0.187,-5.118
-3.803,1.160,-5.171
-3.799,1.164,-5.177
-3.458,1.124,-5.229
-5.092,-0.006,-5.125
-5.790,-0.949,-4.998
-5.772,-0.937,-4.995
-4.846,-0.179,-4.950
-4.847,-0.170,-4.951
-4.870,0.213,-5.017
-4.875,0.208,-5.018
-4.758,-0.099,-5.067
-4.776,-0.131,-5.080
-4.695,-0.168,-5.126
-4.693,-0.165,-5.126
-4.349,0.038,-5.106
-4.352,0.041,-5.104
-4.698,0.137,-5.078
-4.697,0.133,-5.079
-4.305,0.000,-5.036
-4.302,0.001,-5.035
-4.428,0.030,-5.066
5.155,0.135,-5.031
5.399,0.341,-5.103
-5.122,-0.260,-5.065
-5.580,-0.411,-5.043
5.141,0.385,-5.091
5.797,0.491,-5.154
-5.109,-0.395,-5.086
-5.680,-0.449,-5.005
5.273,0.443,-5.217
5.891,0.445,-5.223
5.812,0.425,-5.215
4.455,0.012,-5.149
4.443,-0.001,-5.148
4.240,-0.220,-5.123
4.249,-0.218,-5.122
4.353,-0.041,-5.080
5.068,0.113,-5.050
5.381,0.277,-5.054
5.378,0.276,-5.055
4.985,0.186,-5.040
4.983,0.184,-5.038
4.984,0.087,-5.054
4.987,0.088,-5.055
4.840,0.129,-5.115
4.843,0.130,-5.115
4.859,0.176,-5.172
4.859,0.176,-5.174
4.607,0.142,-5.137
4.608,0.140,-5.135
4.674,0.140,-5.076
4.676,0.141,-5.075
4.519,0.149,-5.014
4.525,0.147,-5.012
4.636,0.158,-4.981
4.638,0.159,-4.981
4.497,0.163,-5.011
4.773,0.007,-5.054
4.818,-0.026,-5.122
4.766,-0.019,-5.128
4.153,-0.015,-5.176
4.151,-0.017,-5.176
4.323,-0.077,-5.126
4.325,-0.075,-5.125
4.167,-0.058,-5.102
4.950,-0.082,-5.042
5.250,0.044,-5.066
5.249,0.045,-5.067
4.985,0.074,-5.089
4.983,0.073,-5.089
4.879,-0.019,-5.073
4.879,-0.020,-5.072
4.665,-0.096,-5.080
4.689,-0.100,-5.079
4.803,-0.087,-5.069
4.805,-0.085,-5.070
4.610,-0.017,-5.067
4.611,-0.018,-5.067
4.686,-0.058,-5.080
-5.075,-0.159,-5.024
-5.490,-0.393,-5.019
5.223,0.322,-5.071
5.663,0.444,-5.156
-5.213,-0.389,-5.045
-5.606,-0.520,-5.000
5.115,0.418,-5.154
5.820,0.453,-5.120
5.789,0.444,-5.119
4.658,0.074,-5.088
4.652,0.067,-5.089
4.361,-0.224,-5.061
4.370,-0.223,-5.061
4.546,-0.061,-5.091
5.004,0.407,-5.098
4.942,0.420,-5.055
4.941,0.419,-5.055
4.676,0.326,-5.073
4.705,0.316,-5.074
4.889,0.314,-5.081
4.890,0.315,-5.081
4.748,0.330,-5.118
4.747,0.327,-5.118
4.710,0.303,-5.074
4.710,0.303,-5.073
4.567,0.317,-5.102
4.571,0.317,-5.103
4.832,0.178,-5.114
4.832,0.179,-5.113
4.563,0.235,-5.075
4.564,0.236,-5.074
4.601,0.249,-5.086
4.603,0.249,-5.086
4.456,0.215,-5.066
4.458,0.214,-5.066
4.798,0.103,-5.105
4.797,0.105,-5.105
4.548,0.128,-5.132
4.547,0.127,-5.132
4.486,0.123,-5.123
4.488,0.126,-5.123
4.188,0.149,-5.122
4.194,0.144,-5.121
4.564,0.073,-5.094
-5.149,-0.226,-5.071
-5.633,-0.544,-5.044
-5.619,-0.541,-5.044
-4.640,-0.146,-5.065
-4.624,-0.108,-5.071
-4.461,0.188,-5.062
-4.469,0.187,-5.063
-4.551,0.027,-5.076
-4.758,-0.186,-5.112
-4.808,-0.250,-5.113
-4.806,-0.248,-5.111
-4.511,-0.123,-5.099
-4.512,-0.116,-5.098
-4.532,-0.040,-5.088
-4.533,-0.040,-5.087
-4.346,-0.064,-5.100
-4.782,0.008,-5.093
-4.983,-0.011,-5.064
-4.985,-0.012,-5.061
-4.678,0.001,-5.010
-4.677,0.002,-5.010
-4.663,0.012,-5.002
-4.666,0.012,-5.002
-4.531,0.025,-5.029
-4.532,0.025,-5.029
-4.547,0.038,-5.144
5.141,0.173,-5.065
5.704,0.461,-5.034
-5.283,-0.424,-5.121
-5.727,-0.558,-5.173
5.195,0.430,-5.076
5.781,0.501,-5.052
-5.191,-0.399,-5.104
-5.787,-0.447,-5.125
5.047,0.302,-5.129
5.463,0.357,-5.108
5.454,0.354,-5.107
4.705,0.063,-5.106
4.703,0.056,-5.106
4.682,-0.071,-5.037
4.689,-0.069,-5.036
4.747,0.102,-5.059
4.749,0.104,-5.060
4.828,0.216,-5.076
4.828,0.216,-5.077
4.547,0.134,-5.126
4.548,0.130,-5.126
4.579,0.028,-5.116
4.581,0.029,-5.116
4.421,0.067,-5.087
4.422,0.068,-5.087
4.698,0.114,-5.014
-5.009,-0.105,-5.129
-5.407,-0.341,-5.148
5.259,0.352,-5.087
5.720,0.464,-5.091
-5.155,-0.441,-5.132
-5.925,-0.542,-5.182
5.280,0.395,-5.106
5.868,0.513,-5.126
-5.114,-0.364,-5.031
-5.520,-0.488,-5.060
5.084,0.265,-5.129
5.277,0.255,-5.142
-5.074,-0.332,-5.116
-5.595,-0.245,-5.129
5.095,0.287,-5.091
5.637,0.378,-5.094
5.517,0.355,-5.089
4.324,0.068,-5.114
4.320,0.060,-5.113
4.250,-0.143,-5.119
4.260,-0.141,-5.118
4.439,0.027,-5.100
4.449,0.032,-5.099
4.971,0.223,-5.026
4.967,0.224,-5.025
4.595,0.227,-5.053
4.591,0.224,-5.054
4.494,0.097,-5.094
-5.048,-0.115,-5.105
-5.604,-0.411,-5.091
5.224,0.378,-5.117
5.576,0.494,-5.128
5.558,0.488,-5.129
4.663,0.049,-5.110
4.662,0.034,-5.110
4.505,-0.168,-5.097
4.512,-0.163,-5.098
4.492,-0.014,-5.092
4.941,0.236,-5.094
4.984,0.351,-5.084
4.983,0.351,-5.084
4.716,0.282,-5.084
4.719,0.279,-5.085
4.791,0.192,-5.066
4.795,0.193,-5.067
4.450,0.186,-5.041
4.676,0.049,-5.026
4.912,0.035,-5.061
4.915,0.036,-5.061
4.661,0.103,-5.048
4.657,0.101,-5.047
4.503,0.012,-5.064
4.504,0.010,-5.064
4.321,-0.006,-5.078
5.030,-0.023,-5.081
5.191,0.067,-5.109
-5.078,-0.198,-5.051
-5.524,-0.410,-5.006
5.141,0.383,-5.142
5.762,0.470,-5.133
-5.217,-0.415,-5.151
-5.864,-0.441,-5.143
5.236,0.308,-5.076
5.474,0.361,-5.081
-5.026,-0.221,-5.135
-5.340,-0.223,-5.095
5.286,0.295,-5.087
5.767,0.437,-5.101
-5.170,-0.370,-5.139
-5.746,-0.539,-5.084
-5.626,-0.508,-5.071
-4.247,-0.074,-5.067
-4.242,-0.067,-5.068
-4.074,0.203,-5.099
-4.084,0.201,-5.100
-4.252,0.028,-5.114
-4.989,-0.061,-5.101
-5.329,-0.207,-5.069
-5.326,-0.206,-5.068
-5.004,-0.115,-4.995
-5.003,-0.113,-4.995
-4.901,0.003,-5.046
-4.901,0.003,-5.046
-4.732,-0.001,-5.107
-4.750,-0.004,-5.108
-4.906,-0.052,-5.116
-4.908,-0.053,-5.116
-4.751,-0.061,-5.119
-4.750,-0.060,-5.119
-4.681,-0.017,-5.087
-4.681,-0.018,-5.087
-4.474,-0.021,-5.036
-4.493,-0.015,-5.036
-4.631,0.019,-5.030
-4.633,0.019,-5.031
-4.431,0.016,-5.056
-4.746,0.058,-5.073
-4.958,0.013,-5.121
-4.959,0.012,-5.120
-4.639,-0.006,-5.088
-4.637,-0.004,-5.088
-4.567,0.100,-5.064
-4.571,0.101,-5.064
-4.508,0.076,-5.057
-4.707,0.050,-5.050
-4.757,0.007,-5.002
5.105,0.189,-5.136
landing
disarming drone
done!
gps location lat=47.641510009765625, lon=-122.14017486572266, alt=119.40699768066406
local position x=0.0, y=0.0, z=0.0
Press any key to continue . . .

And here's a picture showing the complete flight path. (I'll have to start publishing these as abstract art :)
image
BTW - Although indeed the starting local position was 0, 0, 0, as you can see the ending position was not, therefore I don't know why the final check of local position reported 0, 0, 0. The LAT/LON is probably accurate.

Please let me know what else I can do to help test things out. Hopefully this bug is traceable. :) Thanks sir!

@lovettchris
Copy link
Member

Ok, great, so we have a repro for the bug and we should make this a high priority item. I also see the final print_position 0,0,0 but which is another bug, not sure what's happening there, perhaps changing the armed state or the enableApiControl state is impacting the position printed (which it shouldn't)...

@whxru
Copy link

whxru commented Mar 6, 2019

I met the same problem and unfortunately I met another problem #1292 too. Finally I found that I could use moveByVelocityAsync(vx, vy, vz, duration) to set velocity to make the drone move and use moveByVelocityAsync(0, 0, 0, duration) to make it stop after a specific time . In this way I could custom a new moveToPosition method like:

def moveToPosition(x, y, z, v):
    currentPos = uav.getMultirotorState().kinematics_estimated.position
    t = ((currentPos.x_val - x)**2 + (currentPos.y_val - y)**2 + (currentPos.z_val - z)**2)**0.5 / v
    delta_x = x - currentPos.x_val
    delta_y = y - currentPos.y_val
    delta_z = z - currentPos.z_val
    vx = delta_x / t
    vy = delta_y / t
    vz = delta_z / t
    uav.moveByVelocityAsync(vx, vy, vz, t)
    time.sleep(t)
    uav.moveByVelocityAsync(0, 0, 0, 5)
    uav.hoverAsync().join()

This method is able to make the drone stop at the given position accurately even with a fast speed (e.g. 10m/s in my simple test). So this might be a temporal solution before the bug has been fixed.

@seheevic
Copy link
Contributor

seheevic commented Nov 14, 2019

I've encountered this problem and investigated a little inside AirSim source code.
There are 3 problems I can state here.

  1. MultirotorApiBase::moveOnPath

    setNextPathPosition(path3d, path_segs, cur_path_loc, lookahead + lookahead_error, next_path_loc);
    float overshoot = 0;
    float goal_dist = 0;
    //until we are at the end of the path (last seg is always zero size)
    while (!waiter.isTimeout() && (next_path_loc.seg_index < path_segs.size()-1 || goal_dist > 0)
    ) { //current position is approximately at the last end point

    When velocity argument which determines lookahead (default behavior of adaptive_lookahead) is too high compared to the path length, next_path_loc will be set to the very last path segment, so the code inside loop is never executed since initial goal_dist was set to zero. It seems that we need more robust 'termination criteria'.

  2. Physics frequency / Command frequency / Rendering frequency when using Multirotor
    [Default physics frequency: 333 Hz (3ms)]

    long long physics_loop_period_ = 3000000LL; //3ms

    [Default command frequency: 50 Hz (20ms)]
    virtual float getCommandPeriod() const override
    {
    return 1.0f / 50; //50hz
    }

    [Rendering frequency: not fixed, but let's say it's about 30 Hz (a little low frequency)]
    AirSim(SimpleFlight) updates estimated kinematics information (which will be used in the command loop) from high frequency physics results on main thread every tick, so the update frequency is as same as rendering frequency. But as you can see from source code, when the command frequency is higher than the rendering frequency, I think it would be possible that control command is processed twice within single main thread tick. That can also cause goal_dist to be zero (no movement from measurement), and the command loop will be terminated unexpectedly.

  3. detectTakingOff which affects control(goal) time out detection of OffboardApi
    This seems to be fixed or at least improved.

I'm not sure that this is the reason of the discussion above.
But it seems to be somewhat related to them.

@xxEoD2242
Copy link

xxEoD2242 commented Mar 28, 2020

So, this may not solve anyone's problems, but I had a lot of issues in using the join calls for calling absolute positioning and what I have determined is that when using loops inside of Python to do that type of async behavior with the join() calls, either Unreal, Airsim or RPC freaks out about the asynchronous method that freezes the call. My thought would be that it has something to do with freezing the currently running process, when it is supposed to be communicating with the RPC server. (I had the same exact issues using an interrupt-based GPS module and calling sleep in the process loop. Took me 6 months to figure out why it wasn't working!)

To solve my issues, as I was writing a simple chase-follow script, I did the following. This isn't refactored in any way but I haven't had any issues with positioning since.

for i, waypoint in enumerate(route.primary_route):
    try:
        next_point = route.primary_route[i + 1]
    except Exception as error:
        print('Final point!')
        next_point = False
    f1 = client.moveToPositionAsync(waypoint[0], waypoint[1], waypoint[2], waypoint[3], vehicle_name=veh_1_name)
    if (i % 10 == 0):
        f2 = client.moveToPositionAsync(waypoint[0], waypoint[1], waypoint[2] - 0.1, waypoint[3] + 1, vehicle_name=veh_2_name)
    else:
        f2 = client.moveToPositionAsync(waypoint[0], waypoint[1], waypoint[2], waypoint[3], vehicle_name=veh_2_name)

    if (i % 5 == 0):
        print(waypoint)

    # Instead of join, pull state and get GPS data to confirm where the drone is at
    # When the drone is at a sufficiently close location, feed the next point in the async way
    kinematics = client.simGetGroundTruthKinematics(vehicle_name=veh_1_name)
    if next_point:
        # For the first point, the drones need to fly to a normalized location
        if i == 0:
            f2.join()
        else:
            while (abs(kinematics.position.x_val - abs(next_point[0])) - 3) > CONFIRMATION_DISTANCE and (abs(kinematics.position.y_val - abs(next_point[1])) - 3) > CONFIRMATION_DISTANCE and abs(abs(kinematics.position.z_val) - abs(next_point[2])) > CONFIRMATION_DISTANCE:
                kinematics = client.simGetGroundTruthKinematics(vehicle_name=veh_1_name)
                print('\n')
                print(kinematics.position.x_val)
                print(kinematics.position.y_val)
                print(kinematics.position.z_val)
                print((abs(kinematics.position.x_val - abs(next_point[0])) - 3))
                print((abs(kinematics.position.y_val - abs(next_point[0])) - 3))
                print(abs(abs(kinematics.position.z_val) - abs(next_point[2])))
                print('\n')
                time.sleep(0.2)

I have gotten this to work with sufficiently large enough distance between points. I currently break up the route into 50 points and then just do this. The route object you are seeing is something I build before starting the drone's movement.

I'm going to be writing a GPS based version of this that can go between x,y,z and GPS coordinates to mimic some of what a PixHawk does when interpreting points.

Let me know if there are any improvements to this.

@cloudlakecho
Copy link

@xxEoD2242, Thanks for the snippet.
I wonder how to choose the sleeping time. Is it empirical depending on position distance?

@cloudlakecho
Copy link

@saihv, would you explain how to plot the vehicle trajectory using airsim_rec log? I wonder your coordinate is rotated. Have you tried to see your drone GPS location as well?

@cloudlakecho
Copy link

@lovettchris, thanks for posting nice graph of drone location. I try to plot, but I couldn't find how to get the position continuously. Please, share the function of recording drone location, thanks.

@lovettchris
Copy link
Member

I was using PX4 drone with a mavlink logger, probably connected to the LogViewer app included in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet