zjewp
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # PX4 and MAVROS Installation <details> <summary style="font-size: 18px; font-weight: bold;">Official Documentation</summary> ### PX4 Installation https://docs.px4.io/main/en/dev_setup/dev_env_linux_ubuntu.html ### MAVROS Installation https://docs.px4.io/main/en/ros/mavros_installation.html ### MAVROS Offboard control example (Python) https://docs.px4.io/main/en/ros/mavros_offboard_python.html </details> <details> <summary style="font-size: 18px; font-weight: bold;">TL;DR</summary> ## The extra Steps you need to do ### 1. Install catkin_tools https://catkin-tools.readthedocs.io/en/latest/installing.html ### 2. Modify .bashrc https://docs.px4.io/main/en/ros/mavros_offboard_python.html#launching-your-script 將下面幾行放到你的 .bashrc 中,並且 setup.bash 要在 PX4 的四行命令之前,並且後面不能再 source 其他 workspace 的 setup.bash。 ``` source ~/<你的工作目錄>/devel/setup.bash source ~/PX4-Autopilot/Tools/simulation/gazebo-classic/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:/usr/lib/x86_64-linux-gnu/gazebo-11/plugins ``` ### 3. 修改 offb_node.py 將 Shebang 移到最上方,並改成 python3 <details> <summary>修改後的 offb_node.py</summary> ```python= #! /usr/bin/env python3 """ * File: offb_node.py * Stack and tested in Gazebo Classic 9 SITL """ import rospy from geometry_msgs.msg import PoseStamped from mavros_msgs.msg import State from mavros_msgs.srv import CommandBool, CommandBoolRequest, SetMode, SetModeRequest current_state = State() def state_cb(msg): global current_state current_state = msg if __name__ == "__main__": rospy.init_node("offb_node_py") state_sub = rospy.Subscriber("mavros/state", State, callback = state_cb) local_pos_pub = rospy.Publisher("mavros/setpoint_position/local", PoseStamped, queue_size=10) rospy.wait_for_service("/mavros/cmd/arming") arming_client = rospy.ServiceProxy("mavros/cmd/arming", CommandBool) rospy.wait_for_service("/mavros/set_mode") set_mode_client = rospy.ServiceProxy("mavros/set_mode", SetMode) # Setpoint publishing MUST be faster than 2Hz rate = rospy.Rate(20) # Wait for Flight Controller connection while(not rospy.is_shutdown() and not current_state.connected): rate.sleep() pose = PoseStamped() pose.pose.position.x = 0 pose.pose.position.y = 0 pose.pose.position.z = 2 # Send a few setpoints before starting for i in range(100): if(rospy.is_shutdown()): break local_pos_pub.publish(pose) rate.sleep() offb_set_mode = SetModeRequest() offb_set_mode.custom_mode = 'OFFBOARD' arm_cmd = CommandBoolRequest() arm_cmd.value = True last_req = rospy.Time.now() while(not rospy.is_shutdown()): if(current_state.mode != "OFFBOARD" and (rospy.Time.now() - last_req) > rospy.Duration(5.0)): if(set_mode_client.call(offb_set_mode).mode_sent == True): rospy.loginfo("OFFBOARD enabled") last_req = rospy.Time.now() else: if(not current_state.armed and (rospy.Time.now() - last_req) > rospy.Duration(5.0)): if(arming_client.call(arm_cmd).success == True): rospy.loginfo("Vehicle armed") last_req = rospy.Time.now() local_pos_pub.publish(pose) rate.sleep() ``` </details> 官方的說明文件上未將 Shebang 置於程式碼最上方,導致執行時會發生錯誤,且 ubuntu 20.04 版本的 ```python``` 環境變數是未被設定的,應該將 Shebang 裡的 ```python``` 改成 ```python3```。 ```#! /usr/bin/env python3``` 這行指令就是 Shebang,用於指定該檔案的直譯器,可使該程式檔可如同一般的執行檔一樣直接呼叫。 > e.g., 直接在 terminal 打 ```./foo.py```,前面不必加 python。 ### 4. Compile PX4 SITL and Gazebo Classic ``` make -C ./PX4-Autopilot/ px4_sitl gazebo-classic ``` </details> <iframe height="405" src="https://www.youtube.com/embed/3CWNg_pJPFQ?si=IupvA6u8OGqOPXYy" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> > This video starts after completing the "Run the `ubuntu.sh` to install" step. > Download the vdi file from my Google Drive [here](https://drive.google.com/file/d/1LMt0zbts0C5hIjb7dVVFDUKfM0ROCESi/view?usp=drive_link) if you want to follow along with the video. (The user password is "rvl".) <span style=color:red;font-weight:bold>!! If you are a student from the Robot Vision Lab, make sure to download from our [NAS](http://gofile.me/3rsol/q4LWCGK8x). Downloading from external sources could lead to our lab's network being blocked. !!</span> > Additionally, check out the note in the [README](https://github.com/cjzrv/summer-course/blob/main/week3/HW2/README.md) of my GitHub repository (for easier copy-pasting of commands). ## 1. Install PX4 #### Download PX4 Source Code ```shell git clone https://github.com/PX4/PX4-Autopilot.git --recursive ``` #### Run the `ubuntu.sh` to install ```shell bash ./PX4-Autopilot/Tools/setup/ubuntu.sh ``` #### Compile PX4 SITL and Gazebo Classic ``` DONT_RUN=1 make -C ./PX4-Autopilot/ px4_sitl gazebo-classic ``` [](https://) ## 2. Install catkin_tools #### Add ROS apt repositories ``` sudo sh \ -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" \ > /etc/apt/sources.list.d/ros-latest.list' && \ wget http://packages.ros.org/ros.key -O - | sudo apt-key add - ``` #### Install catkin-tools with apt-get ``` sudo apt-get update && sudo apt-get install -y python3-catkin-tools ``` ## 3. Install MAVROS #### Install MAVROS with apt-get (Binary Install) ``` sudo apt-get install -y ros-${ROS_DISTRO}-mavros ros-${ROS_DISTRO}-mavros-extras ros-${ROS_DISTRO}-mavros-msgs ``` #### Install GeographicLib datasets ``` wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh && \ sudo bash ./install_geographiclib_datasets.sh && \ rm -f ./install_geographiclib_datasets.sh ``` ## 4. Run the MAVROS Offboard control example #### Create Catkin Workspace ``` mkdir -p ~/poop_space/src cd ~/poop_space catkin init wstool init src ``` #### Create the ROS Package ``` cd src catkin_create_pkg offboard_py rospy cd .. catkin build source devel/setup.bash roscd offboard_py mkdir scripts cd scripts touch offb_node.py chmod +x offb_node.py ``` #### Edit `offb_node.py` with following code: <details> <summary style="font-weight: bold;">offb_node.py (modified)</summary> ```python= #! /usr/bin/env python3 """ * File: offb_node.py * Stack and tested in Gazebo Classic 9 SITL """ import rospy from geometry_msgs.msg import PoseStamped from mavros_msgs.msg import State from mavros_msgs.srv import CommandBool, CommandBoolRequest, SetMode, SetModeRequest current_state = State() def state_cb(msg): global current_state current_state = msg if __name__ == "__main__": rospy.init_node("offb_node_py") state_sub = rospy.Subscriber("mavros/state", State, callback = state_cb) local_pos_pub = rospy.Publisher("mavros/setpoint_position/local", PoseStamped, queue_size=10) rospy.wait_for_service("/mavros/cmd/arming") arming_client = rospy.ServiceProxy("mavros/cmd/arming", CommandBool) rospy.wait_for_service("/mavros/set_mode") set_mode_client = rospy.ServiceProxy("mavros/set_mode", SetMode) # Setpoint publishing MUST be faster than 2Hz rate = rospy.Rate(20) # Wait for Flight Controller connection while(not rospy.is_shutdown() and not current_state.connected): rate.sleep() pose = PoseStamped() pose.pose.position.x = 0 pose.pose.position.y = 0 pose.pose.position.z = 2 # Send a few setpoints before starting for i in range(100): if(rospy.is_shutdown()): break local_pos_pub.publish(pose) rate.sleep() offb_set_mode = SetModeRequest() offb_set_mode.custom_mode = 'OFFBOARD' arm_cmd = CommandBoolRequest() arm_cmd.value = True last_req = rospy.Time.now() while(not rospy.is_shutdown()): if(current_state.mode != "OFFBOARD" and (rospy.Time.now() - last_req) > rospy.Duration(5.0)): if(set_mode_client.call(offb_set_mode).mode_sent == True): rospy.loginfo("OFFBOARD enabled") last_req = rospy.Time.now() else: if(not current_state.armed and (rospy.Time.now() - last_req) > rospy.Duration(5.0)): if(arming_client.call(arm_cmd).success == True): rospy.loginfo("Vehicle armed") last_req = rospy.Time.now() local_pos_pub.publish(pose) rate.sleep() ``` </details> <details> <summary style="font-weight: bold;">Additional explanation</summary> 官方的說明文件上未將 Shebang 置於程式碼最上方,導致執行時會發生錯誤,且 ubuntu 20.04 版本的 ```python``` 環境變數是未被設定的,應該將 Shebang 裡的 ```python``` 改成 ```python3```。 ```#! /usr/bin/env python3``` 這行指令就是 Shebang,用於指定該檔案的直譯器,可使該程式檔可如同一般的執行檔一樣直接呼叫。 > e.g., 直接在 terminal 打 ```./foo.py```,前面不必加 python。 </details> #### Create the ROS launch file ``` roscd offboard_py mkdir launch cd launch touch start_offb.launch ``` #### Edit `start_offb.launch` with following code: ```XML= <?xml version="1.0"?> <launch> <!-- Include the MAVROS node with SITL and Gazebo --> <include file="$(find px4)/launch/mavros_posix_sitl.launch"> </include> <!-- Our node to control the drone --> <node pkg="offboard_py" type="offb_node.py" name="offb_node_py" required="true" output="screen" /> </launch> ``` ## Modify your .bashrc #### Add following lines to your `.bashrc` ```= source ~/poop_space/devel/setup.bash source ~/PX4-Autopilot/Tools/simulation/gazebo-classic/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic export GAZEBO_MODEL_PATH=${GAZEBO_MODEL_PATH}:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models ``` <details> <summary style="font-weight: bold;">(optional) Edit .bashrc with echo and ">>"</summary> ```= echo -e "source ~/poop_space/devel/setup.bash \n\ source ~/PX4-Autopilot/Tools/simulation/gazebo-classic/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default \n\ export ROS_PACKAGE_PATH=\$ROS_PACKAGE_PATH:~/PX4-Autopilot \n\ export ROS_PACKAGE_PATH=\$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic \n\ export GAZEBO_MODEL_PATH=\${GAZEBO_MODEL_PATH}:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic/models" \ >> ~/.bashrc ``` </details> #### Source your `.bashrc` ``` source ~/.bashrc ``` ## Launching your script ``` roslaunch offboard_py start_offb.launch ``` --- <details> <summary style="font-weight: bold;">Reference</summary> PX4 Installation https://docs.px4.io/main/en/dev_setup/dev_env_linux_ubuntu.html MAVROS Installation https://docs.px4.io/main/en/ros/mavros_installation.html MAVROS Offboard control example (Python) https://docs.px4.io/main/en/ros/mavros_offboard_python.html PX4 UAV uses Mavros in Gazebo-classic simulation https://github.com/FCWTW/SummerCourse/blob/main/Week%203/HW2/README.md ERROR: cannot launch node of type [px4/px4] https://github.com/PX4/PX4-Autopilot/issues/14762 </details>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully