Danny Ho
    • 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
    • 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
    • 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
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
  • 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
    # UAV Simulation with Gazebo + PX4 The origin project is at [here](https://github.com/matlabbe/rtabmap_drone_example.git), we will show how to install the corresponding packages and start the process like so. The origin repository provides a `Docker` file, and we will be using the commands in it. After we can successfully start the navigation, we will change the control of drone to KeyBoard, and then apply to our own world file created at [Simulation using ROS + Gazebo with ArduPilot](https://hackmd.io/@dANNy1209/rkBAPYyqA). ## Install packages Use the following command to install ROS packages: ```shell sudo apt update sudo apt install ros-noetic-teleop-twist-keyboard ros-noetic-geographic-msgs ros-noetic-dwa-local-planner ros-noetic-rtabmap-ros ros-noetic-mavlink geographiclib-tools libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev python3-pip ``` Use the following command to install Python packages: ```shell sudo pip3 install numpy toml packaging jinja2 empy pyros-genmsg ``` <br> ## Install PX4 We will be using PX4 for controling drone in Gazebo and communicate with ROS. Install PX4 using the following commands: ```shell git clone https://github.com/PX4/PX4-Autopilot.git cd PX4-Autopilot git checkout v1.12.3 git submodule update --init --recursive sudo HEADLESS=1 make -j8 px4_sitl_default gazebo sudo make px4_sitl_default install source ~/.bashrc ``` >[!Note] >If you found it stuck at the command `HEADLESS` (it will automatically start the PX4 for testing), just hit `enter` and `CTRL`+`C` to >escape it and keep going on the next command. <br> ## Create Workspace Next, create a ROS workspace with the following command, it also contains the repository we need inside: ```shell cd ~/Documents #You can decide where to put your workspace by yourself, I put it in ~/Documents mkdir -p catkin_ws/src cd catkin_ws/src catkin_init_workspace git clone https://github.com/mavlink/mavros.git git clone https://github.com/SyrianSpock/realsense_gazebo_plugin.git echo "install(DIRECTORY models DESTINATION \${CATKIN_PACKAGE_SHARE_DESTINATION})" >> realsense_gazebo_plugin/CMakeLists.txt cd mavros git checkout 1.9.0 sudo ./mavros/scripts/install_geographiclib_datasets.sh cd ../../ catkin_make -j8 ``` <br> ## Build up the SLAM with ROS Clone the repository <b>(we are currently at the workspace root directory)</b> and change some settings then build it. We need to change those settings because we wan't to control the drone using keyboard, so the corresponding packages needs to be removed to avoid errors: ```shell git clone https://github.com/matlabbe/rtabmap_drone_example.git src/rtabmap_drone_example source ~/.bashrc ``` Open `src/rtabmap_drone_example/launch/slam.launch` with your preference text editor. Delete all code in `<!-- joystick -->` section: ![image](https://hackmd.io/_uploads/SkjC4pra0.png) Open `src/rtabmap_drone_example/src/offboard_node.cpp` with your preference text editor. Delete the following lines: ![image](https://hackmd.io/_uploads/rkRCH6BpC.png) ![image](https://hackmd.io/_uploads/BkigLpBpC.png) ![image](https://hackmd.io/_uploads/HJPMLaH6R.png) CMake it again (Currently at your workspace root dir): ```shell catkin_make -j8 echo 'export NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES:-all}' >> ~/.bashrc echo 'export NVIDIA_DRIVER_CAPABILITIES=${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics' >> ~/.bashrc source ~/.bashrc ``` <br> ## Final setup Finally, we need to setup some source and export so that we don't need to do such things every time we open terminal. You will see `{YOUR_WORKSPACE_PATH}` in the commands, you need to change them to where you put the workspace at: ```shell echo "source /usr/local/px4/Tools/setup_gazebo.bash /usr/local/px4 /usr/local/px4/build/px4_sitl_default" >> ~/.bashrc echo "source {YOUR_WORKSPACE_PATH}/devel/setup.sh" >> ~/.bashrc echo "export GAZEBO_MODEL_PATH=\$GAZEBO_MODEL_PATH:{YOUR_WORKSPACE_PATH}/src/rtabmap_drone_example/models" >> ~/.bashrc echo "export GAZEBO_MODEL_PATH=\$GAZEBO_MODEL_PATH:{YOUR_WORKSPACE_PATH}/src/realsense_gazebo_plugin/models" >> ~/.bashrc echo "export ROS_PACKAGE_PATH=\$ROS_PACKAGE_PATH:/usr/local/px4:/usr/local/px4/Tools/sitl_gazebo" >> ~/.bashrc source ~/.bashrc ``` Change to root privilege and delete those two files: ```shell sudo su rm /tmp/px4-sock-0 /tmp/px4_lock-0 # Go back to normal user using CTRL+D ``` Change the package imported in `patrol.py`: Use your preference text editor to open `/opt/ros/noetic/lib/rtabmap_util/patrol.py` (with sudo), change ``` from rtabmap_ros.msg import Goal ``` to ``` from rtabmap_msgs.msg import Goal ``` This is for making sure `patrol.py` works in later SLAM navigation. <br> ## Running the origin project To run the project, we need a total of 6 terminal sessions. Below I'll show you how to open and execute them. 1. Start Gazebo simulation We can start the simulation using the command in first session: ```shell roslaunch rtabmap_drone_example gazebo.launch ``` You should see the rooms just like those in the origin repository. 2. Start SLAM Next, use the below command to start the rtabmap and SLAM for map in the second session: ```shell roslaunch rtabmap_drone_example slam.launch ``` You should see the rtabmap application pop out and can see the drone's sight. 3. Start SLAM result view Start the rviz using the below command to view the result of SLAM in 2D view in third session: ```shell roslaunch rtabmap_drone_example rviz.launch ``` The result should look like a lidar but create with VSLAM. 4. Drone takeoff Use the following command to let the drone takeoff in the forth session: ```shell rosrun rtabmap_drone_example offboard ``` Wait for the drone to takeoff, the rtabmap and SLAM view should follow it. 5. Start drone control We've mentioned to control the drone with keyboard, this is the place. We can use the following command to send instructions to drone in Gazebo in fifth session: ```shell rosrun teleop_twist_keyboard teleop_twist_keyboard.py ``` You should get the following result that tells you how to control the drone: ```shell Reading from the keyboard and Publishing to Twist! --------------------------- Moving around: u i o j k l m , . For Holonomic mode (strafing), hold down the shift key: --------------------------- U I O J K L M < > t : up (+z) b : down (-z) anything else : stop ``` 6. Set label of position The repository provides a way to set position marking for later navigation. We can use the following command in the sixth session: ``` rosservice call /rtabmap/set_label "node_id: 0 node_label: 'home' frame_id: ''" ``` This should be a one liner. Change the `home` to your label name, for example `kitchen`, `bedroom`...etc. At this point, <b>we already have everything we need</b>. Start controling the drone to fly around and use the command in step 6 to <b style="color: red;">set up some labels</b>. After you finish them, you can stop the simulation, and <b>start them all again</b>, with the guidence: 1. Start Gazebo simulation Remain the same, just open the simulation. 2. Start SLAM Change the command to: ``` roslaunch rtabmap_drone_example slam.launch localization:=true ``` This would start SLAM that enable us to use the recorded map. 3. Start SLAM result view Remain the same, open rviz. You should now see the track of drone you go through during the previous simulation. 4. Drone takeoff Same, takeoff the drone. 5. Set the map for SLAM Go to rtabmap application. Click the reload button on the left top, and just click ok to let it load the record. If you accidently start the SLAM again without adding `localization:=true`, you will found that it overwrites the map result. Just do the map record again and carefully dealing with the launch command 6. Automatic navigation Finally, provide some points and the wait time using the following command, it should automatically start the navigation: ``` rosrun rtabmap_util patrol.py _time:=5 kitchen room1 ``` The above command means that the drone will keep navigating between `kitchen` and `room1` with a `5 secs` wait time when reaching the target point. Change them to fit your requirement. Upon sending the above commands, you should now see the drone keep flying around the points and are following the track you do when creating SLAM map. Congrats! Next, we will be changing the map to our own one. ## Replace the Gazebo world with our own world Finally, to replace the world, we can simply create a new `.world` file in `{YOUR_WORKSPACE_PATH}/src/rtabmap_drone_example/worlds`, and edit the line: ``` <arg name="world_name" default="apt"/> ``` Replace `apt` to your world's file name(see the second step of the [overall guidence](https://hackmd.io/@dANNy1209/HylB7L-PoC)), and remember to remove the drone we created before, as it provides a drone by default when launching the gazebo world. Start the simulation as usual and you should now see your world and can fly around using the commands provided in last section.

    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 Google 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