-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
navigation: adds example usage of local navigation interface
- Loading branch information
1 parent
e2bccb8
commit 7107fc6
Showing
6 changed files
with
177 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(example_local_navigation_cpp) | ||
|
||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 17) | ||
endif() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter) | ||
endif() | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
find_package(eigen3_cmake_module REQUIRED) | ||
find_package(Eigen3 REQUIRED) | ||
find_package(ament_cmake REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(px4_ros2_cpp REQUIRED) | ||
|
||
include_directories(include ${Eigen3_INCLUDE_DIRS}) | ||
add_executable(example_local_navigation_cpp | ||
src/main.cpp) | ||
ament_target_dependencies(example_local_navigation_cpp Eigen3 px4_ros2_cpp rclcpp) | ||
|
||
install(TARGETS | ||
example_local_navigation_cpp | ||
DESTINATION lib/${PROJECT_NAME}) | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
ament_package() |
80 changes: 80 additions & 0 deletions
80
examples/cpp/navigation/local_navigation/include/local_navigation.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/**************************************************************************** | ||
* Copyright (c) 2023 PX4 Development Team. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
****************************************************************************/ | ||
#pragma once | ||
|
||
|
||
#include <rclcpp/rclcpp.hpp> | ||
#include <px4_ros2/common/context.hpp> | ||
#include <px4_ros2/navigation/experimental/local_navigation_interface.hpp> | ||
|
||
#include <Eigen/Core> | ||
|
||
using namespace std::chrono_literals; // NOLINT | ||
|
||
static const std::string kName = "local_navigation_test"; | ||
static const std::string kNodeName = "example_local_navigation_node"; | ||
|
||
class LocalNavigationTest : public px4_ros2::Context | ||
{ | ||
public: | ||
explicit LocalNavigationTest(rclcpp::Node & node) | ||
: Context(node), _node(node) | ||
{ | ||
const uint8_t pose_frame = 0; | ||
const uint8_t velocity_frame = 0; | ||
|
||
_local_navigation_interface = std::make_shared<px4_ros2::LocalNavigationInterface>( | ||
*this, | ||
pose_frame, | ||
velocity_frame); | ||
|
||
} | ||
|
||
void updateAuxLocalPosition() | ||
{ | ||
px4_ros2::LocalPositionEstimate local_position_estimate {}; | ||
|
||
local_position_estimate.timestamp_sample = _node.get_clock()->now().nanoseconds() * 1e-3; | ||
local_position_estimate.velocity_xy = Eigen::Vector2f{1.f, 2.f}; | ||
local_position_estimate.velocity_xy_variance = Eigen::Vector2f{0.3f, 0.4f}; | ||
|
||
_local_navigation_interface->update(local_position_estimate); | ||
} | ||
|
||
private: | ||
rclcpp::Node & _node; | ||
std::shared_ptr<px4_ros2::LocalNavigationInterface> _local_navigation_interface; | ||
}; | ||
|
||
class TestNode : public rclcpp::Node | ||
{ | ||
public: | ||
TestNode() | ||
: Node(kNodeName) | ||
{ | ||
// Enable debug output | ||
auto ret = | ||
rcutils_logging_set_logger_level(get_logger().get_name(), RCUTILS_LOG_SEVERITY_DEBUG); | ||
|
||
if (ret != RCUTILS_RET_OK) { | ||
RCLCPP_ERROR(get_logger(), "Error setting severity: %s", rcutils_get_error_string().str); | ||
rcutils_reset_error(); | ||
} | ||
|
||
_local_navigation_test = std::make_unique<LocalNavigationTest>(*this); | ||
|
||
RCLCPP_INFO(get_logger(), "TestNode running!"); | ||
|
||
int counter = 10; | ||
while (counter-- > 0) { | ||
_local_navigation_test->updateAuxLocalPosition(); | ||
sleep(1); | ||
} | ||
|
||
} | ||
|
||
private: | ||
std::unique_ptr<LocalNavigationTest> _local_navigation_test; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>example_local_navigation_cpp</name> | ||
<version>0.0.1</version> | ||
<description>Example navigation: local navigation</description> | ||
<maintainer email="[email protected]">Beat Kueng</maintainer> | ||
<license>BSD-3-Clause</license> | ||
|
||
<buildtool_depend>eigen3_cmake_module</buildtool_depend> | ||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<buildtool_export_depend>eigen3_cmake_module</buildtool_export_depend> | ||
|
||
<build_depend>eigen</build_depend> | ||
<build_depend>rclcpp</build_depend> | ||
<build_export_depend>eigen</build_export_depend> | ||
|
||
<depend>px4_ros2_cpp</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>ament_lint_common</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/**************************************************************************** | ||
* Copyright (c) 2023 PX4 Development Team. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
****************************************************************************/ | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
|
||
#include <local_navigation.hpp> | ||
|
||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
rclcpp::init(argc, argv); | ||
rclcpp::spin(std::make_shared<TestNode>()); | ||
rclcpp::shutdown(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters