13 #include <Eigen/Dense>
19 TwoAndAHalfCarrots::TwoAndAHalfCarrots(std::shared_ptr<std::vector<float>>
const p_yawStepsSPtr,
float p_horizonStepTimeSec,
int p_horizon,
int p_errorAccuracyStepsPerHorizon,
float p_carWheelbase,
float p_errorIncraseFactor) :
20 m_yawStepsSPtr(p_yawStepsSPtr) {
26 assert(p_carWheelbase > 0);
30 assert(p_errorAccuracyStepsPerHorizon > 0);
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!");
77 std::shared_ptr<line_markings_reference_t> p_lineMarkings,
78 float p_currentVelocity,
CarPose p_pose) {
79 if(p_currentVelocity < 0) {
80 log_warning(
"Velocity below 0! Return last Yaw Rate and skip calculation.");
87 float bestYawRate = 0;
88 float bestError = 100000000;
90 std::shared_ptr<CarPose> currentPose = std::make_shared<CarPose>(p_pose);
105 if(error < bestError) {
106 bestYawRate = yawStepH1;
117 log(
"[CONTROL] Yaw Calculation Time [microsec]: ", time,
"");
125 log_error(
"[CONTROL] Step Amount below 1.");
126 throw std::runtime_error(
"TwoAndAHalfCarrots::get_pose_series: Step amount below 1.");
129 std::shared_ptr<CarPoseSeries> series = std::make_shared<CarPoseSeries>();
130 series->push_back(p_currentPoseSPtr);
132 float step_distance = p_distance /
static_cast<float>(p_steps);
133 for(
int i = 0; i < p_steps; ++i) {
168 std::shared_ptr<CarPose>
galaxis::control::get_new_pose(std::shared_ptr<CarPose>
const p_currentPoseSPtr,
float p_carWheelbase,
float p_distance,
float p_yawDiff) {
169 std::shared_ptr<CarPose> newPoseSPtr = std::make_shared<CarPose>();
170 newPoseSPtr->position = p_currentPoseSPtr->position;
171 newPoseSPtr->orientation = p_currentPoseSPtr->orientation;
173 Eigen::Rotation2Df rotation(p_currentPoseSPtr->orientation);
176 if(std::sin(p_yawDiff) == 0) {
178 newPoseSPtr->position += rotation * distance;
183 float radiusOfSteeringCircle = p_carWheelbase / std::sin(p_yawDiff);
185 float steeringCircumference = 2 *
MATH_PI * radiusOfSteeringCircle;
187 float circleDrivenAngle = p_distance / steeringCircumference * 2 *
MATH_PI;
189 float directDistanceBetweenStartAndNewPose = 2 * std::sin(circleDrivenAngle / 2) * radiusOfSteeringCircle;
192 position[0] = directDistanceBetweenStartAndNewPose * std::cos(circleDrivenAngle / 2);
193 position[1] = directDistanceBetweenStartAndNewPose * std::sin(circleDrivenAngle / 2);
196 position = rotation * position;
198 newPoseSPtr->position += position;
199 newPoseSPtr->orientation += circleDrivenAngle;