|
| 1 | +// Copyright 2026 PickNik Inc. |
| 2 | +// All rights reserved. |
| 3 | +// |
| 4 | +// Unauthorized copying of this code base via any medium is strictly prohibited. |
| 5 | +// Proprietary and confidential. |
| 6 | + |
| 7 | +#pragma once |
| 8 | + |
| 9 | +#include <behaviortree_cpp/action_node.h> |
| 10 | +#include <moveit_pro_behavior/behaviors/visualization/ros_publisher_handle.hpp> |
| 11 | +#include <moveit_pro_behavior_interface/behavior_context.hpp> |
| 12 | +#include <moveit_pro_behavior_interface/shared_resources_node.hpp> |
| 13 | + |
| 14 | +namespace lab_sim_behaviors |
| 15 | +{ |
| 16 | +/** |
| 17 | + * @brief Computes a grid of place positions within a tray detected via its AprilTag. |
| 18 | + * |
| 19 | + * @details Given an array of AprilTag detections and camera intrinsics, this Behavior finds the |
| 20 | + * tray's AprilTag by ID, uses its 3D pose plus a known offset to locate the tray center, then |
| 21 | + * generates a grid of place positions (multiple columns per row). Rows fill from the far end |
| 22 | + * of the tray toward the tag (top-to-bottom). Positions are transformed from the camera frame |
| 23 | + * to the world frame with a fixed gripper-down orientation. |
| 24 | + * |
| 25 | + * If an input image is provided, the Behavior annotates it with green circles sized to match |
| 26 | + * the bottle diameter at each computed place position and publishes the result. |
| 27 | + * |
| 28 | + * | Data Port Name | Port Type | Object Type | |
| 29 | + * | ----------------------- | --------- | --------------------------------------------------- | |
| 30 | + * | detections | input | moveit_studio_vision_msgs::msg::ObjectDetectionArray | |
| 31 | + * | camera_info | input | sensor_msgs::msg::CameraInfo | |
| 32 | + * | input_image | input | sensor_msgs::msg::Image (optional) | |
| 33 | + * | tray_apriltag_id | input | int | |
| 34 | + * | num_rows | input | int | |
| 35 | + * | columns_per_row | input | int | |
| 36 | + * | row_spacing | input | double | |
| 37 | + * | column_spacing | input | double | |
| 38 | + * | tag_to_tray_center | input | double | |
| 39 | + * | bottle_diameter | input | double | |
| 40 | + * | visualization_topic | input | std::string | |
| 41 | + * | place_positions | output | std::vector<geometry_msgs::msg::PoseStamped> | |
| 42 | + */ |
| 43 | +class ComputeTrayPlacePositionsUsingAprilTags final |
| 44 | + : public moveit_pro::behaviors::SharedResourcesNode<BT::SyncActionNode> |
| 45 | +{ |
| 46 | +public: |
| 47 | + ComputeTrayPlacePositionsUsingAprilTags( |
| 48 | + const std::string& name, const BT::NodeConfiguration& config, |
| 49 | + const std::shared_ptr<moveit_pro::behaviors::BehaviorContext>& shared_resources, |
| 50 | + std::unique_ptr<moveit_pro::behaviors::ROSPublisherHandle> ros_publisher_interface = |
| 51 | + std::make_unique<moveit_pro::behaviors::ROSPublisherHandle>()); |
| 52 | + |
| 53 | + static BT::PortsList providedPorts(); |
| 54 | + |
| 55 | + static BT::KeyValueVector metadata(); |
| 56 | + |
| 57 | + BT::NodeStatus tick() override; |
| 58 | + |
| 59 | +private: |
| 60 | + std::unique_ptr<moveit_pro::behaviors::ROSPublisherHandle> ros_publisher_interface_; |
| 61 | +}; |
| 62 | +} // namespace lab_sim_behaviors |
0 commit comments