Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
galaxis::control::TwoAndAHalfCarrots Class Reference

#include <control.hpp>

Collaboration diagram for galaxis::control::TwoAndAHalfCarrots:

Public Member Functions

 TwoAndAHalfCarrots (std::shared_ptr< std::vector< float >> const p_yawStepsSPtr, float p_horizonStepTimeSec=0.5, int p_horizon=2, int p_errorAccuracyStepsPerHorizon=4, float p_carWheelbase=0.205f, float p_errorIncraseFactor=3)
 
void set_horizon (int p_horizon)
 
bool set_horizon_step_time (float valueSec)
 
bool set_error_factor_first_horizon (float factor)
 
bool set_error_accuracy_steps_per_horizon (int value)
 
void set_cross_angle_error_weight (float val)
 
void set_cross_line_marking_error_weight (float val)
 
float calculate_best_yaw_rate (std::shared_ptr< PolySpline > p_referenceTrajectorySPtr, std::shared_ptr< line_markings_reference_t > p_lineMarkings, float p_currentVelocity, CarPose p_pose=CarPose())
 
std::shared_ptr< CarPoseSeries > get_pose_series (std::shared_ptr< CarPose > const p_currentPoseSPtr, float p_distance, float p_yawRate, int p_steps)
 
std::shared_ptr< CarPoseSeries const > get_last_first_poseseries () const
 
std::shared_ptr< CarPoseSeries const > get_last_second_poseseries () const
 
float get_last_best_yaw_rate () const
 

Private Attributes

int m_horizon
 
int m_errorAccuracyStepsPerHorizon
 
const std::shared_ptr< std::vector< float > > m_yawStepsSPtr
 
float m_crossAngleErrorWeight = 0
 
float m_crossLineMarkingErrorWeight = 0
 
float m_carWheelbase = 0.205f
 
float m_errorIncraseFactor = 5
 
float m_lastYawRate = 0
 
float m_currentVelocity = 0
 
float m_horizonStepTimeSec = 0.5f
 
MicroStopwatch m_debugStopwatch
 
std::shared_ptr< CarPoseSeries > m_lastFirstPoseSeries
 
std::shared_ptr< CarPoseSeries > m_lastSecondPoseSeries
 

Detailed Description

Definition at line 28 of file control.hpp.

Constructor & Destructor Documentation

◆ TwoAndAHalfCarrots()

TwoAndAHalfCarrots::TwoAndAHalfCarrots ( std::shared_ptr< std::vector< float >> const  p_yawStepsSPtr,
float  p_horizonStepTimeSec = 0.5,
int  p_horizon = 2,
int  p_errorAccuracyStepsPerHorizon = 4,
float  p_carWheelbase = 0.205f,
float  p_errorIncraseFactor = 3 
)

Definition at line 19 of file control.cpp.

19  :
20  m_yawStepsSPtr(p_yawStepsSPtr) {
21  this->set_horizon(p_horizon);
22 
23  assert(m_horizonStepTimeSec > 0);
24  m_horizonStepTimeSec = p_horizonStepTimeSec;
25 
26  assert(p_carWheelbase > 0);
27  m_carWheelbase = p_carWheelbase;
28  m_errorIncraseFactor = p_errorIncraseFactor;
29 
30  assert(p_errorAccuracyStepsPerHorizon > 0);
31  m_errorAccuracyStepsPerHorizon = p_errorAccuracyStepsPerHorizon;
32 
33  //log("TwoAndAHalfCarrots \n - HorizonTimeStep: ", m_horizonStepTimeSec, "\n - Horizon: ", m_horizon, "\n - ErrorAccuracy (StepsPerHorizon): ", m_errorAccuracyStepsPerHorizon, "\n - Wheelbase: ", m_carWheelbase, "");
34 }

References m_carWheelbase, m_errorAccuracyStepsPerHorizon, m_errorIncraseFactor, m_horizonStepTimeSec, and set_horizon().

Here is the call graph for this function:

Member Function Documentation

◆ calculate_best_yaw_rate()

float TwoAndAHalfCarrots::calculate_best_yaw_rate ( std::shared_ptr< PolySpline >  p_referenceTrajectorySPtr,
std::shared_ptr< line_markings_reference_t >  p_lineMarkings,
float  p_currentVelocity,
CarPose  p_pose = CarPose() 
)

Definition at line 76 of file control.cpp.

78  { // currentYawRate?
79  if(p_currentVelocity < 0) {
80  log_warning("Velocity below 0! Return last Yaw Rate and skip calculation.");
81  return m_lastYawRate;
82  }
83 
84  m_currentVelocity = p_currentVelocity;
85  float coveredDistancePerHorizonStep = m_currentVelocity * m_horizonStepTimeSec;
86 
87  float bestYawRate = 0;
88  float bestError = 100000000; // TODO: maybe set maximum error here -> then yaw rate = 0
89 
90  std::shared_ptr<CarPose> currentPose = std::make_shared<CarPose>(p_pose);
91 
92  // debug track calculation time
94 
95  for(auto const& yawStepH1: *m_yawStepsSPtr) {
96  std::shared_ptr<CarPoseSeries> firstPoseSeries = get_pose_series(currentPose, coveredDistancePerHorizonStep, yawStepH1, m_errorAccuracyStepsPerHorizon);
97  for(auto const& yawStepH2: *m_yawStepsSPtr) {
98  // calculate point series
99  std::shared_ptr<CarPoseSeries> secondPoseSeries = get_pose_series(firstPoseSeries->at(firstPoseSeries->size() - 1), coveredDistancePerHorizonStep, yawStepH2, m_errorAccuracyStepsPerHorizon);
100 
101  // calculate error
102  float error = calculate_error_between_polyspline_poseseries(p_referenceTrajectorySPtr, firstPoseSeries, p_lineMarkings, m_crossAngleErrorWeight, m_crossLineMarkingErrorWeight) * m_errorIncraseFactor;
103  error += calculate_error_between_polyspline_poseseries(p_referenceTrajectorySPtr, secondPoseSeries, p_lineMarkings, m_crossAngleErrorWeight, m_crossLineMarkingErrorWeight);
104 
105  if(error < bestError) {
106  bestYawRate = yawStepH1;
107  bestError = error;
108 
109  m_lastFirstPoseSeries = firstPoseSeries;
110  m_lastSecondPoseSeries = secondPoseSeries;
111  }
112  }
113  }
114 
115  // debug print calculation time
116  long long time = m_debugStopwatch.get_time();
117  log("[CONTROL] Yaw Calculation Time [microsec]: ", time, "");
118 
119  m_lastYawRate = bestYawRate;
120  return bestYawRate;
121 }

References galaxis::calculate_error_between_polyspline_poseseries(), get_pose_series(), galaxis::utils::MicroStopwatch::get_time(), galaxis::utils::log(), galaxis::utils::log_warning(), m_crossAngleErrorWeight, m_crossLineMarkingErrorWeight, m_currentVelocity, m_debugStopwatch, m_errorAccuracyStepsPerHorizon, m_errorIncraseFactor, m_horizonStepTimeSec, m_lastFirstPoseSeries, m_lastSecondPoseSeries, m_lastYawRate, m_yawStepsSPtr, and galaxis::utils::MicroStopwatch::start().

Here is the call graph for this function:

◆ get_last_best_yaw_rate()

float TwoAndAHalfCarrots::get_last_best_yaw_rate ( ) const

Definition at line 154 of file control.cpp.

154  {
155  return m_lastYawRate;
156 }

References m_lastYawRate.

◆ get_last_first_poseseries()

std::shared_ptr< CarPoseSeries const > TwoAndAHalfCarrots::get_last_first_poseseries ( ) const

Definition at line 140 of file control.cpp.

140  {
141  if(m_lastFirstPoseSeries == nullptr) {
142  log_warning("LastFirstPoseSeries is nullptr");
143  }
144  return m_lastFirstPoseSeries;
145 }

References galaxis::utils::log_warning(), and m_lastFirstPoseSeries.

Here is the call graph for this function:

◆ get_last_second_poseseries()

std::shared_ptr< CarPoseSeries const > TwoAndAHalfCarrots::get_last_second_poseseries ( ) const

Definition at line 147 of file control.cpp.

147  {
148  if(m_lastSecondPoseSeries == nullptr) {
149  log_warning("LastSecondPoseSeries is nullptr");
150  }
151  return m_lastSecondPoseSeries;
152 }

References galaxis::utils::log_warning(), and m_lastSecondPoseSeries.

Here is the call graph for this function:

◆ get_pose_series()

std::shared_ptr< CarPoseSeries > TwoAndAHalfCarrots::get_pose_series ( std::shared_ptr< CarPose > const  p_currentPoseSPtr,
float  p_distance,
float  p_yawRate,
int  p_steps 
)

Definition at line 123 of file control.cpp.

123  {
124  if(p_steps < 1) {
125  log_error("[CONTROL] Step Amount below 1.");
126  throw std::runtime_error("TwoAndAHalfCarrots::get_pose_series: Step amount below 1.");
127  }
128 
129  std::shared_ptr<CarPoseSeries> series = std::make_shared<CarPoseSeries>();
130  series->push_back(p_currentPoseSPtr); // start pose
131 
132  float step_distance = p_distance / static_cast<float>(p_steps);
133  for(int i = 0; i < p_steps; ++i) {
134  series->push_back(galaxis::control::get_new_pose(series->at(i), m_carWheelbase, step_distance, p_yawRate));
135  }
136 
137  return series;
138 }

References galaxis::control::get_new_pose(), galaxis::utils::log_error(), and m_carWheelbase.

Referenced by calculate_best_yaw_rate().

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

◆ set_cross_angle_error_weight()

void TwoAndAHalfCarrots::set_cross_angle_error_weight ( float  val)

Definition at line 158 of file control.cpp.

158  {
160 }

References m_crossAngleErrorWeight.

◆ set_cross_line_marking_error_weight()

void TwoAndAHalfCarrots::set_cross_line_marking_error_weight ( float  val)

Definition at line 161 of file control.cpp.

161  {
163 }

References m_crossLineMarkingErrorWeight.

◆ set_error_accuracy_steps_per_horizon()

bool TwoAndAHalfCarrots::set_error_accuracy_steps_per_horizon ( int  value)

Definition at line 61 of file control.cpp.

61  {
62  if (value > 0) {
64  return true;
65  }
66  else {
67  return false;
68  }
69 }

References m_errorAccuracyStepsPerHorizon.

◆ set_error_factor_first_horizon()

bool TwoAndAHalfCarrots::set_error_factor_first_horizon ( float  factor)

Definition at line 57 of file control.cpp.

57  {
58  m_errorIncraseFactor = factor;
59 }

References m_errorIncraseFactor.

◆ set_horizon()

void TwoAndAHalfCarrots::set_horizon ( int  p_horizon)

Definition at line 36 of file control.cpp.

36  {
37  if(p_horizon < 1) {
38  log_error();
39  throw std::invalid_argument("Invalid Horizon! Horizon must be greater than 0!");
40  } else if(p_horizon != 2) {
41  log_warning("TwoAndAHalfCarrots only supports horizon 2 at the moment!");
42  }
43 
44  m_horizon = p_horizon;
45 }

References galaxis::utils::log_error(), galaxis::utils::log_warning(), and m_horizon.

Referenced by TwoAndAHalfCarrots().

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

◆ set_horizon_step_time()

bool TwoAndAHalfCarrots::set_horizon_step_time ( float  valueSec)

Definition at line 47 of file control.cpp.

47  {
48  if (valueSec > 0) {
49  m_horizonStepTimeSec = valueSec;
50  return true;
51  }
52  else {
53  return false;
54  }
55 }

References m_horizonStepTimeSec.

Member Data Documentation

◆ m_carWheelbase

float galaxis::control::TwoAndAHalfCarrots::m_carWheelbase = 0.205f
private

Definition at line 37 of file control.hpp.

Referenced by get_pose_series(), and TwoAndAHalfCarrots().

◆ m_crossAngleErrorWeight

float galaxis::control::TwoAndAHalfCarrots::m_crossAngleErrorWeight = 0
private

Definition at line 34 of file control.hpp.

Referenced by calculate_best_yaw_rate(), and set_cross_angle_error_weight().

◆ m_crossLineMarkingErrorWeight

float galaxis::control::TwoAndAHalfCarrots::m_crossLineMarkingErrorWeight = 0
private

Definition at line 35 of file control.hpp.

Referenced by calculate_best_yaw_rate(), and set_cross_line_marking_error_weight().

◆ m_currentVelocity

float galaxis::control::TwoAndAHalfCarrots::m_currentVelocity = 0
private

Definition at line 41 of file control.hpp.

Referenced by calculate_best_yaw_rate().

◆ m_debugStopwatch

MicroStopwatch galaxis::control::TwoAndAHalfCarrots::m_debugStopwatch
private

Definition at line 45 of file control.hpp.

Referenced by calculate_best_yaw_rate().

◆ m_errorAccuracyStepsPerHorizon

int galaxis::control::TwoAndAHalfCarrots::m_errorAccuracyStepsPerHorizon
private

◆ m_errorIncraseFactor

float galaxis::control::TwoAndAHalfCarrots::m_errorIncraseFactor = 5
private

◆ m_horizon

int galaxis::control::TwoAndAHalfCarrots::m_horizon
private

Definition at line 30 of file control.hpp.

Referenced by set_horizon().

◆ m_horizonStepTimeSec

float galaxis::control::TwoAndAHalfCarrots::m_horizonStepTimeSec = 0.5f
private

Definition at line 42 of file control.hpp.

Referenced by calculate_best_yaw_rate(), set_horizon_step_time(), and TwoAndAHalfCarrots().

◆ m_lastFirstPoseSeries

std::shared_ptr<CarPoseSeries> galaxis::control::TwoAndAHalfCarrots::m_lastFirstPoseSeries
private

Definition at line 46 of file control.hpp.

Referenced by calculate_best_yaw_rate(), and get_last_first_poseseries().

◆ m_lastSecondPoseSeries

std::shared_ptr<CarPoseSeries> galaxis::control::TwoAndAHalfCarrots::m_lastSecondPoseSeries
private

Definition at line 47 of file control.hpp.

Referenced by calculate_best_yaw_rate(), and get_last_second_poseseries().

◆ m_lastYawRate

float galaxis::control::TwoAndAHalfCarrots::m_lastYawRate = 0
private

Definition at line 40 of file control.hpp.

Referenced by calculate_best_yaw_rate(), and get_last_best_yaw_rate().

◆ m_yawStepsSPtr

const std::shared_ptr<std::vector<float> > galaxis::control::TwoAndAHalfCarrots::m_yawStepsSPtr
private

Definition at line 32 of file control.hpp.

Referenced by calculate_best_yaw_rate().


The documentation for this class was generated from the following files:
galaxis::calculate_error_between_polyspline_poseseries
float calculate_error_between_polyspline_poseseries(shared_ptr< PolySpline > p_polySplineSPtr, shared_ptr< galaxis::control::CarPoseSeries > p_poseSeriesSPtr, shared_ptr< line_markings_reference_t > p_lineMarkings, float cross_angle_weight, float cross_line_weight)
Definition: poly.cpp:136
galaxis::control::TwoAndAHalfCarrots::m_currentVelocity
float m_currentVelocity
Definition: control.hpp:41
galaxis::utils::log_error
void log_error(const Args &... args)
Definition: logger.hpp:50
galaxis::control::TwoAndAHalfCarrots::m_carWheelbase
float m_carWheelbase
Definition: control.hpp:37
galaxis::control::TwoAndAHalfCarrots::m_lastFirstPoseSeries
std::shared_ptr< CarPoseSeries > m_lastFirstPoseSeries
Definition: control.hpp:46
galaxis::utils::log_warning
void log_warning(const Args &... args)
Definition: logger.hpp:41
galaxis::control::TwoAndAHalfCarrots::m_crossAngleErrorWeight
float m_crossAngleErrorWeight
Definition: control.hpp:34
galaxis::control::TwoAndAHalfCarrots::m_lastSecondPoseSeries
std::shared_ptr< CarPoseSeries > m_lastSecondPoseSeries
Definition: control.hpp:47
galaxis::control::TwoAndAHalfCarrots::m_yawStepsSPtr
const std::shared_ptr< std::vector< float > > m_yawStepsSPtr
Definition: control.hpp:32
galaxis::control::TwoAndAHalfCarrots::m_debugStopwatch
MicroStopwatch m_debugStopwatch
Definition: control.hpp:45
galaxis::utils::MicroStopwatch::start
void start()
Definition: clock.cpp:25
galaxis::utils::MicroStopwatch::get_time
long long get_time() const
Definition: clock.cpp:33
galaxis::control::TwoAndAHalfCarrots::m_errorAccuracyStepsPerHorizon
int m_errorAccuracyStepsPerHorizon
Definition: control.hpp:31
galaxis::control::TwoAndAHalfCarrots::set_horizon
void set_horizon(int p_horizon)
Definition: control.cpp:36
galaxis::control::TwoAndAHalfCarrots::m_lastYawRate
float m_lastYawRate
Definition: control.hpp:40
galaxis::control::TwoAndAHalfCarrots::get_pose_series
std::shared_ptr< CarPoseSeries > get_pose_series(std::shared_ptr< CarPose > const p_currentPoseSPtr, float p_distance, float p_yawRate, int p_steps)
Definition: control.cpp:123
galaxis::control::TwoAndAHalfCarrots::m_crossLineMarkingErrorWeight
float m_crossLineMarkingErrorWeight
Definition: control.hpp:35
galaxis::control::TwoAndAHalfCarrots::m_errorIncraseFactor
float m_errorIncraseFactor
Definition: control.hpp:38
galaxis::utils::log
void log(const Args &... args)
Definition: logger.hpp:33
galaxis::control::get_new_pose
std::shared_ptr< CarPose > get_new_pose(std::shared_ptr< CarPose > const p_currentPoseSPtr, float p_carWheelbase, float p_distance, float p_yawDiff)
Definition: control.cpp:168
galaxis::control::TwoAndAHalfCarrots::m_horizonStepTimeSec
float m_horizonStepTimeSec
Definition: control.hpp:42
galaxis::control::TwoAndAHalfCarrots::m_horizon
int m_horizon
Definition: control.hpp:30