Skip to content

File continental_ars548_hw_interface_wrapper.hpp

File List > include > nebula_continental > continental_ars548_hw_interface_wrapper.hpp

Go to the documentation of this file

// Copyright 2024 TIER IV, Inc.
//
// 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.

#pragma once

#include "nebula_core_ros/agnocast_wrapper/node.hpp"
#include "nebula_core_ros/parameter_descriptors.hpp"

#include <nebula_continental_common/continental_ars548.hpp>
#include <nebula_continental_hw_interfaces/continental_ars548_hw_interface.hpp>
#include <nebula_core_common/util/rate_checker.hpp>
#include <rclcpp/rclcpp.hpp>

#include <continental_srvs/srv/continental_ars548_set_network_configuration.hpp>
#include <continental_srvs/srv/continental_ars548_set_radar_parameters.hpp>
#include <continental_srvs/srv/continental_ars548_set_sensor_mounting.hpp>
#include <continental_srvs/srv/continental_ars548_set_vehicle_parameters.hpp>
#include <geometry_msgs/msg/accel_with_covariance_stamped.hpp>
#include <geometry_msgs/msg/twist_with_covariance_stamped.hpp>
#include <std_msgs/msg/float32.hpp>

#include <memory>

namespace nebula::ros
{
class ContinentalARS548HwInterfaceWrapper
{
public:
  ContinentalARS548HwInterfaceWrapper(
    nebula::agnocast_wrapper::Node * const parent_node,
    std::shared_ptr<const drivers::continental_ars548::ContinentalARS548SensorConfiguration> &
      config);

  Status sensor_interface_start();

  void on_config_change(
    const std::shared_ptr<const drivers::continental_ars548::ContinentalARS548SensorConfiguration> &
      new_config_ptr);

  nebula::Status status();

  std::shared_ptr<drivers::continental_ars548::ContinentalARS548HwInterface> hw_interface() const;

private:
  void odometry_callback(
    NEBULA_MESSAGE_CONST_SHARED_PTR(geometry_msgs::msg::TwistWithCovarianceStamped) msg);

  void acceleration_callback(
    NEBULA_MESSAGE_CONST_SHARED_PTR(geometry_msgs::msg::AccelWithCovarianceStamped) msg);

  void steering_angle_callback(NEBULA_MESSAGE_CONST_SHARED_PTR(std_msgs::msg::Float32) msg);

  void set_network_configuration_request_callback(
    const std::shared_ptr<continental_srvs::srv::ContinentalArs548SetNetworkConfiguration::Request>
      request,
    const std::shared_ptr<continental_srvs::srv::ContinentalArs548SetNetworkConfiguration::Response>
      response);

  void set_sensor_mounting_request_callback(
    const std::shared_ptr<continental_srvs::srv::ContinentalArs548SetSensorMounting::Request>
      request,
    const std::shared_ptr<continental_srvs::srv::ContinentalArs548SetSensorMounting::Response>
      response);

  void set_vehicle_parameters_request_callback(
    const std::shared_ptr<continental_srvs::srv::ContinentalArs548SetVehicleParameters::Request>
      request,
    const std::shared_ptr<continental_srvs::srv::ContinentalArs548SetVehicleParameters::Response>
      response);

  void set_radar_parameters_request_callback(
    const std::shared_ptr<continental_srvs::srv::ContinentalArs548SetRadarParameters::Request>
      request,
    const std::shared_ptr<continental_srvs::srv::ContinentalArs548SetRadarParameters::Response>
      response);

  nebula::agnocast_wrapper::Node * const parent_node_;
  std::shared_ptr<drivers::continental_ars548::ContinentalARS548HwInterface> hw_interface_{};
  rclcpp::Logger logger_;
  nebula::Status status_{};
  std::shared_ptr<const nebula::drivers::continental_ars548::ContinentalARS548SensorConfiguration>
    config_ptr_{};

  NEBULA_SUBSCRIPTION_PTR(geometry_msgs::msg::TwistWithCovarianceStamped) odometry_sub_ {};
  NEBULA_SUBSCRIPTION_PTR(geometry_msgs::msg::AccelWithCovarianceStamped) acceleration_sub_ {};
  NEBULA_SUBSCRIPTION_PTR(std_msgs::msg::Float32) steering_angle_sub_ {};

  nebula::util::RateChecker odometry_rate_checker_;
  nebula::util::RateChecker acceleration_rate_checker_;
  nebula::util::RateChecker steering_angle_rate_checker_;

  bool standstill_{true};

  NEBULA_SERVICE_PTR(continental_srvs::srv::ContinentalArs548SetNetworkConfiguration)
  set_network_configuration_service_server_{};
  NEBULA_SERVICE_PTR(continental_srvs::srv::ContinentalArs548SetSensorMounting)
  set_sensor_mounting_service_server_{};
  NEBULA_SERVICE_PTR(continental_srvs::srv::ContinentalArs548SetVehicleParameters)
  set_vehicle_parameters_service_server_{};
  NEBULA_SERVICE_PTR(continental_srvs::srv::ContinentalArs548SetRadarParameters)
  set_radar_parameters_service_server_{};
};
}  // namespace nebula::ros