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 a new c++ node offboard example #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Offboard mode works. Added readme to explain procedure and fixed smal…
…l typo in CMakeLists.txt
  • Loading branch information
Claudio Fritsche committed Nov 18, 2022
commit 83e5d7d24b4c3e2e12283fa2e973671771667acc
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
*.pyc
.vscode/*


px4_msgs/*
px4_ros_com/*

build/*
install/*
log/*
2 changes: 1 addition & 1 deletion offboard_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ find_package(px4_msgs REQUIRED)
find_package(px4_ros_com REQUIRED)

add_executable(offboard_cpp_node src/offboard_cpp_node.cpp)
ament_target_dependencies(offboard_node rclcpp std_msgs px4_msgs px4_ros_com)
ament_target_dependencies(offboard_cpp_node rclcpp std_msgs px4_msgs px4_ros_com)
target_include_directories(offboard_cpp_node PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
66 changes: 66 additions & 0 deletions offboard_cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# offboard_cpp
This `package` contains a c++ example for offboard control on ROS2 with [PX4](https://px4.io/).The source code is released under a BSD 3-Clause license.


## Instructions

### Setup
Add this `repository` to your RO2 workspace.
```
git clone https://github.com/Jaeyoung-Lim/px4-offboard.git
```

Make sure that the newest versions of [px4_msgs](https://github.com/PX4/px4_msgs) and [px4_ros_com](https://github.com/PX4/px4_ros_com) are in the same workspace.

```
git clone --recursive https://github.com/PX4/px4_ros_com.git
git clone --recursive https://github.com/PX4/px4_msgs.git
```

In a different folder, outside of your ros2 workspace clone the [PX4-Autopilot](https://github.com/PX4/PX4-Autopilot). At the time of writing this was commit [f2607335ac](https://github.com/PX4/PX4-Autopilot/commit/f2607335ac80dbd0fe151ba8fde122e91d776fc7).

```
git clone --recursive https://github.com/PX4/PX4-Autopilot.git

```

Finally you need to make sure that you have installed the `micro-ros-agent`. You can use `snap` to install it or [build it from source](https://github.com/micro-ROS/micro_ros_setup#building-micro-ros-agent).

### Build
1. Go to your ros2 workspace
2. Source your ros2 installation. For me this was:
```
source /opt/ros/galactic/setup.zsh
```
3. Build your workspace, which includes the 4 packages (px4_msgs, px4_ros_com and the two offboard packages from this repo..
```
colcon build --symlink-install
```
### Run
1. Open a new terminal and go to your PX4-Autopilot folder. Run:
```
make px4_sitl gazebo
```

2. Open a new terminal and source your ros2 workspace. Then run the micro-ros-agent:
```
micro-ros-agent udp4 --port 8888
```

3. Open a new terminal and source your ros2 workspace. Then run the c++ offboard node:
```
ros2 run offboard_cpp offboard_cpp_node
```

4. The SITL drone should have taken-off.

### Troubleshoot
* I don't know why but sometimes the offboard node does not manage to change the `NavState` of the SITL drone to offboard (14) and it remains on hold mode (4). To change that use QGC or use your nutt-shell:
```
commander mode offboard
```
* Once the offboard mode is set the SITL drone must be armed using QGC or the nutt-shell:
```
commander arm
```

2 changes: 1 addition & 1 deletion offboard_cpp/package.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<version>0.0.0</version>
<description>Simple PX4 offboard example with ROS2 and C++</description>
<maintainer email="claudio9fritsche@hotmail.com">claudio</maintainer>
<license>TODO: License declaration</license>
<license>BSD 3-Clause</license>

<buildtool_depend>ament_cmake</buildtool_depend>