Skip to content

Commit a661169

Browse files
add obstacle motion model interface
1 parent e1b0d92 commit a661169

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(nav2_dynamic_motion_model)
3+
4+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
add_compile_options(-Wall -Wextra -Wpedantic)
6+
endif()
7+
8+
# find dependencies
9+
find_package(ament_cmake REQUIRED)
10+
find_package(rclcpp REQUIRED)
11+
find_package(geometry_msgs REQUIRED)
12+
find_package(nav2_dynamic_msgs REQUIRED)
13+
14+
15+
16+
include_directories(include)
17+
18+
add_library(nav2_dynamic_motion_model
19+
src/constant_velocity_model.cpp
20+
)
21+
ament_target_dependencies(nav2_dynamic_motion_model
22+
rclcpp
23+
nav2_dynamic_msgs
24+
geometry_msgs
25+
)
26+
# Export header files
27+
# target_include_directories(nav2_dynamic_motion_model PUBLIC
28+
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
29+
# $<INSTALL_INTERFACE:include>
30+
# )
31+
32+
install(DIRECTORY include/
33+
DESTINATION include/${PROJECT_NAME}
34+
)
35+
# Install libraries
36+
install(
37+
TARGETS nav2_dynamic_motion_model
38+
EXPORT export_nav2_dynamic_motion_model
39+
LIBRARY DESTINATION lib
40+
ARCHIVE DESTINATION lib
41+
RUNTIME DESTINATION bin
42+
)
43+
44+
45+
if(BUILD_TESTING)
46+
find_package(ament_lint_auto REQUIRED)
47+
# the following line skips the linter which checks for copyrights
48+
# comment the line when a copyright and license is added to all source files
49+
set(ament_cmake_copyright_FOUND TRUE)
50+
# the following line skips cpplint (only works in a git repo)
51+
# comment the line when this package is in a git repo and when
52+
# a copyright and license is added to all source files
53+
set(ament_cmake_cpplint_FOUND TRUE)
54+
ament_lint_auto_find_test_dependencies()
55+
endif()
56+
57+
# Export library for other packages
58+
ament_export_include_directories(include)
59+
ament_export_libraries(nav2_dynamic_motion_model)
60+
61+
ament_package()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef NAV2_DYNAMIC_MOTION_MODEL__CONSTANT_VELOCITY_MODEL_HPP_
2+
#define NAV2_DYNAMIC_MOTION_MODEL__CONSTANT_VELOCITY_MODEL_HPP_
3+
4+
#include "nav2_dynamic_motion_model/motion_model_base.hpp"
5+
6+
7+
namespace nav2_dynamic_motion_model
8+
{
9+
10+
class ConstantVelocityModel : public MotionModelInterface
11+
{
12+
public:
13+
geometry_msgs::msg::Pose predictObstaclePose(
14+
const nav2_dynamic_msgs::msg::Obstacle &obstacle,
15+
double dt) const override;
16+
};
17+
18+
19+
} //namespace
20+
#endif //NAV2_DYNAMIC_MOTION_MODEL__CONSTANT_VELOCITY_MODEL_HPP_
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef NAV2_DYNAMIC_MOTION_MODEL__MOTION_MODEL_INTERFACE_HPP_
2+
#define NAV2_DYNAMIC_MOTION_MODEL__MOTION_MODEL_INTERFACE_HPP_
3+
4+
#include <geometry_msgs/msg/pose.hpp>
5+
#include <geometry_msgs/msg/pose_array.hpp>
6+
#include <geometry_msgs/msg/twist.hpp>
7+
#include <nav2_dynamic_msgs/msg/obstacle.hpp>
8+
#include <nav2_dynamic_msgs/msg/obstacle_array.hpp>
9+
10+
namespace nav2_dynamic_motion_model
11+
{
12+
13+
class MotionModelInterface
14+
{
15+
public:
16+
virtual ~MotionModelInterface() = default;
17+
18+
virtual geometry_msgs::msg::Pose predictObstaclePose(
19+
const nav2_dynamic_msgs::msg::Obstacle &obstacle,
20+
double dt) const = 0;
21+
22+
virtual geometry_msgs::msg::PoseArray predictObstaclePoseArray(
23+
const nav2_dynamic_msgs::msg::ObstacleArray &obstacle_array,
24+
double dt) const = 0;
25+
};
26+
27+
} //namespace
28+
#endif //NAV2_DYNAMIC_MOTION_MODEL__MOTION_MODEL_INTERFACE_HPP_
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>nav2_dynamic_motion_model</name>
5+
<version>0.0.0</version>
6+
<description>TODO: Package description</description>
7+
<maintainer email="[email protected]">Chirag Makwana</maintainer>
8+
<license>Apache-2.0</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<test_depend>ament_lint_auto</test_depend>
13+
<test_depend>ament_lint_common</test_depend>
14+
15+
<export>
16+
<build_type>ament_cmake</build_type>
17+
</export>
18+
</package>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef CONSTANT_VELOCITY_MODEL_HPP
2+
#define CONSTANT_VELOCITY_MODEL_HPP
3+
4+
#include "nav2_dynamic_motion_model/constant_velocity_model.hpp"
5+
6+
namespace nav2_dynamic_motion_model
7+
{
8+
9+
geometry_msgs::msg::Pose ConstantVelocityModel::predictObstaclePose(
10+
const nav2_dynamic_msgs::msg::Obstacle &obstacle,
11+
double dt) const
12+
{
13+
geometry_msgs::msg::Pose predicted_pose;
14+
predicted_pose.position.x = obstacle.position.x;
15+
predicted_pose.position.y = obstacle.position.y;
16+
predicted_pose.position.z = obstacle.position.z;
17+
18+
predicted_pose.position.x += obstacle.velocity.x * dt;
19+
predicted_pose.position.y += obstacle.velocity.y * dt;
20+
predicted_pose.position.z += obstacle.velocity.z * dt;
21+
return predicted_pose;
22+
}
23+
24+
}
25+
#endif // CONSTANT_VELOCITY_MODEL_HPP
26+

0 commit comments

Comments
 (0)