Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
Localizer Class Reference

#include <Localizer.hpp>

Collaboration diagram for Localizer:

Public Member Functions

 Localizer ()
 
void init (rclcpp::Time &timestamp, double orientationRad)
 
bool is_empty ()
 
void add_position_timepoint (rclcpp::Time &timestamp, galaxis::lina::Vector2f positionMillimeter, double speedMillimeterPerSec, double orientationRad)
 
void add_state (rclcpp::Time &timestamp, double speedMillimeterPerSec, double orientationRad)
 
std::shared_ptr< PositionTimepoint > get_latest_position_timepoint ()
 
std::shared_ptr< PositionTimepoint > get_position_timepoint_by_time (rclcpp::Time &timestamp)
 

Private Attributes

PositionTimepointBuffer m_positionHistory
 

Detailed Description

Definition at line 93 of file Localizer.hpp.

Constructor & Destructor Documentation

◆ Localizer()

Localizer::Localizer ( )

Definition at line 8 of file Localizer.cpp.

8  :
9  m_positionHistory(200) {}

Member Function Documentation

◆ add_position_timepoint()

void Localizer::add_position_timepoint ( rclcpp::Time &  timestamp,
galaxis::lina::Vector2f  positionMillimeter,
double  speedMillimeterPerSec,
double  orientationRad 
)

Definition at line 19 of file Localizer.cpp.

19  {
20  PositionTimepoint newPositionPoint;
21  newPositionPoint.timestamp = timestamp;
22  newPositionPoint.speed = speedMillimeterPerSec;
23  newPositionPoint.position = positionMillimeter;
24  newPositionPoint.orientation = orientationRad;
25 
26  m_positionHistory.add(newPositionPoint);
27 }

References PositionTimepointBuffer::add(), m_positionHistory, PositionTimepoint::orientation, PositionTimepoint::position, PositionTimepoint::speed, and PositionTimepoint::timestamp.

Referenced by add_state(), AutoPilotNode::AutoPilotNode(), and AutoPilotNode::on_simulation_pose_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_state()

void Localizer::add_state ( rclcpp::Time &  timestamp,
double  speedMillimeterPerSec,
double  orientationRad 
)

Definition at line 30 of file Localizer.cpp.

30  {
32  log_warning("[LOCALIZER] Position History Empty!");
33  this->add_position_timepoint(timestamp, galaxis::lina::Vector2f(0.f,0.f), speedMillimeterPerSec, orientationRad);
34  return;
35  }
36 
37  orientationRad = std::fmod(orientationRad, 2*MATH_PI_DOUBLE);
38  // assert(orientationRad <= 2 * MATH_PI_DOUBLE + 0.1);
39 
40  PositionTimepoint newPositionPoint;
41  newPositionPoint.timestamp = timestamp;
42  newPositionPoint.orientation = orientationRad;
43  newPositionPoint.speed = speedMillimeterPerSec;
44 
45  PositionTimepoint lastPositionPoint = m_positionHistory.get_last();
46 
47  // calc driven distance within time interval
48  rclcpp::Duration timeIntervalNanoseconds = timestamp - lastPositionPoint.timestamp;
49  double speed = (lastPositionPoint.speed + speedMillimeterPerSec) / 2.f;
50  double drivenDistanceMillimeter = timeIntervalNanoseconds.nanoseconds() * speed / 1000000000.f; // based on speed at last point // TODO: CHECK
51 
52  // based on single-track model
53  std::shared_ptr<CarPose> lastPose = std::make_shared<CarPose>();
54  lastPose->orientation = lastPositionPoint.orientation;
55 
56  double orientationDiff = orientationRad - lastPositionPoint.orientation;
57 
58  if(orientationDiff > MATH_PI_DOUBLE) { // if currentOrientation is lower than 0 deg (something around 2*PI) and lastOrientation greater than 0 deg
59  orientationDiff -= 2 * MATH_PI_DOUBLE;
60  } else if(orientationDiff < -MATH_PI_DOUBLE) { // analog the other way round
61  orientationDiff += 2 * MATH_PI_DOUBLE;
62  }
63 
64  // orientationDiff treated as turn angle
65  // lastPose->position = galaxis::lina::Vector2f(m_positionHistory.get_last().position[1], m_positionHistory.get_last().position[0]); // in mm
66  // std::shared_ptr<CarPose> newPoseSPtr = galaxis::control::get_new_pose(lastPose, galaxis::controllerSettings::carWheelbase * 1000, drivenDistanceMillimeter, orientationDiff);
67  // newPositionPoint.position = galaxis::lina::Vector2f(newPoseSPtr->position[1], newPoseSPtr->position[0]);
68  // newPositionPoint.orientation = orientationRad; // should be approx. equal to newPoseSPtr->orientation // TODO: check (look above) ***
69 
70  // new calculation
71  Eigen::Rotation2Df lastOrientationRotMat(-lastPositionPoint.orientation); // counter-clock wise rotation
72  galaxis::lina::Vector2f drivenDistanceVector = lastOrientationRotMat * galaxis::lina::Vector2f(0.f, drivenDistanceMillimeter);
73  Eigen::Rotation2Df orientationDiffRotMat(-orientationDiff);
74  drivenDistanceVector = orientationDiffRotMat * drivenDistanceVector;
75 
76  newPositionPoint.position = lastPositionPoint.position + drivenDistanceVector;
77 
78 
79  log_debug("[LOCALIZER] Position: ", newPositionPoint.position[0], ",", newPositionPoint.position[1], "; Orientation: ", orientationRad);
80 
81  // append to buffer
82  m_positionHistory.add(newPositionPoint);
83 }

References PositionTimepointBuffer::add(), add_position_timepoint(), PositionTimepointBuffer::get_last(), PositionTimepointBuffer::is_empty(), galaxis::utils::log_debug(), galaxis::utils::log_warning(), m_positionHistory, MATH_PI_DOUBLE, PositionTimepoint::orientation, PositionTimepoint::position, PositionTimepoint::speed, and PositionTimepoint::timestamp.

Referenced by AutoPilotNode::on_ecu_measurement_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_latest_position_timepoint()

std::shared_ptr< PositionTimepoint > Localizer::get_latest_position_timepoint ( )

Definition at line 85 of file Localizer.cpp.

85  {
86  return std::make_shared<PositionTimepoint>(m_positionHistory.get_last());
87 }

References PositionTimepointBuffer::get_last(), and m_positionHistory.

Referenced by AutoPilotNode::car_pose_publish_loop(), AutoPilot::get_drive_information(), AutoPilot::get_lane_blocked(), AutoPilotNode::on_stop_line_callback(), and AutoPilotNode::send_map_debug_image().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_position_timepoint_by_time()

std::shared_ptr< PositionTimepoint > Localizer::get_position_timepoint_by_time ( rclcpp::Time &  timestamp)

Definition at line 89 of file Localizer.cpp.

89  {
90  return std::make_shared<PositionTimepoint>(m_positionHistory.get_last_by_time(timestamp));
91 }

References PositionTimepointBuffer::get_last_by_time(), and m_positionHistory.

Referenced by AutoPilotNode::on_obstacle_callback(), and AutoPilotNode::on_vci_lane_detection_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

void Localizer::init ( rclcpp::Time &  timestamp,
double  orientationRad 
)

Definition at line 11 of file Localizer.cpp.

11  {
12  m_positionHistory.add({ timestamp, galaxis::lina::Vector2f(0.f, 0.f), 0, orientationRad });
13 }

References PositionTimepointBuffer::add(), and m_positionHistory.

Here is the call graph for this function:

◆ is_empty()

bool Localizer::is_empty ( )

Definition at line 15 of file Localizer.cpp.

15  {
16  return m_positionHistory.is_empty();
17 }

References PositionTimepointBuffer::is_empty(), and m_positionHistory.

Referenced by AutoPilotNode::car_pose_publish_loop(), AutoPilotNode::on_obstacle_callback(), and AutoPilotNode::on_vci_lane_detection_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_positionHistory


The documentation for this class was generated from the following files:
PositionTimepoint::orientation
double orientation
Definition: Localizer.hpp:23
PositionTimepoint::position
galaxis::lina::Vector2f position
Definition: Localizer.hpp:21
galaxis::utils::log_warning
void log_warning(const Args &... args)
Definition: logger.hpp:41
PositionTimepoint::speed
double speed
Definition: Localizer.hpp:22
PositionTimepointBuffer::get_last
PositionTimepoint get_last()
Definition: Localizer.hpp:76
Localizer::m_positionHistory
PositionTimepointBuffer m_positionHistory
Definition: Localizer.hpp:106
Localizer::add_position_timepoint
void add_position_timepoint(rclcpp::Time &timestamp, galaxis::lina::Vector2f positionMillimeter, double speedMillimeterPerSec, double orientationRad)
Definition: Localizer.cpp:19
galaxis::lina::Vector2f
Eigen::Vector2f Vector2f
Definition: linatypes.hpp:14
MATH_PI_DOUBLE
constexpr double MATH_PI_DOUBLE
Definition: AutoPilot.hpp:22
PositionTimepointBuffer::get_last_by_time
PositionTimepoint get_last_by_time(rclcpp::Time &timestamp)
Definition: Localizer.hpp:48
PositionTimepoint::timestamp
rclcpp::Time timestamp
Definition: Localizer.hpp:20
PositionTimepointBuffer::add
void add(PositionTimepoint const &element)
Definition: Localizer.hpp:37
PositionTimepointBuffer::is_empty
bool is_empty()
Definition: Localizer.hpp:84
galaxis::utils::log_debug
void log_debug(const Args &... args)
Definition: logger.hpp:62
PositionTimepoint
Definition: Localizer.hpp:19