microsoft / AirSim

Open source simulator for autonomous vehicles built on Unreal Engine / Unity, from Microsoft AI & Research
https://microsoft.github.io/AirSim/
Other
16.29k stars 4.53k forks source link

getMultirotorState linear velocity not matching gradient(position) #2914

Open p3jawors opened 4 years ago

p3jawors commented 4 years ago

python==3.5.2 airsim==1.2.7 unreal==4.24.1-0+++UE4+Release-4.24 OS: Ubuntu 16.04

I am currently trying to implement my own PD controller for the multirotor and have been having issues with the gain tuning. Comparing my planned target positions and velocities I would be overshooting position while undershooting the target velocity, which didn't make any sense. If I take the gradient of my path planner's position with my set dt I get my expected velocity profile, so the issue is not with the path planner. This led me to look into the derivative of the position feedback.

For a little background, I am controlling the drone's motor's PWMs in synchronous mode with... moveByMotorPWMsAsync(pwm[0], pwm[1], pwm[2], pwm[3], dt).join()

I get feedback with...

state = client.getMultirotorState().kinematics_estimated
pos = state.position.to_numpy_array()
lin_vel = state.linear_velocity.to_numpy_array()

If I plot my planned target positions and velocities against the drone feedback for a run, then compare those feedback velocities with np.gradient(pos, dt) (pos recorded for an entire flight) I get much higher velocities (very close to x2 as big) with the gradient, compared to the feedback. This make much more sense with what I am observing between position and velocity of my drone and path planner. I am also setting a spherical object's state with this path planner and can confirm that it goes from start to target, and that the drone is moving faster than it.

I have attached a plot showing:

Is there something I could be missing or some mistake I am making in getting my velocity feedback? It might just be a coincidence, but if I scale the feedback velocity by 2 is almost perfectly matches the gradient of position, except for dg which is different.

I thought this could be an issue with commands being run asynchronously, but with how I understand the docs I believe I am correctly setting my pwm commands to run in synchronous mode by passing in dt for duration and appending the .join() command.

p3jawors commented 4 years ago

I just wanted to update my figure, as I have sorted out my issue with dg being different than the other velocity signals, and to provide a tldr for the above...

Why do the linear and angular velocity feedback signals not match the rate of change of the position and orientation signals? green: airsim feedback yellow: np.gradient(position) for linear velocity and np.gradient(euler_angles) for angular velocity red: airsim feedback * 2

Figure_1

The velocity feedback * 2 is very close to the derivatives of position and orientation, however, that could just be coincidence. Also, I can confirm I am using the right timestep size for my differentiation.

p3jawors commented 3 years ago

Is there any update on this? I'm still getting innacurate velocity feedback when compared to the derivative of position feedback. Any insight to this problem is greatly appreciated.

p3jawors commented 3 years ago

I came across this problem again when I tried changing my simulator timestep from 10ms to 1ms. It appears that Airsim is not accounting for timestep when providing velocity feedback. I've attached a plot showing the linear and angular velocity feedback from airsim (along rows) plotted against different timesteps (along columns). There is a clear increase in the scale of the feedback as the timestep increases. The dotted lines label grad are the np.gradient(0th_state, dt), so for the dx row, it will be the gradient of x_position. state_vs_expected The difference between timesteps is a bit clearer when plotted on a single subplot for differing timesteps. state_vs_dt2 For the time being I've used the ratio of the actual/expected and interpolated a linear function to set a scaling factor, given the timestep. Any insights on this are greatly appreciated, as I can not find anything relevant in the documentation or previous issues.

p3jawors commented 3 years ago

Is this a dead issue as I haven't gotten a single response in half a year? Unless I'm mistaken, the velocity feedback is quite wrong depending on sim timesteps. I have an empircal solution for now that scales the velocity given the timestep, but this is far from an ideal solution.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity from the community in the last year. It will be closed if no further activity occurs within 20 days.

p3jawors commented 2 years ago

This is still an issue on my end, has there been any word on taking a look at, or trying to recreate these results?

p3jawors commented 1 year ago

:cry: