0
$\begingroup$

I have a node class shown below and I want to call its setCloud method from another class but it gives me the error:

error: ‘using element_type = class rclcpp::Node’ {aka ‘class rclcpp::Node’} has no member named ‘setCloud’ 422 | node_->setCloud(data);

My Node class:

class ROSNode : public rclcpp::Node
{
public:
    ROSNode() : Node("ros_node")
    {
        msg.header.frame_id = "t";
        points_publisher = this->create_publisher<sensor_msgs::msg::PointCloud2>("/t_points", 10);
    }


    void setCloud(typename pcl::PointCloud<pcl::PointXYZI> cloud)
    {
        pcl::toROSMsg(cloud, msg);
        msg.header.stamp = get_clock()->now();
        points_publisher->publish(msg);
    };

private:

sensor_msgs::msg::PointCloud2 msg;
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr points_publisher;
};

Header for the other class:

class testclass{
public:
    testclass();
    virtual ~testclass();

protected:
    ROSNode::SharedPtr node_;
    void transmitTargetDataROS(pcl::PointCloud<pcl::PointXYZI> data);

};

Source file for the other class:

testclass::testclass(): node_(std::make_shared<ROSNode>())
{
    rclcpp::spin(node_);
}


void testclass::transmitTargetDataROS(pcl::PointCloud<pcl::PointXYZI> data)
{
    node_->setCloud(data);
}

I copied only relevant parts from the files.

$\endgroup$

1 Answer 1

1
$\begingroup$

ROSNode::SharedPtr is a typedef inside rclcpp::Node that is always a std::shared_ptr<rclcpp::Node>. As such, it cannot inherit the setCloud method from your custom node.

Juste replace with an explicit std::shared_ptr<ROSNode> and you should be fine.

Not relevant for the question but I do not get the use of typename in the setCloud argument. Additionally, the point cloud could be passed by (const) reference at it is probably a pretty large object.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.