Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions vortex_utils/include/vortex/utils/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ struct LineSegment2D {
/**
* @brief Enum class for operation modes.
*/
enum class Mode : uint8_t { manual, autonomous, reference };
enum class Mode : int { autonomous, manual, reference };

/**
* @brief Convert Mode enum to string for logging or display purposes.
Expand All @@ -419,7 +419,8 @@ inline std::string mode_to_string(Mode mode) {
case Mode::reference:
return "reference mode";
default:
throw std::runtime_error("Invalid operation mode.");
throw std::runtime_error(
"String conversion failed, invalid mode value");
}
}

Expand Down
27 changes: 26 additions & 1 deletion vortex_utils_ros/include/vortex/utils/ros/ros_conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,32 @@ inline vortex::utils::types::Mode convert_from_ros(
case vortex_msgs::msg::OperationMode::REFERENCE:
return vortex::utils::types::Mode::reference;
}
throw std::runtime_error("Invalid operation mode.");
throw std::runtime_error("Conversion failed, invalid operation mode value");
}

/**
* @brief Converts an internal Mode enum to a ROS
* vortex_msgs::msg::OperationMode.
* @param mode vortex::utils::types::Mode
* @return vortex_msgs::msg::OperationMode ROS mode message
*/
inline vortex_msgs::msg::OperationMode convert_to_ros(
const vortex::utils::types::Mode& mode) {
vortex_msgs::msg::OperationMode mode_msg;
switch (mode) {
case vortex::utils::types::Mode::manual:
mode_msg.operation_mode = vortex_msgs::msg::OperationMode::MANUAL;
return mode_msg;
case vortex::utils::types::Mode::autonomous:
mode_msg.operation_mode =
vortex_msgs::msg::OperationMode::AUTONOMOUS;
return mode_msg;
case vortex::utils::types::Mode::reference:
mode_msg.operation_mode =
vortex_msgs::msg::OperationMode::REFERENCE;
return mode_msg;
}
throw std::runtime_error("Conversion failed, invalid operation mode value");
}

} // namespace vortex::utils::ros_conversions
Expand Down