Skip to content

Commit f5a975c

Browse files
suchkristenwowJWhitleyWork
authored andcommitted
Visualized Translated pose seems legit
1 parent e5b70f9 commit f5a975c

30 files changed

Lines changed: 1272 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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#pragma once
2+
3+
#include <behaviortree_cpp/action_node.h>
4+
#include <moveit_pro_behavior_interface/get_required_ports.hpp>
5+
6+
namespace convert_odom_to_pose_stamped
7+
{
8+
/**
9+
* @brief TODO(...)
10+
*/
11+
class ConvertOdomToPoseStamped : public BT::SyncActionNode
12+
{
13+
public:
14+
/**
15+
* @brief Constructor for the convert_odom_to_pose_stamped behavior.
16+
* @param name The name of a particular instance of this Behavior. This will be set by the behavior tree factory when
17+
* this Behavior is created within a new behavior tree.
18+
* @param config This contains runtime configuration info for this Behavior, such as the mapping between the
19+
* Behavior's data ports on the behavior tree's blackboard. This will be set by the behavior tree factory when this
20+
* Behavior is created within a new behavior tree.
21+
* @details An important limitation is that the members of the base Behavior class are not instantiated until after
22+
* 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+
* @brief Implementation of the required providedPorts() function for the convert_odom_to_pose_stamped Behavior.
28+
* @details The BehaviorTree.CPP library requires that Behaviors must implement a static function named
29+
* providedPorts() which defines their input and output ports. If the Behavior does not use any ports, this function
30+
* must return an empty BT::PortsList. This function returns a list of ports with their names and port info, which is
31+
* used internally by the behavior tree.
32+
* @return convert_odom_to_pose_stamped does not expose any ports, so this function returns an empty list.
33+
*/
34+
static BT::PortsList providedPorts();
35+
36+
/**
37+
* @brief Implementation of the metadata() function for displaying metadata, such as Behavior description and
38+
* subcategory, in the MoveIt Studio Developer Tool.
39+
* @return A BT::KeyValueVector containing the Behavior metadata.
40+
*/
41+
static BT::KeyValueVector metadata();
42+
43+
/**
44+
* @brief Implementation of BT::SyncActionNode::tick() for ConvertOdomToPoseStamped.
45+
* @details This function is where the Behavior performs its work when the behavior tree is being run. Since
46+
* ConvertOdomToPoseStamped is derived from BT::SyncActionNode, it is very important that its tick() function always
47+
* finishes very quickly. If tick() blocks before returning, it will block execution of the entire behavior tree,
48+
* which may have undesirable consequences for other Behaviors that require a fast update rate to work correctly.
49+
*/
50+
BT::NodeStatus tick() override;
51+
};
52+
} // namespace convert_odom_to_pose_stamped
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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>
6+
This removes the twist part of the odom message so you can visualize/operate
7+
on the pose.
8+
</description>
9+
10+
<maintainer email="support@picknik.ai">MoveIt Pro User</maintainer>
11+
<author email="support@picknik.ai">MoveIt Pro User</author>
12+
13+
<license>TODO</license>
14+
15+
<buildtool_depend>ament_cmake</buildtool_depend>
16+
17+
<build_depend>moveit_pro_package</build_depend>
18+
19+
<depend>moveit_pro_behavior_interface</depend>
20+
21+
<test_depend>ament_cmake_ros</test_depend>
22+
<test_depend>ament_lint_auto</test_depend>
23+
<test_depend>ament_cmake_gtest</test_depend>
24+
25+
<export>
26+
<build_type>ament_cmake</build_type>
27+
</export>
28+
<buildtool_depend>python3-colcon-common-extensions</buildtool_depend>
29+
</package>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
namespace
9+
{
10+
constexpr auto kPortIDOdometry = "odometry";
11+
constexpr auto kPortIDPoseStamped = "pose_stamped";
12+
} // namespace
13+
14+
namespace convert_odom_to_pose_stamped
15+
{
16+
ConvertOdomToPoseStamped::ConvertOdomToPoseStamped(const std::string& name, const BT::NodeConfiguration& config)
17+
: BT::SyncActionNode(name, config)
18+
{
19+
}
20+
21+
BT::PortsList ConvertOdomToPoseStamped::providedPorts()
22+
{
23+
return BT::PortsList(
24+
{ BT::InputPort<nav_msgs::msg::Odometry>(kPortIDOdometry, "{odometry}",
25+
"The gnav_msgs::msg::Odometry message to "
26+
"convert."),
27+
BT::OutputPort<geometry_msgs::msg::PoseStamped>(kPortIDPoseStamped, "{pose_stamped}",
28+
"The converted geometry_msgs::msg::PoseStamped message.") });
29+
}
30+
31+
BT::KeyValueVector ConvertOdomToPoseStamped::metadata()
32+
{
33+
return { { "description", "Converts a nav_msgs::msg::Odometry message into a "
34+
"geometry_msgs::msg::PoseStamped message." },
35+
{ "subcategory", "Conversions" } };
36+
}
37+
38+
BT::NodeStatus ConvertOdomToPoseStamped::tick()
39+
{
40+
const auto ports = moveit_pro::behaviors::getRequiredInputs(getInput<nav_msgs::msg::Odometry>(kPortIDOdometry));
41+
42+
if (!ports.has_value())
43+
{
44+
spdlog::warn("Failed to get required value from input data port: {}", ports.error());
45+
return BT::NodeStatus::FAILURE;
46+
}
47+
48+
const auto& odom_msg = std::get<0>(ports.value());
49+
50+
geometry_msgs::msg::PoseStamped pose_out;
51+
pose_out.header = odom_msg.header;
52+
pose_out.pose = odom_msg.pose.pose;
53+
54+
setOutput(kPortIDPoseStamped, pose_out);
55+
56+
return BT::NodeStatus::SUCCESS;
57+
}
58+
59+
} // 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(
15+
BT::BehaviorTreeFactory& factory,
16+
[[maybe_unused]] const std::shared_ptr<moveit_pro::behaviors::BehaviorContext>& shared_resources) override
17+
{
18+
moveit_pro::behaviors::registerBehavior<ConvertOdomToPoseStamped>(factory, "ConvertOdomToPoseStamped");
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 =
23+
class_loader.createUniqueInstance("convert_odom_to_pose_stamped::ConvertOdomToPoseStampedBehaviorsLoader");
24+
ASSERT_NO_THROW(plugin_instance->registerBehaviors(factory, shared_resources));
25+
}
26+
27+
// Test that ClassLoader is able to find and instantiate each behavior using the package's plugin description info.
28+
EXPECT_NO_THROW(
29+
(void)factory.instantiateTreeNode("test_behavior_name", "ConvertOdomToPoseStamped", BT::NodeConfiguration()));
30+
}
31+
32+
int main(int argc, char** argv)
33+
{
34+
rclcpp::init(argc, argv);
35+
36+
testing::InitGoogleTest(&argc, argv);
37+
return RUN_ALL_TESTS();
38+
}
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)