Skip to content

Commit 03b4d49

Browse files
Visualized Translated pose seems legit
1 parent 6a1c79a commit 03b4d49

30 files changed

Lines changed: 1080 additions & 0 deletions
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(convert_odom_to_pose_stamped CXX)
3+
4+
find_package(moveit_pro_package REQUIRED)
5+
moveit_pro_package()
6+
7+
set(THIS_PACKAGE_INCLUDE_DEPENDS moveit_pro_behavior_interface pluginlib)
8+
foreach(package IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
9+
find_package(${package} REQUIRED)
10+
endforeach()
11+
12+
add_library(
13+
convert_odom_to_pose_stamped
14+
SHARED
15+
src/convert_odom_to_pose_stamped.cpp
16+
src/register_behaviors.cpp)
17+
target_include_directories(
18+
convert_odom_to_pose_stamped
19+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
20+
$<INSTALL_INTERFACE:include>)
21+
ament_target_dependencies(convert_odom_to_pose_stamped
22+
${THIS_PACKAGE_INCLUDE_DEPENDS})
23+
24+
# Install Libraries
25+
install(
26+
TARGETS convert_odom_to_pose_stamped
27+
EXPORT convert_odom_to_pose_stampedTargets
28+
ARCHIVE DESTINATION lib
29+
LIBRARY DESTINATION lib
30+
RUNTIME DESTINATION bin
31+
INCLUDES
32+
DESTINATION include)
33+
34+
if(BUILD_TESTING)
35+
moveit_pro_behavior_test(convert_odom_to_pose_stamped)
36+
endif()
37+
38+
# Export the behavior plugins defined in this package so they are available to
39+
# plugin loaders that load the behavior base class library from the
40+
# moveit_studio_behavior package.
41+
pluginlib_export_plugin_description_file(
42+
moveit_pro_behavior_interface convert_odom_to_pose_stamped_plugin_description.xml)
43+
44+
ament_export_targets(convert_odom_to_pose_stampedTargets HAS_LIBRARY_TARGET)
45+
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
46+
ament_package()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
objectives:
2+
behavior_loader_plugins:
3+
convert_odom_to_pose_stamped:
4+
- "convert_odom_to_pose_stamped::ConvertOdomToPoseStampedBehaviorsLoader"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<library path="convert_odom_to_pose_stamped">
3+
<class
4+
type="convert_odom_to_pose_stamped::ConvertOdomToPoseStampedBehaviorsLoader"
5+
base_class_type="moveit_pro::behaviors::SharedResourcesNodeLoaderBase"
6+
/>
7+
</library>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#pragma once
2+
3+
#include <behaviortree_cpp/action_node.h>
4+
#include <moveit_pro_behavior_interface/get_required_ports.hpp>
5+
6+
7+
8+
9+
10+
namespace convert_odom_to_pose_stamped
11+
{
12+
/**
13+
* @brief TODO(...)
14+
*/
15+
class ConvertOdomToPoseStamped : public BT::SyncActionNode
16+
{
17+
public:
18+
/**
19+
* @brief Constructor for the convert_odom_to_pose_stamped behavior.
20+
* @param name The name of a particular instance of this Behavior. This will be set by the behavior tree factory when this Behavior is created within a new behavior tree.
21+
* @param config This contains runtime configuration info for this Behavior, such as the mapping between the Behavior's data ports on the behavior tree's blackboard. This will be set by the behavior tree factory when this Behavior is created within a new behavior tree.
22+
* @details An important limitation is that the members of the base Behavior class are not instantiated until after the initialize() function is called, so these classes should not be used within the constructor.
23+
*/
24+
ConvertOdomToPoseStamped(const std::string& name, const BT::NodeConfiguration& config);
25+
26+
27+
/**
28+
* @brief Implementation of the required providedPorts() function for the convert_odom_to_pose_stamped Behavior.
29+
* @details The BehaviorTree.CPP library requires that Behaviors must implement a static function named providedPorts() which defines their input and output ports. If the Behavior does not use any ports, this function must return an empty BT::PortsList.
30+
* This function returns a list of ports with their names and port info, which is used internally by the behavior tree.
31+
* @return convert_odom_to_pose_stamped does not expose any ports, so this function returns an empty list.
32+
*/
33+
static BT::PortsList providedPorts();
34+
35+
/**
36+
* @brief Implementation of the metadata() function for displaying metadata, such as Behavior description and
37+
* subcategory, in the MoveIt Studio Developer Tool.
38+
* @return A BT::KeyValueVector containing the Behavior metadata.
39+
*/
40+
static BT::KeyValueVector metadata();
41+
42+
/**
43+
* @brief Implementation of BT::SyncActionNode::tick() for ConvertOdomToPoseStamped.
44+
* @details This function is where the Behavior performs its work when the behavior tree is being run. Since ConvertOdomToPoseStamped is derived from BT::SyncActionNode, it is very important that its tick() function always finishes very quickly. If tick() blocks before returning, it will block execution of the entire behavior tree, which may have undesirable consequences for other Behaviors that require a fast update rate to work correctly.
45+
*/
46+
BT::NodeStatus tick() override;
47+
48+
};
49+
} // namespace convert_odom_to_pose_stamped
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<package format="3">
3+
<name>convert_odom_to_pose_stamped</name>
4+
<version>0.0.0</version>
5+
<description>This removes the twist part of the odom message so you can visualize/operate on the pose. </description>
6+
7+
<maintainer email="support@picknik.ai">
8+
MoveIt Pro User
9+
</maintainer>
10+
<author email="support@picknik.ai">
11+
MoveIt Pro User
12+
</author>
13+
14+
<license>TODO</license>
15+
16+
<buildtool_depend>ament_cmake</buildtool_depend>
17+
18+
<build_depend>moveit_pro_package</build_depend>
19+
20+
<depend>moveit_pro_behavior_interface</depend>
21+
22+
<test_depend>ament_cmake_ros</test_depend>
23+
<test_depend>ament_lint_auto</test_depend>
24+
<test_depend>ament_cmake_gtest</test_depend>
25+
26+
<export>
27+
<build_type>ament_cmake</build_type>
28+
</export>
29+
<buildtool_depend>python3-colcon-common-extensions</buildtool_depend>
30+
</package>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <convert_odom_to_pose_stamped/convert_odom_to_pose_stamped.hpp>
2+
3+
#include "spdlog/spdlog.h"
4+
5+
#include <geometry_msgs/msg/pose_stamped.hpp>
6+
#include <nav_msgs/msg/odometry.hpp>
7+
8+
9+
namespace
10+
{
11+
constexpr auto kPortIDOdometry = "odometry";
12+
constexpr auto kPortIDPoseStamped = "pose_stamped";
13+
} // namespace
14+
15+
namespace convert_odom_to_pose_stamped
16+
{
17+
ConvertOdomToPoseStamped::ConvertOdomToPoseStamped(const std::string& name, const BT::NodeConfiguration& config)
18+
: BT::SyncActionNode(name, config)
19+
{
20+
}
21+
22+
23+
BT::PortsList ConvertOdomToPoseStamped::providedPorts()
24+
{
25+
return BT::PortsList(
26+
{ BT::InputPort<nav_msgs::msg::Odometry>(kPortIDOdometry, "{odometry}",
27+
"The gnav_msgs::msg::Odometry message to "
28+
"convert."),
29+
BT::OutputPort<geometry_msgs::msg::PoseStamped>(kPortIDPoseStamped, "{pose_stamped}",
30+
"The converted geometry_msgs::msg::PoseStamped message.") });
31+
}
32+
33+
BT::KeyValueVector ConvertOdomToPoseStamped::metadata()
34+
{
35+
return { { "description", "Converts a nav_msgs::msg::Odometry message into a "
36+
"geometry_msgs::msg::PoseStamped message." },
37+
{ "subcategory", "Conversions" } };
38+
}
39+
40+
BT::NodeStatus ConvertOdomToPoseStamped::tick()
41+
{
42+
const auto ports = moveit_pro::behaviors::getRequiredInputs(
43+
getInput<nav_msgs::msg::Odometry>(kPortIDOdometry));
44+
45+
if (!ports.has_value())
46+
{
47+
spdlog::warn("Failed to get required value from input data port: {}", ports.error());
48+
return BT::NodeStatus::FAILURE;
49+
}
50+
51+
const auto& odom_msg = std::get<0>(ports.value());
52+
53+
geometry_msgs::msg::PoseStamped pose_out;
54+
pose_out.header = odom_msg.header;
55+
pose_out.pose = odom_msg.pose.pose;
56+
57+
setOutput(kPortIDPoseStamped, pose_out);
58+
59+
return BT::NodeStatus::SUCCESS;
60+
}
61+
62+
} // namespace convert_odom_to_pose_stamped
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <behaviortree_cpp/bt_factory.h>
2+
#include <moveit_pro_behavior_interface/behavior_context.hpp>
3+
#include <moveit_pro_behavior_interface/shared_resources_node_loader.hpp>
4+
5+
#include <convert_odom_to_pose_stamped/convert_odom_to_pose_stamped.hpp>
6+
7+
#include <pluginlib/class_list_macros.hpp>
8+
9+
namespace convert_odom_to_pose_stamped
10+
{
11+
class ConvertOdomToPoseStampedBehaviorsLoader : public moveit_pro::behaviors::SharedResourcesNodeLoaderBase
12+
{
13+
public:
14+
void registerBehaviors(BT::BehaviorTreeFactory& factory,
15+
[[maybe_unused]] const std::shared_ptr<moveit_pro::behaviors::BehaviorContext>& shared_resources) override
16+
{
17+
moveit_pro::behaviors::registerBehavior<ConvertOdomToPoseStamped>(factory, "ConvertOdomToPoseStamped");
18+
19+
}
20+
};
21+
} // namespace convert_odom_to_pose_stamped
22+
23+
PLUGINLIB_EXPORT_CLASS(convert_odom_to_pose_stamped::ConvertOdomToPoseStampedBehaviorsLoader,
24+
moveit_pro::behaviors::SharedResourcesNodeLoaderBase);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
find_package(ament_cmake_gtest REQUIRED)
2+
find_package(ament_cmake_ros REQUIRED)
3+
4+
ament_add_ros_isolated_gtest(test_behavior_plugins test_behavior_plugins.cpp)
5+
ament_target_dependencies(test_behavior_plugins ${THIS_PACKAGE_INCLUDE_DEPENDS})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <behaviortree_cpp/bt_factory.h>
4+
#include <moveit_pro_behavior_interface/shared_resources_node_loader.hpp>
5+
#include <pluginlib/class_loader.hpp>
6+
#include <rclcpp/node.hpp>
7+
8+
/**
9+
* @brief This test makes sure that the Behaviors provided in this package can be successfully registered and
10+
* instantiated by the behavior tree factory.
11+
*/
12+
TEST(BehaviorTests, test_load_behavior_plugins)
13+
{
14+
pluginlib::ClassLoader<moveit_pro::behaviors::SharedResourcesNodeLoaderBase> class_loader(
15+
"moveit_pro_behavior_interface", "moveit_pro::behaviors::SharedResourcesNodeLoaderBase");
16+
17+
auto node = std::make_shared<rclcpp::Node>("BehaviorTests");
18+
auto shared_resources = std::make_shared<moveit_pro::behaviors::BehaviorContext>(node);
19+
20+
BT::BehaviorTreeFactory factory;
21+
{
22+
auto plugin_instance = class_loader.createUniqueInstance("convert_odom_to_pose_stamped::ConvertOdomToPoseStampedBehaviorsLoader");
23+
ASSERT_NO_THROW(plugin_instance->registerBehaviors(factory, shared_resources));
24+
}
25+
26+
// Test that ClassLoader is able to find and instantiate each behavior using the package's plugin description info.
27+
EXPECT_NO_THROW(
28+
(void)factory.instantiateTreeNode("test_behavior_name", "ConvertOdomToPoseStamped", BT::NodeConfiguration()));
29+
}
30+
31+
int main(int argc, char** argv)
32+
{
33+
rclcpp::init(argc, argv);
34+
35+
testing::InitGoogleTest(&argc, argv);
36+
return RUN_ALL_TESTS();
37+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
project(convert_pose_stamped_to_transform_stamped CXX)
3+
4+
find_package(moveit_pro_package REQUIRED)
5+
moveit_pro_package()
6+
7+
set(THIS_PACKAGE_INCLUDE_DEPENDS moveit_pro_behavior_interface pluginlib)
8+
foreach(package IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
9+
find_package(${package} REQUIRED)
10+
endforeach()
11+
12+
add_library(
13+
convert_pose_stamped_to_transform_stamped
14+
SHARED
15+
src/convert_pose_stamped_to_transform_stamped.cpp
16+
src/register_behaviors.cpp)
17+
target_include_directories(
18+
convert_pose_stamped_to_transform_stamped
19+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
20+
$<INSTALL_INTERFACE:include>)
21+
ament_target_dependencies(convert_pose_stamped_to_transform_stamped
22+
${THIS_PACKAGE_INCLUDE_DEPENDS})
23+
24+
# Install Libraries
25+
install(
26+
TARGETS convert_pose_stamped_to_transform_stamped
27+
EXPORT convert_pose_stamped_to_transform_stampedTargets
28+
ARCHIVE DESTINATION lib
29+
LIBRARY DESTINATION lib
30+
RUNTIME DESTINATION bin
31+
INCLUDES
32+
DESTINATION include)
33+
34+
if(BUILD_TESTING)
35+
moveit_pro_behavior_test(convert_pose_stamped_to_transform_stamped)
36+
endif()
37+
38+
# Export the behavior plugins defined in this package so they are available to
39+
# plugin loaders that load the behavior base class library from the
40+
# moveit_studio_behavior package.
41+
pluginlib_export_plugin_description_file(
42+
moveit_pro_behavior_interface convert_pose_stamped_to_transform_stamped_plugin_description.xml)
43+
44+
ament_export_targets(convert_pose_stamped_to_transform_stampedTargets HAS_LIBRARY_TARGET)
45+
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
46+
ament_package()

0 commit comments

Comments
 (0)