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

WSL2 instructions to build, flash and simulate on Windows #1747

Merged
merged 11 commits into from
Mar 17, 2022
Merged

Conversation

MaEtUgR
Copy link
Member

@MaEtUgR MaEtUgR commented Jan 31, 2022

I added instructions on how to employ WSL2 to do PX4 development on Windows. I'm successfully using this environment for several months now. It works seamlessly, fast and allows for efficient work. The biggest improvement that brought me to switch to this environment is the native graphics support with 3D acceleration through the built-in WSLg. I suggest we add these instructions as even a preferred option to the Cygwin toolchain and keep both options for now. I would honestly also surface the VMWare instructions as a valid option because for certain developers it might be the prefered way.

I replaced the BashOnWindows instructions because those are deprecated.

Co-authored-by: Daniel Agar <daniel@agar.ca>
@hamishwillee
Copy link
Collaborator

I will try this out tomorrow. Thanks!

There should be only one recommended main approach for each platform - what would it take for WSL2 to become that option?

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Feb 1, 2022

what would it take for WSL2 to become that option?

For my workflow it is already the main option. The caveats are:

  • No direct serial flashing with the upload script
  • No automatic connection of native QGC to the sim running in WSL
  • ~Win 11 requirement for graphics support

This might as well be a complete deal-breaker for some but on the other side the size problems preventing to generate a new Cygwin toolchain with the existing script makes the current version more and more outdated.

@hamishwillee
Copy link
Collaborator

hamishwillee commented Feb 2, 2022

Thanks @MaEtUgR!

Are any of the issues you listed - direct serial flashing, auto connection of native QGC, graphics support amenable to fixing via configuration in some way or are they likely "forever" problems?

My take on this is that we can live with "No direct serial flashing with the upload script", and "No automatic connection of native QGC to the sim running in WSL." (if we have to - undesirable) but it is much too early to insist on Win 11.

You state in "Requirements for graphics support" that this is in Windows insider preview builds, so assuming it will go into Windows 10 soon, that might reasonably be the trigger for making this the main approach (if my assumption it will go into Windows 10 is correct). That said, if we can somehow route the the comms to localhost on the host, that would be even better.

@hamishwillee
Copy link
Collaborator

hamishwillee commented Feb 2, 2022

I got the error WARNING: An illegal reflective access operation has occurred running JMAVSim. Anything special I need to do?

Feb 02, 2022 4:35:32 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by javax.media.j3d.JoglPipeline (rsrc:j3dcore.jar) to method sun.awt.AppContext.getAppContext()
WARNING: Please consider reporting this to the maintainers of javax.media.j3d.JoglPipeline
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Gazebo seems to work. Still playing.

3. Install the extension called [Remote - WSL](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) (marketplace)
4. [Open a WSL shell](dev_env_windows_wsl.md#opening-a-wsl-shell)
5. Switch to the PX4 folder: `cd ~/PX4-Autopilot`
6. Open this folder with WSL integration in Visual Studio Code `code .`
Copy link
Collaborator

Choose a reason for hiding this comment

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

How? I presume you mean find the folder in the windows C drive? Note that the Linux penguin doesn't show up in VS Code so you can't select the WSL version in the same way as you would in Explorer?

Copy link
Member Author

Choose a reason for hiding this comment

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

You install the extension in the VS code gui, then open a WSL shell, navigate to the folder with the command cd ~/PX4-Autopilot and in this folder execute the command code . as if you would be on Linux and the repository opens in VS code but natively. They do some trickery WSL magic to make that happen.

@MaEtUgR
Copy link
Member Author

MaEtUgR commented Feb 7, 2022

are they likely "forever" problems?

@hamishwillee Theoretically there can be workarounds. E.g. serial flashing could maybe call a pyton script outside of WSL and for the automatic connection to native QGC we could in theory run MAVLink router in WSL to forward the conntection to Windows. So easy to fix no, possibly yes with some cumbersome workarounds.

but it is much too early to insist on Win 11

I thought so too. It's only for graphics support that the Windows version has to be so recent.

You state in "Requirements for graphics support" that this is in Windows insider preview builds, so assuming it will go into Windows 10 soon

I expected the same since I had it running on the Windows 10 insider build before I switched to Windows 11 stable. But when I checked https://github.com/microsoft/wslg#pre-requisites again it switched from Windows 10 insider build to Windows 11 insider build 🤔 Maybe it's just to tease or not up to date. In any case Windows 11 stable works for sure. Windows 10 I'd need to test again.

That said, if we can somehow route the comms to localhost on the host, that would be even better.

Do you mean such that e.g. jMAVsim could run natively? That's also theoretically possible but with multiple workarounds to start and connect it all.

I got the error WARNING: An illegal reflective access operation has occurred running JMAVSim.

I got that as well. Was assuming it's the same for Ubuntu since it's basically running on Ubuntu. I remember jMAVsim worked with this setup earlier on. So I was assuming it's a general issue.

@hamishwillee
Copy link
Collaborator

That said, if we can somehow route the comms to localhost on the host, that would be even better.

Do you mean such that e.g. jMAVsim could run natively? That's also theoretically possible but with multiple workarounds to start and connect it all.

@MaEtUgR No, I mean setting things up such that you can automatically connect to simulator from QGC on Windows (without having to work out the IP address of your virtual machine). You answered here #1747 (comment) as "maybe, but I'm not sure how".

I got the error WARNING: An illegal reflective access operation has occurred running JMAVSim.

I got that as well. Was assuming it's the same for Ubuntu since it's basically running on Ubuntu. I remember jMAVsim worked with this setup earlier on. So I was assuming it's a general issue.

You would be right/it is: http://docs.px4.io/master/en/simulation/jmavsim.html#an-illegal-reflective-access-operation-has-occured

@hamishwillee
Copy link
Collaborator

Awesome. Nearly there. Would be good if you could sanity check my changes.

@hamishwillee
Copy link
Collaborator

hamishwillee commented Mar 17, 2022

@MaEtUgR One more idea for "static IP address" workaround. Not sure it is "scalable" or something we can support, but perhaps something we could mention.

A similar problem comes up with websites hosted as a process in a virtual machine - every time they boot they get a new IP. The solution as I understand it is Dynamic DNS. Yes your IP address changes, but on boot you find the address and send it to the DNS system which then updates. So you end up doing your addressing via DNS. https://www.noip.com/support/knowledgebase/installing-the-linux-dynamic-update-client-on-ubuntu/

Something to think about.

```
This will open the IDE fully integrated with the WSL shell.

Make sure you always open the PX4 repository in the Remote WSL mode.
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, @MaEtUgR Thanks for your explanation of the WSL integration.

To make this clear to others, I have added this line here - so that make it very clear that "this" is what it mean to open the PX4 repository in the Remote WSL mode.

Then in step 7 I add your image of how you "Open Recent" and not that it is also " opening in Remote WSL mode "

Copy link
Member Author

Choose a reason for hiding this comment

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

Perfect, thanks a lot. I just didn't see how to tell that in a clear way 😇

@hamishwillee
Copy link
Collaborator

@MaEtUgR Thanks for your patience. I've integrated your comments. Also done a cross link from Cygwin recommending this if you're building against master. There is a suggestion here #1747 (comment) but should not block merging.

Upshot, merging now as "useful starting point". We can iterate.

If you find out that this runs on windows 10 with the GUI, let me know. That would trigger it replacing Cygwin IMO.

@hamishwillee hamishwillee merged commit f1927ed into master Mar 17, 2022
@hamishwillee hamishwillee deleted the WSL2 branch March 17, 2022 07:27
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.

4 participants