Program Listing for File body.hpp
↰ Return to documentation for file (include/hri/body.hpp
)
// Copyright (c) 2023 PAL Robotics S.L. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef HRI__BODY_HPP_
#define HRI__BODY_HPP_
#include <memory>
#include <optional>
#include <string>
#include "hri_msgs/msg/normalized_region_of_interest2_d.hpp"
#include "hri_msgs/msg/skeleton2_d.hpp"
#include "opencv2/core.hpp"
#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/image.hpp"
#include "std_msgs/msg/string.hpp"
#include "tf2_ros/buffer.h"
#include "hri/feature_tracker.hpp"
#include "hri/types.hpp"
namespace hri
{
// TODO(LJU): possibly subscribe also to the /joint_states, gesture and /posture sub-topics
class Body : public FeatureTracker, public std::enable_shared_from_this<Body>
{
friend class HRIListener; // for invalidate()
public:
Body(
ID id,
NodeInterfaces node_interfaces,
rclcpp::CallbackGroup::SharedPtr callback_group,
const tf2::BufferCore & tf_buffer,
const std::string & reference_frame);
virtual ~Body();
std::optional<cv::Rect2f> roi() const {return roi_;}
std::optional<cv::Mat> cropped() const {return cropped_;}
std::optional<SkeletalKeypoints> skeleton() const {return skeleton_;}
std::optional<std::string> bodyDescription() const {return body_description_;}
private:
void onRoI(hri_msgs::msg::NormalizedRegionOfInterest2D::ConstSharedPtr msg);
void onCropped(sensor_msgs::msg::Image::ConstSharedPtr msg);
void onSkeleton(hri_msgs::msg::Skeleton2D::ConstSharedPtr msg);
void onBodyDescription(std_msgs::msg::String::ConstSharedPtr msg);
void invalidate();
std::optional<cv::Rect2f> roi_;
std::optional<cv::Mat> cropped_;
std::optional<SkeletalKeypoints> skeleton_;
std::optional<std::string> body_description_;
rclcpp::Subscription<hri_msgs::msg::NormalizedRegionOfInterest2D>::SharedPtr roi_subscriber_;
rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr cropped_subscriber_;
rclcpp::Subscription<hri_msgs::msg::Skeleton2D>::SharedPtr skeleton_subscriber_;
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr body_description_subscriber_;
};
typedef std::shared_ptr<Body> BodyPtr;
typedef std::shared_ptr<const Body> ConstBodyPtr;
} // namespace hri
#endif // HRI__BODY_HPP_