College of DuPage Lunabotics Documentation  2025
LocalizationServer Class Reference

Provides localization using AprilTags and manages an action server for localization feedback. More...

Inheritance diagram for LocalizationServer:
Collaboration diagram for LocalizationServer:

Public Types

using Localization = lunabot_msgs::action::Localization
 
using GoalHandleLocalization = rclcpp_action::ServerGoalHandle< Localization >
 

Public Member Functions

 LocalizationServer ()
 Constructor for the LocalizationServer class. More...
 

Private Member Functions

rclcpp_action::GoalResponse handle_goal (const rclcpp_action::GoalUUID &, std::shared_ptr< const Localization::Goal >)
 Handles goal requests from clients. More...
 
rclcpp_action::CancelResponse handle_cancel (const std::shared_ptr< GoalHandleLocalization >)
 Handles cancellation requests from clients. More...
 
void handle_accepted (const std::shared_ptr< GoalHandleLocalization > goal_handle)
 Accepts and starts the goal execution. More...
 
void execute (const std::shared_ptr< GoalHandleLocalization > goal_handle)
 Executes the localization process. More...
 
void localize ()
 Aligns the robot to face east with the D455 camera facing AprilTag with tag 7. More...
 
void d455_detect_apriltag (const sensor_msgs::msg::Image::SharedPtr input_image)
 Detects AprilTags in images from the D455 camera. More...
 
void d456_detect_apriltag (const sensor_msgs::msg::Image::SharedPtr input_image)
 Detects AprilTags in images from the D456 camera. More...
 
void process_apriltag (const sensor_msgs::msg::Image::SharedPtr &input_image, bool &tag_7_detected_, bool &tag_11_detected_, const rclcpp::Publisher< sensor_msgs::msg::Image >::SharedPtr &overlay_publisher, bool calculate_tag_)
 Processes detected AprilTags, calculates pose, and publishes overlay image. More...
 
double normalize_angle (double angle)
 Normalizes an angle to the range [-pi, pi]. More...
 
void calculate_distances (const cv::Vec3d &tvec, double &lateral_distance, double &depth_distance)
 Calculates lateral and depth distances from translation vector. More...
 
void calculate_yaw (const cv::Vec3d &rvec, double &tag_7_yaw_)
 Calculates yaw from rotation vector. More...
 

Private Attributes

bool d455_tag_7_detected_
 
bool d455_tag_11_detected_
 
bool d456_tag_7_detected_
 
bool d456_tag_11_detected_
 
bool turn_direction_set_
 
bool turn_clockwise_
 
bool timer_started_
 
bool success_
 
double lateral_distance_
 
double depth_distance_
 
double tag_7_yaw_
 
rclcpp::Time start_time_
 
rclcpp::TimerBase::SharedPtr localization_timer_
 
geometry_msgs::msg::Twist twist
 
rclcpp_action::Server< Localization >::SharedPtr action_server_
 
rclcpp::Subscription< sensor_msgs::msg::Image >::SharedPtr d455_image_subscriber_
 
rclcpp::Subscription< sensor_msgs::msg::Image >::SharedPtr d456_image_subscriber_
 
rclcpp::Publisher< sensor_msgs::msg::Image >::SharedPtr d455_overlay_publisher_
 
rclcpp::Publisher< sensor_msgs::msg::Image >::SharedPtr d456_overlay_publisher_
 
rclcpp::Publisher< geometry_msgs::msg::Twist >::SharedPtr cmd_vel_publisher_
 

Detailed Description

Provides localization using AprilTags and manages an action server for localization feedback.

Member Typedef Documentation

◆ GoalHandleLocalization

using LocalizationServer::GoalHandleLocalization = rclcpp_action::ServerGoalHandle<Localization>

◆ Localization

using LocalizationServer::Localization = lunabot_msgs::action::Localization

Constructor & Destructor Documentation

◆ LocalizationServer()

LocalizationServer::LocalizationServer ( )
inline

Constructor for the LocalizationServer class.

Member Function Documentation

◆ calculate_distances()

void LocalizationServer::calculate_distances ( const cv::Vec3d &  tvec,
double &  lateral_distance,
double &  depth_distance 
)
inlineprivate

Calculates lateral and depth distances from translation vector.

Parameters
tvecTranslation vector.
lateral_distanceCalculated lateral distance.
depth_distanceCalculated depth distance.

◆ calculate_yaw()

void LocalizationServer::calculate_yaw ( const cv::Vec3d &  rvec,
double &  tag_7_yaw_ 
)
inlineprivate

Calculates yaw from rotation vector.

Parameters
rvecRotation vector.
tag_7_yaw_Calculated yaw for tag_7.

◆ d455_detect_apriltag()

void LocalizationServer::d455_detect_apriltag ( const sensor_msgs::msg::Image::SharedPtr  input_image)
inlineprivate

Detects AprilTags in images from the D455 camera.

Parameters
input_imageImage message from the D455 camera.

◆ d456_detect_apriltag()

void LocalizationServer::d456_detect_apriltag ( const sensor_msgs::msg::Image::SharedPtr  input_image)
inlineprivate

Detects AprilTags in images from the D456 camera.

Parameters
input_imageImage message from the D456 camera.

◆ execute()

void LocalizationServer::execute ( const std::shared_ptr< GoalHandleLocalization goal_handle)
inlineprivate

Executes the localization process.

Parameters
goal_handleHandle for the current goal.

◆ handle_accepted()

void LocalizationServer::handle_accepted ( const std::shared_ptr< GoalHandleLocalization goal_handle)
inlineprivate

Accepts and starts the goal execution.

Parameters
goal_handleHandle for the current goal.

◆ handle_cancel()

rclcpp_action::CancelResponse LocalizationServer::handle_cancel ( const std::shared_ptr< GoalHandleLocalization )
inlineprivate

Handles cancellation requests from clients.

Returns
Cancel response (accept or reject).

◆ handle_goal()

rclcpp_action::GoalResponse LocalizationServer::handle_goal ( const rclcpp_action::GoalUUID &  ,
std::shared_ptr< const Localization::Goal >   
)
inlineprivate

Handles goal requests from clients.

Returns
Goal response (accept or reject).

◆ localize()

void LocalizationServer::localize ( )
inlineprivate

Aligns the robot to face east with the D455 camera facing AprilTag with tag 7.

◆ normalize_angle()

double LocalizationServer::normalize_angle ( double  angle)
inlineprivate

Normalizes an angle to the range [-pi, pi].

Parameters
angleThe angle to normalize.
Returns
Normalized angle.

◆ process_apriltag()

void LocalizationServer::process_apriltag ( const sensor_msgs::msg::Image::SharedPtr &  input_image,
bool &  tag_7_detected_,
bool &  tag_11_detected_,
const rclcpp::Publisher< sensor_msgs::msg::Image >::SharedPtr &  overlay_publisher,
bool  calculate_tag_ 
)
inlineprivate

Processes detected AprilTags, calculates pose, and publishes overlay image.

Parameters
input_imageInput image message.
tag_7_detected_Flag for tag 7 detection.
tag_11_detected_Flag for tag 11 detection
overlay_publisherPublisher for overlay image.
calculate_tag_Flag to determine whether to calculate yaw and distances for the detected tag.

Member Data Documentation

◆ action_server_

rclcpp_action::Server<Localization>::SharedPtr LocalizationServer::action_server_
private

◆ cmd_vel_publisher_

rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr LocalizationServer::cmd_vel_publisher_
private

◆ d455_image_subscriber_

rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr LocalizationServer::d455_image_subscriber_
private

◆ d455_overlay_publisher_

rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr LocalizationServer::d455_overlay_publisher_
private

◆ d455_tag_11_detected_

bool LocalizationServer::d455_tag_11_detected_
private

◆ d455_tag_7_detected_

bool LocalizationServer::d455_tag_7_detected_
private

◆ d456_image_subscriber_

rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr LocalizationServer::d456_image_subscriber_
private

◆ d456_overlay_publisher_

rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr LocalizationServer::d456_overlay_publisher_
private

◆ d456_tag_11_detected_

bool LocalizationServer::d456_tag_11_detected_
private

◆ d456_tag_7_detected_

bool LocalizationServer::d456_tag_7_detected_
private

◆ depth_distance_

double LocalizationServer::depth_distance_
private

◆ lateral_distance_

double LocalizationServer::lateral_distance_
private

◆ localization_timer_

rclcpp::TimerBase::SharedPtr LocalizationServer::localization_timer_
private

◆ start_time_

rclcpp::Time LocalizationServer::start_time_
private

◆ success_

bool LocalizationServer::success_
private

◆ tag_7_yaw_

double LocalizationServer::tag_7_yaw_
private

◆ timer_started_

bool LocalizationServer::timer_started_
private

◆ turn_clockwise_

bool LocalizationServer::turn_clockwise_
private

◆ turn_direction_set_

bool LocalizationServer::turn_direction_set_
private

◆ twist

geometry_msgs::msg::Twist LocalizationServer::twist
private

The documentation for this class was generated from the following file: