PX4 / PX4-user_guide

PX4 User Guide
https://docs.px4.io/main/en/index.html
Other
311 stars 1.63k forks source link

px4-ros2 offboard control with pyrhon example #1675

Open JinraeKim opened 2 years ago

JinraeKim commented 2 years ago

There is a cpp script for offboard control example, but it would be also helpful to provide some launchable python codes for the same example as ros2 usually supports both languages.

TSC21 commented 2 years ago

There is a cpp script for offboard control example, but it would be also helpful to provide some launchable python codes for the same example as ros2 usually supports both languages.

@JinraeKim thanks for the suggestion. We are open for contributions in this regard from anyone willing to do them. Are you open to contribute in this regard? Thank you

JinraeKim commented 2 years ago

@JinraeKim thanks for the suggestion. We are open for contributions in this regard from anyone willing to do them. Are you open to contribute in this regard? Thank you

Thank you for your reply. I'd like to do so, but I have been trying to learn how to use PX4 and ROS2; due to lack of my knowledge of both PX4 and ROS2 (and C++ as well), I don't think I can add an appropriate example. I'm really sorry. If I find a successful example (but it could be a far future), I'll contribute.

Jaeyoung-Lim commented 2 years ago

@JinraeKim Could you maybe elaborate if there is a specific reason you are trying to use python for offboard control?

hamishwillee commented 2 years ago

I would guess the same reason everyone uses Python when they are starting - it's a much easier language to learn.

Jaeyoung-Lim commented 2 years ago

@hamishwillee I totally agree, but more wondering if we should enable beginners use ROS2 + offboard.

Since the use case of ROS2 with PX4 is motivated by removing the performance bottlenecks coming from using mavlink, I was trying to understand why one would use python ROS2 with PX4.

IMO, it is safer to use mavsdk-python if the developer is starting out and does not understand what is going on inside PX4.

hamishwillee commented 2 years ago

@Jaeyoung-Lim Howdy! My take on this is that this is a matter of setting expectation - what can you do with each framework and programming language? What is easier for what task? What are the limits? There is no point telling a beginner "go and use MAVSDK" if that isn't going to get the performance they need for the task at hand.

Some questions

If the answer is "Python is a peer of C++ for ROS" then we should try have an example of that too. And here we should compare and contrast, with some kind of useful comparison of the options.

Can you give me some idea of where the border for usage is? Normally we say:

JinraeKim commented 2 years ago

@JinraeKim Could you maybe elaborate if there is a specific reason you are trying to use python for offboard control?

It is because I'm familiar with Python and ROS2, not with C++ (main language is Julia though).

Honestly, there are too many choices to use PX4 so I'm not sure my plan is suitable for my research. Also, I saw in docs that the developers highly recommend that I start with ROS2 for offboard control.

JinraeKim commented 2 years ago

@Jaeyoung-Lim Howdy! My take on this is that this is a matter of setting expectation - what can you do with each framework and programming language? What is easier for what task? What are the limits? There is no point telling a beginner "go and use MAVSDK" if that isn't going to get the performance they need for the task at hand.

Some questions

  • is there "really" a bottleneck using Python with ROS2 and offboard - note, I did not say "MAVLink"?
  • Is Python a reasonable peer of C++ in ROS.
  • Where do you think the boundaries are?

If the answer is "Python is a peer of C++ for ROS" then we should try have an example of that too. And here we should compare and contrast, with some kind of useful comparison of the options.

Can you give me some idea of where the border for usage is? Normally we say:

  • "MAVSDK has small learning curve, is intuitive, and is already customised for UAV domain". Use it where you can, which tends to be any kind of basic basic flight tasks - setting positions, taking off, landing, setting missions.
  • ROS is generic robotics. As such it has harder learning curve but it comes with a lot of useful routines for doing common stuff, and integrates well with computer vision libraries which would be hard to write yourself. So if you want to leverage existing code that would be hard to write yourself this is worth considering.
    • Sounds like you're adding performance as a benefit here, presumably because of the ROS2 integration with uorb?

A nice summary! As a beginner of PX4, there are too many routines to perform flight control tasks, although there are less comparisons between them. IMO, there should be more comparisons between those approaches in terms of 1) performance, 2) usage pattern, and 3) how easy to learn and Implement.

hamishwillee commented 2 years ago

Also, I saw in docs that the developers highly recommend that I start with ROS2 for offboard control.

As above, you need to start with "what you want to achieve" and that will determine the path you take.

I have tried to integrate above summary in https://github.com/PX4/PX4-user_guide/pull/1681 . I personally don't propose to create any Python ROS examples - though if someone wants to that would be great. I consider it a minor bug that we don't.

haotianh9 commented 2 years ago

@JinraeKim I have tried to write a python version of offboard control, and it behaves the same as the original C++ version. It is located in the scripts folder and can be ran by python3 offboard_control_py.py I've already submitted pull request .