diff --git a/nebula_common/include/nebula_common/nebula_common.hpp b/nebula_common/include/nebula_common/nebula_common.hpp index 36044a9e8..869ea8979 100644 --- a/nebula_common/include/nebula_common/nebula_common.hpp +++ b/nebula_common/include/nebula_common/nebula_common.hpp @@ -15,11 +15,14 @@ #ifndef NEBULA_COMMON_H #define NEBULA_COMMON_H +#include "nebula_common/util/expected.hpp" + #include #include #include +#include #include #include #include @@ -28,6 +31,9 @@ namespace nebula { namespace drivers { + +using std::string_literals::operator""s; + /// @brief Coordinate mode for Velodyne's setting (need to check) enum class CoordinateMode { UNKNOWN = 0, CARTESIAN, SPHERICAL, CYLINDRICAL }; @@ -636,6 +642,47 @@ inline std::string SensorModelToString(const SensorModel & sensor_model) } } +/** + * @brief Get the number of channels a specific sensor model has. A string error message is returned + * for sensors that do not have a meaningful channel number. + * + * @param sensor_model The sensor model of interest + * @return nebula::util::expected The number of channels on success, or a + * string error message. + */ +inline nebula::util::expected get_n_channels( + const SensorModel & sensor_model) +{ + switch (sensor_model) { + case SensorModel::VELODYNE_VLP16: + return 16; + case SensorModel::VELODYNE_VLP32: + case SensorModel::VELODYNE_VLP32MR: + case SensorModel::VELODYNE_HDL32: + case SensorModel::HESAI_PANDARXT32: + case SensorModel::HESAI_PANDARXT32M: + case SensorModel::ROBOSENSE_HELIOS: + case SensorModel::ROBOSENSE_BPEARL_V3: + case SensorModel::ROBOSENSE_BPEARL_V4: + return 32; + case SensorModel::HESAI_PANDAR40P: + case SensorModel::HESAI_PANDAR40M: + return 40; + case SensorModel::VELODYNE_HDL64: + case SensorModel::HESAI_PANDAR64: + case SensorModel::HESAI_PANDARQT64: + return 64; + case SensorModel::VELODYNE_VLS128: + case SensorModel::HESAI_PANDARQT128: + case SensorModel::HESAI_PANDARAT128: + case SensorModel::HESAI_PANDAR128_E3X: + case SensorModel::HESAI_PANDAR128_E4X: + return 128; + default: + return "unsupported sensor model"s; + } +} + /// @brief Convert return mode name to ReturnMode enum /// @param return_mode Return mode name (Upper and lower case letters must match) /// @return Corresponding ReturnMode