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

Add Wind simulation #2867

Merged
merged 4 commits into from
Sep 2, 2020
Merged

Add Wind simulation #2867

merged 4 commits into from
Sep 2, 2020

Conversation

rajat2004
Copy link
Contributor

@rajat2004 rajat2004 commented Jul 20, 2020

Adds force calculation due to Wind. Based on #284

TODO:

Settings:

{
    "SettingsVersion": 1.2,
    "SimMode": "Multirotor",
    "Wind": {
        "X": 0, "Y": 30, "Z": 0
    }
}

API:

wind = airsim.Vector3r(0, 25, 0)
client.simSetWind(wind)

Video: https://drive.google.com/file/d/1Cl1QOY_pD4SQd-EtuUNMMmxYDGDHZagI/view?usp=sharing
Script video - https://drive.google.com/file/d/1Gx4zCSnifbVN3I-32583dM6GTiQP0ZLT/view?usp=sharing

Would be great if others can test it out as well. Review of the physics implementation would be very much appreciated, haven't dabbled in this part of the codebase earlier

Related issues: #284, #2081, #2728, #2342

@rajat2004 rajat2004 marked this pull request as ready for review July 21, 2020 07:29
@rajat2004 rajat2004 mentioned this pull request Jul 21, 2020
@rajat2004 rajat2004 force-pushed the wind branch 2 times, most recently from 8793f35 to d1b4c6d Compare July 26, 2020 14:39
Copy link

@nicocarb nicocarb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented payload dynamics (single point of attachment to a cable) in AirSim and implemented it very similarly to how you have done. Can't speak to the exact physics of the wind, but it looks good.

@rajat2004
Copy link
Contributor Author

@nicocarb Thanks for the review! Payload attachment certainly seems interesting, would be nice to see the implementation if you're able to
I'm going to do some testing with ArduPilot, and I think those logs will be able to give more idea about the physics, maybe not to me, but definitely other much more experienced members of the AP community. One thing which is a bit strange is the vehicle remains tilted in the wind, maybe cause the wind to too high?

@nicocarb
Copy link

nicocarb commented Aug 3, 2020

@rajat2004 I apologize for the late response. I could perhaps explain my payload implementation. Not sure if I can show you my full code, however. I essentially created a payload object that has a volume, drag faces, a mass, and a cable length. Then, I take information about the current angle of the payload, current rate of change of angle of the payload, and drag force on the payload and use a small angle approximation to solve for the payload position in time in the World Frame relative to the drone's attachment point. Then, I apply a force vector equivalent to the tension force created by the payload in the direction of the payload position. Small angle approximations were appropriate for my use case; however, if small angle approximations are not valid, perhaps exploring a Euler approximation using payload acceleration and velocity may be successful. I was not able to get this to act appropriately. Most of the actual calculations occur in getNextKinematicsNoCollision(), which I've overriden. Perhaps we can discuss showing you an implementation of this from my side (I am just not sure as of right now whether I can).

In terms of the wind, I imagine it must be too high. For a drone to fly against wind, attempting to hold its positions, its thrust vectors must attempt to counteract the wind force. The video you've attached seems to suggest this is what the controller is attempting to do. I may be incorrect, however.

@rajat2004
Copy link
Contributor Author

@nicocarb No problem at all, I was just interested in getting an overview on the implementation. Thanks for the explanation, looks pretty complex, great that you got it working.
Re the wind, yeah, the values I'm using are quite high, low values didn't get much visual response. From the ArduPilot testing (Drive link in description) as well, the drone bounces back to the original orientation when wind is reset to 0. Also, the tilt seems slightly lesser in AP than Simple flight, and bounce back isn't also that much sudden, which could be due to more sophisticated control in AP. Still need to do some log analysis, an AP member did have a look at the physics and seemed okay.

@samuelctabor
Copy link

I think the physics implementation could be improved. Right now drag and wind are dealt with separately in getWindWrench and getDragWrench using the vehicle and wind velocities respectively. In reality, wind can only affect a vehicle through drag, and the only velocity needed for drag calculation is the velocity of the vehicle relative to the air.

The correct way to calculate the effect of wind would be to feed it into getDragWrench and subtract/add it (depending on convention) from the vehicle linear velocity linear_vel to give the velocity of the vehicle relative to the air.

@rajat2004
Copy link
Contributor Author

@samuelctabor Thanks for the review! Yes, I think you're correct, using the relative velocity does make more sense.
I've added a commit which makes those changes, could you have a look? This also reduces the code changes required by a lot.

Here's a video with SimpleFlight - https://drive.google.com/file/d/1ydMt8BFMTWRvJiTEuEByY6bfJmfswR4Z/view?usp=sharing
This however required reducing the wind speed in the example script, otherwise it would crash repeatedly to the ground when 25m/s speed was applied. So there's a behaviour change, was the previous implementation incorrect, or something more needs fixing?

@samuelctabor
Copy link

@rajat2004 the previous implementation was incorrect :-)

25m/s is a lot - over 55mph - your new values are more realistic.

Note that getWindWrench can now be removed.

@rajat2004
Copy link
Contributor Author

Yup, the new behaviour did make more sense, but wanted to confirm. The getWindWrench method was kept for reference, cleaned up now.
Thanks a lot for the review @samuelctabor!

@ibrhm0v
Copy link
Contributor

ibrhm0v commented Sep 2, 2020

hey @rajat2004 , I tried to test out your implementation. I keep getting this when I run simSetWind():

msgpackrpc.error.RPCError: rpclib: function 'simSetWind' (called with 1 arg(s)) threw an exception. The exception is not derived from std::exception. No further information available.

I could not trace it back. Could you guess my mistake?

@rajat2004
Copy link
Contributor Author

Quite strange, haven't seen that before.
You're running on Windows? Could you post the settings used, and maybe try the example script as well

@ibrhm0v
Copy link
Contributor

ibrhm0v commented Sep 2, 2020

Okay my bad :) It was a silly mistake. Seems like I need some coffee :DD

@rajat2004
Copy link
Contributor Author

Ok, great that it got fixed. Still, curious to know what caused the problem :)

@ibrhm0v
Copy link
Contributor

ibrhm0v commented Sep 2, 2020

I have given a tuple as the argument of airsim.Vector3r function. So instead of passing windX,windY,windZ I have passed (windX,windY,windZ)

@ibrhm0v
Copy link
Contributor

ibrhm0v commented Sep 2, 2020

BTW, wind physics is beautiful but can be adjusted to me more realistic. I can run tests for my drone now. Thanks for your contribution.
A.I: I have tested this on PX4 1.9.2 SITL

Copy link
Contributor

@ibrhm0v ibrhm0v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it on the following environment:

  1. Unreal Engine 4.24
  2. PX4 1.9.2 SITL
  3. AirSim 1.2.0 (+ some updates from 1.3.1 and a few fixes + my own customizations)

Couldn't face any problems. Wind implementation is great and fine for me now. Good job @rajat2004

@rajat2004
Copy link
Contributor Author

Great, thanks for the testing!
Agree, the physics could be improved, probably the job for someone more knowledgeable and motivated

@madratman madratman merged commit 67d5b6a into microsoft:master Sep 2, 2020
@rajat2004 rajat2004 deleted the wind branch September 3, 2020 02:58
@rajat2004
Copy link
Contributor Author

Thanks for merging! Probably should have marked this in the PR itself using keywords, but some issues can be closed now I think - #284, #2081, #2728, #2342

@hebai-github
Copy link

@rajat2004 The wind implementation is great! Is it possible to create location-based injection of wind, i.e., at different locations, different winds are injected?

@rajat2004
Copy link
Contributor Author

An interesting idea, there currently isn't any such location-based separation of effects anywhere in the code AFAIK, a possible way could be to store multiple wind profiles for areas based on the coordinates, and then lookup the specfic area every time. Any another ideas which might work?
I mostly won't be able to work on this any time soon, any contributions are more than welcome!

@hebai-github
Copy link

I was thinking to add another function in the physics engine, which takes the wind velocity and the corresponding location information as the input argument. If the drone's location is close to the input location, the wind velocity takes an effect. otherwise a default wind velocity is used. The wind profiling can be at the client side which looks up the wind velocity based on the vehicle's position. This way i think we can affect multiple drones with different wind velocities.

I would like to give a try anyway. but i am very new to AirSim and a novice C++ programmer. Any advice would be appreciated.

@rajat2004
Copy link
Contributor Author

Sure, that's another way, it all depends on the goal and the kind of effect to be achieved. You'll have to set some threshold to decide the barrier around the location as well.
The files changed in this PR will give an idea on what files you'll need to modify, the file structure naming and all is fairly straightforward, plus other commits and PRs can give pointers on which files and lines need to be touched

@aklein1995
Copy link

aklein1995 commented Nov 21, 2023

I have doubts with the wind implementation. Considering the example provided at:
https://github.com/Microsoft/AirSim/blob/main/PythonClient/multirotor/set_wind.py

As far as I understood, when you apply 10m/s in forward direction, if we do nothing at code (e.g., time.sleep(10)), we should expect the drone to move forward during 10 seconds.

I am confused, because instead of seeing such behavior, the drone does not move. In fact, the drone does not move when you modify either the X or Y dimensions with values between 0 and 20 m/s. For example, for 15m/s in X axis:
client.simSetWind(airsim.Vector3r(15, 0, 0))
When these values are above 20m/s, the drone seems to try to stabilize. Similarly, in Z dimension this issue also exist but lower values seems to make the drone move (e.g., 10m/s works).

Am I missing something? Does the drone have a way to stay stable on its own without coding it?

@Lesh97
Copy link

Lesh97 commented Jul 9, 2024

I use Unity Airsim.
add settings.json Wind :{"X":0,"Y":25,"Z":0}
vehicle is px4multirotor
but wind is not working
anyone can solve this? how to use it for unity?

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

Successfully merging this pull request may close these issues.

8 participants