Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hesai): multicast support #187

Merged
merged 8 commits into from
Sep 7, 2024
Merged
3 changes: 3 additions & 0 deletions nebula_common/include/nebula_common/hesai/hesai_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace drivers
/// @brief struct for Hesai sensor configuration
struct HesaiSensorConfiguration : public LidarConfigurationBase
{
std::string multicast_ip;
knzo25 marked this conversation as resolved.
Show resolved Hide resolved
uint16_t gnss_port{};
double scan_phase{};
double dual_return_distance_threshold{};
Expand All @@ -54,6 +55,8 @@ inline std::ostream & operator<<(std::ostream & os, HesaiSensorConfiguration con
{
os << "Hesai Sensor Configuration:" << '\n';
os << (LidarConfigurationBase)(arg) << '\n';
os << "Multicast: "
<< (arg.multicast_ip.empty() ? "disabled" : "enabled, group " + arg.multicast_ip) << '\n';
os << "GNSS Port: " << arg.gnss_port << '\n';
os << "Scan Phase: " << arg.scan_phase << '\n';
os << "Rotation Speed: " << arg.rotation_speed << '\n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,15 @@ Status HesaiHwInterface::SensorInterfaceStart()
{
try {
std::cout << "Starting UDP server on: " << *sensor_configuration_ << std::endl;
cloud_udp_driver_->init_receiver(
sensor_configuration_->host_ip, sensor_configuration_->data_port);
if (sensor_configuration_->multicast_ip.empty()) {
cloud_udp_driver_->init_receiver(
sensor_configuration_->host_ip, sensor_configuration_->data_port);
} else {
cloud_udp_driver_->init_receiver(
sensor_configuration_->multicast_ip, sensor_configuration_->data_port,
sensor_configuration_->host_ip, sensor_configuration_->data_port);
cloud_udp_driver_->receiver()->setMulticast(true);
}
#ifdef WITH_DEBUG_STDOUT_HESAI_HW_INTERFACE
PrintError("init ok");
#endif
Expand All @@ -165,8 +172,8 @@ Status HesaiHwInterface::SensorInterfaceStart()
#endif
} catch (const std::exception & ex) {
Status status = Status::UDP_CONNECTION_ERROR;
std::cerr << status << sensor_configuration_->sensor_ip << ","
<< sensor_configuration_->data_port << std::endl;
std::cerr << status << " for " << sensor_configuration_->sensor_ip << ":"
<< sensor_configuration_->data_port << " - " << ex.what() << std::endl;
return status;
}
return Status::OK;
Expand Down Expand Up @@ -839,10 +846,13 @@ HesaiStatus HesaiHwInterface::CheckAndSetConfig(
<< static_cast<int>(hesai_config.dest_ipaddr[2]) << "."
<< static_cast<int>(hesai_config.dest_ipaddr[3]);
auto current_host_addr = ss.str();
if (sensor_configuration->host_ip != current_host_addr) {
auto desired_host_addr = sensor_configuration->multicast_ip.empty()
? sensor_configuration->host_ip
: sensor_configuration->multicast_ip;
if (desired_host_addr != current_host_addr) {
set_flg = true;
PrintInfo("current lidar dest_ipaddr: " + current_host_addr);
PrintInfo("current configuration host_ip: " + sensor_configuration->host_ip);
PrintInfo("current configuration host_ip: " + desired_host_addr);
}

auto current_host_dport = hesai_config.dest_LiDAR_udp_port;
Expand All @@ -867,7 +877,7 @@ HesaiStatus HesaiHwInterface::CheckAndSetConfig(

if (set_flg) {
std::vector<std::string> list_string;
boost::split(list_string, sensor_configuration->host_ip, boost::is_any_of("."));
boost::split(list_string, desired_host_addr, boost::is_any_of("."));
std::thread t([this, sensor_configuration, list_string] {
SetDestinationIp(
std::stoi(list_string[0]), std::stoi(list_string[1]), std::stoi(list_string[2]),
Expand Down
1 change: 1 addition & 0 deletions nebula_ros/config/lidar/hesai/Pandar128E4X.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ros__parameters:
host_ip: 255.255.255.255
sensor_ip: 192.168.1.201
multicast_ip: ""
data_port: 2368
gnss_port: 10110
packet_mtu_size: 1500
Expand Down
1 change: 1 addition & 0 deletions nebula_ros/config/lidar/hesai/Pandar40P.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ros__parameters:
host_ip: 255.255.255.255
sensor_ip: 192.168.1.201
multicast_ip: ""
data_port: 2368
gnss_port: 10110
packet_mtu_size: 1500
Expand Down
1 change: 1 addition & 0 deletions nebula_ros/config/lidar/hesai/Pandar64.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ros__parameters:
host_ip: 255.255.255.255
sensor_ip: 192.168.1.201
multicast_ip: ""
data_port: 2368
gnss_port: 10110
packet_mtu_size: 1500
Expand Down
1 change: 1 addition & 0 deletions nebula_ros/config/lidar/hesai/PandarAT128.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ros__parameters:
host_ip: 255.255.255.255
sensor_ip: 192.168.1.201
multicast_ip: ""
data_port: 2368
gnss_port: 10110
packet_mtu_size: 1500
Expand Down
1 change: 1 addition & 0 deletions nebula_ros/config/lidar/hesai/PandarQT128.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ros__parameters:
host_ip: 255.255.255.255
sensor_ip: 192.168.1.201
multicast_ip: ""
data_port: 2368
gnss_port: 10110
packet_mtu_size: 1500
Expand Down
1 change: 1 addition & 0 deletions nebula_ros/config/lidar/hesai/PandarQT64.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ros__parameters:
host_ip: 255.255.255.255
sensor_ip: 192.168.1.201
multicast_ip: ""
data_port: 2368
gnss_port: 10110
packet_mtu_size: 1500
Expand Down
1 change: 1 addition & 0 deletions nebula_ros/config/lidar/hesai/PandarXT32.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ros__parameters:
host_ip: 255.255.255.255
sensor_ip: 192.168.1.201
multicast_ip: ""
data_port: 2368
gnss_port: 10110
packet_mtu_size: 1500
Expand Down
1 change: 1 addition & 0 deletions nebula_ros/config/lidar/hesai/PandarXT32M.param.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ros__parameters:
host_ip: 255.255.255.255
sensor_ip: 192.168.1.201
multicast_ip: ""
data_port: 2368
gnss_port: 10110
packet_mtu_size: 1500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ContinentalARS548HwInterfaceWrapper

/// @brief Callback to send the steering angle information to the radar device
/// @param msg The steering angle message
void SteeringAngleCallback(const std_msgs::msg::Float32::SharedPtr msg);
void steeringAngleCallback(const std_msgs::msg::Float32::SharedPtr msg);
knzo25 marked this conversation as resolved.
Show resolved Hide resolved

/// @brief Service callback to set the new sensor ip
/// @param request service request
Expand Down
4 changes: 4 additions & 0 deletions nebula_ros/schema/Pandar128E4X.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"sensor_ip": {
"$ref": "sub/communication.json#/definitions/sensor_ip"
},
"multicast_ip": {
"$ref": "sub/lidar_hesai.json#/definitions/multicast_ip"
},
"data_port": {
"$ref": "sub/communication.json#/definitions/data_port"
},
Expand Down Expand Up @@ -97,6 +100,7 @@
"required": [
"host_ip",
"sensor_ip",
"multicast_ip",
"data_port",
"gnss_port",
"packet_mtu_size",
Expand Down
4 changes: 4 additions & 0 deletions nebula_ros/schema/Pandar40P.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"sensor_ip": {
"$ref": "sub/communication.json#/definitions/sensor_ip"
},
"multicast_ip": {
"$ref": "sub/lidar_hesai.json#/definitions/multicast_ip"
},
"data_port": {
"$ref": "sub/communication.json#/definitions/data_port"
},
Expand Down Expand Up @@ -88,6 +91,7 @@
"required": [
"host_ip",
"sensor_ip",
"multicast_ip",
"data_port",
"gnss_port",
"packet_mtu_size",
Expand Down
4 changes: 4 additions & 0 deletions nebula_ros/schema/Pandar64.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"sensor_ip": {
"$ref": "sub/communication.json#/definitions/sensor_ip"
},
"multicast_ip": {
"$ref": "sub/lidar_hesai.json#/definitions/multicast_ip"
},
"data_port": {
"$ref": "sub/communication.json#/definitions/data_port"
},
Expand Down Expand Up @@ -85,6 +88,7 @@
"required": [
"host_ip",
"sensor_ip",
"multicast_ip",
"data_port",
"gnss_port",
"packet_mtu_size",
Expand Down
4 changes: 4 additions & 0 deletions nebula_ros/schema/PandarAT128.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"sensor_ip": {
"$ref": "sub/communication.json#/definitions/sensor_ip"
},
"multicast_ip": {
"$ref": "sub/lidar_hesai.json#/definitions/multicast_ip"
},
"data_port": {
"$ref": "sub/communication.json#/definitions/data_port"
},
Expand Down Expand Up @@ -105,6 +108,7 @@
"required": [
"host_ip",
"sensor_ip",
"multicast_ip",
"data_port",
"gnss_port",
"packet_mtu_size",
Expand Down
4 changes: 4 additions & 0 deletions nebula_ros/schema/PandarQT128.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"sensor_ip": {
"$ref": "sub/communication.json#/definitions/sensor_ip"
},
"multicast_ip": {
"$ref": "sub/lidar_hesai.json#/definitions/multicast_ip"
},
"data_port": {
"$ref": "sub/communication.json#/definitions/data_port"
},
Expand Down Expand Up @@ -91,6 +94,7 @@
"required": [
"host_ip",
"sensor_ip",
"multicast_ip",
"data_port",
"gnss_port",
"packet_mtu_size",
Expand Down
4 changes: 4 additions & 0 deletions nebula_ros/schema/PandarQT64.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"sensor_ip": {
"$ref": "sub/communication.json#/definitions/sensor_ip"
},
"multicast_ip": {
"$ref": "sub/lidar_hesai.json#/definitions/multicast_ip"
},
"data_port": {
"$ref": "sub/communication.json#/definitions/data_port"
},
Expand Down Expand Up @@ -88,6 +91,7 @@
"required": [
"host_ip",
"sensor_ip",
"multicast_ip",
"data_port",
"gnss_port",
"packet_mtu_size",
Expand Down
4 changes: 4 additions & 0 deletions nebula_ros/schema/PandarXT32.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"sensor_ip": {
"$ref": "sub/communication.json#/definitions/sensor_ip"
},
"multicast_ip": {
"$ref": "sub/lidar_hesai.json#/definitions/multicast_ip"
},
"data_port": {
"$ref": "sub/communication.json#/definitions/data_port"
},
Expand Down Expand Up @@ -91,6 +94,7 @@
"required": [
"host_ip",
"sensor_ip",
"multicast_ip",
"data_port",
"gnss_port",
"packet_mtu_size",
Expand Down
4 changes: 4 additions & 0 deletions nebula_ros/schema/PandarXT32M.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"sensor_ip": {
"$ref": "sub/communication.json#/definitions/sensor_ip"
},
"multicast_ip": {
"$ref": "sub/lidar_hesai.json#/definitions/multicast_ip"
},
"data_port": {
"$ref": "sub/communication.json#/definitions/data_port"
},
Expand Down Expand Up @@ -91,6 +94,7 @@
"required": [
"host_ip",
"sensor_ip",
"multicast_ip",
"data_port",
"gnss_port",
"packet_mtu_size",
Expand Down
7 changes: 7 additions & 0 deletions nebula_ros/schema/sub/lidar_hesai.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
"minimum": 300,
"maximum": 1200,
"multipleOf": 60
},
"multicast_ip": {
"type": "string",
"default": "\"\"",
"pattern": "(^((22[4-9]|23[0-9])\\.)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){2}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$)|",
"readOnly": true,
"description": "Multicast IPv4 address (leave empty to disable multicast)."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ void ContinentalARS548HwInterfaceWrapper::SensorInterfaceStart()
steering_angle_sub_ = parent_node_->create_subscription<std_msgs::msg::Float32>(
"steering_angle_input", rclcpp::SensorDataQoS(),
std::bind(
&ContinentalARS548HwInterfaceWrapper::SteeringAngleCallback, this, std::placeholders::_1));
&::nebula::ros::ContinentalARS548HwInterfaceWrapper::steeringAngleCallback, this,
std::placeholders::_1));

set_network_configuration_service_server_ =
parent_node_->create_service<continental_srvs::srv::ContinentalArs548SetNetworkConfiguration>(
Expand Down Expand Up @@ -151,7 +152,7 @@ void ContinentalARS548HwInterfaceWrapper::AccelerationCallback(
hw_interface_->SetAccelerationLongitudinalCog(msg->accel.accel.linear.x);
}

void ContinentalARS548HwInterfaceWrapper::SteeringAngleCallback(
void ContinentalARS548HwInterfaceWrapper::steeringAngleCallback(
const std_msgs::msg::Float32::SharedPtr msg)
{
constexpr float rad_to_deg = 180.f / M_PI;
Expand Down
5 changes: 5 additions & 0 deletions nebula_ros/src/hesai/hesai_ros_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include "nebula_ros/hesai/hesai_ros_wrapper.hpp"

#include "nebula_ros/common/parameter_descriptors.hpp"

#include <string>

#pragma clang diagnostic ignored "-Wbitwise-instead-of-logical"

namespace nebula
Expand Down Expand Up @@ -77,6 +81,7 @@ nebula::Status HesaiRosWrapper::DeclareAndGetSensorConfigParams()

config.host_ip = declare_parameter<std::string>("host_ip", param_read_only());
config.sensor_ip = declare_parameter<std::string>("sensor_ip", param_read_only());
config.multicast_ip = declare_parameter<std::string>("multicast_ip", param_read_only());
config.data_port = declare_parameter<uint16_t>("data_port", param_read_only());
config.gnss_port = declare_parameter<uint16_t>("gnss_port", param_read_only());
config.frame_id = declare_parameter<std::string>("frame_id", param_read_write());
Expand Down
Loading