Skip to content

Commit

Permalink
TEMP
Browse files Browse the repository at this point in the history
  • Loading branch information
MaEtUgR committed Nov 21, 2023
1 parent c69264b commit 355af09
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/lib/motion_planning/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
############################################################################

px4_add_library(motion_planning
VelocitySmoothing.cpp
PositionSmoothing.cpp
HeadingSmoothing.cpp
ManualVelocitySmoothingXY.cpp
ManualVelocitySmoothingZ.cpp
PositionSmoothing.cpp
VelocitySmoothing.cpp
)

target_include_directories(motion_planning PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
2 changes: 0 additions & 2 deletions src/lib/motion_planning/PositionSmoothing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#include "TrajectoryConstraints.hpp"
#include <mathlib/mathlib.h>
#include <matrix/matrix/math.hpp>
#include <matrix/matrix/helper_functions.hpp>


void PositionSmoothing::_generateSetpoints(
const Vector3f &position,
Expand Down
8 changes: 4 additions & 4 deletions src/modules/mc_pos_control/GotoControl/GotoControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void GotoControl::setPositionSmootherLimits(const goto_setpoint_s &goto_setpoint
if (_position_smoother.getCurrentVelocityXY().norm() <= max_horizontal_speed) {
const float speed_scale = max_horizontal_speed / _vehicle_constraints.max_horizontal_speed;
max_horizontal_accel = math::constrain(_vehicle_constraints.max_horizontal_accel * speed_scale,
VelocitySmoothing::kMinAccel,
0.f,
_vehicle_constraints.max_horizontal_accel);
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ void GotoControl::setPositionSmootherLimits(const goto_setpoint_s &goto_setpoint
// only limit acceleration once within velocity constraints
if (fabsf(_position_smoother.getCurrentVelocityZ()) <= max_vertical_speed) {
const float speed_scale = max_vertical_speed / vehicle_max_vertical_speed;
max_vertical_accel = math::constrain(vehicle_max_vertical_accel * speed_scale, VelocitySmoothing::kMinAccel,
max_vertical_accel = math::constrain(vehicle_max_vertical_accel * speed_scale, 0.f,
vehicle_max_vertical_accel);
}
}
Expand All @@ -193,15 +193,15 @@ void GotoControl::setHeadingSmootherLimits(const goto_setpoint_s &goto_setpoint)
float max_heading_accel = _vehicle_constraints.max_heading_accel;

if (goto_setpoint.flag_set_max_heading_rate && PX4_ISFINITE(goto_setpoint.max_heading_rate)) {
max_heading_rate = math::constrain(goto_setpoint.max_heading_rate, HeadingSmoother::kMinHeadingRate,
max_heading_rate = math::constrain(goto_setpoint.max_heading_rate, 0.f,
_vehicle_constraints.max_heading_rate);

// linearly scale heading acceleration limit with heading rate limit to maintain smoothing dynamic
// only limit acceleration once within velocity constraints
if (fabsf(_heading_smoother.getSmoothedHeadingRate()) <= max_heading_rate) {
const float rate_scale = max_heading_rate / _vehicle_constraints.max_heading_rate;
max_heading_accel = math::constrain(_vehicle_constraints.max_heading_accel * rate_scale,
HeadingSmoother::kMinHeadingAccel, _vehicle_constraints.max_heading_accel);
0.f, _vehicle_constraints.max_heading_accel);
}
}

Expand Down
31 changes: 16 additions & 15 deletions src/modules/mc_pos_control/GotoControl/GotoControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@

#pragma once

#include <matrix/matrix/math.hpp>
#include <lib/motion_planning/HeadingSmoothing.hpp>
#include <lib/motion_planning/PositionSmoothing.hpp>
#include <lib/motion_planning/HeadingSmoother.hpp>
#include <mathlib/math/Limits.hpp>
#include <matrix/matrix/math.hpp>
#include <uORB/topics/goto_setpoint.h>
#include <uORB/topics/trajectory_setpoint.h>

Expand All @@ -63,12 +64,12 @@ class GotoControl
float max_horizontal_speed = kMinSpeed; // [m/s]
float max_down_speed = kMinSpeed; // [m/s]
float max_up_speed = kMinSpeed; // [m/s]
float max_horizontal_accel = VelocitySmoothing::kMinAccel; // [m/s^2]
float max_down_accel = VelocitySmoothing::kMinAccel; // [m/s^2]
float max_up_accel = VelocitySmoothing::kMinAccel; // [m/s^2]
float max_jerk = VelocitySmoothing::kMinJerk; // [m/s^3]
float max_heading_rate = HeadingSmoother::kMinHeadingRate; // [rad/s]
float max_heading_accel = HeadingSmoother::kMinHeadingAccel; // [rad/s^2]
float max_horizontal_accel = 0.f; // [m/s^2]
float max_down_accel = 0.f; // [m/s^2]
float max_up_accel = 0.f; // [m/s^2]
float max_jerk = 0.f; // [m/s^3]
float max_heading_rate = 0.f; // [rad/s]
float max_heading_accel = 0.f; // [rad/s^2]
};

/**
Expand Down Expand Up @@ -109,14 +110,14 @@ class GotoControl
_vehicle_constraints.max_horizontal_speed = math::max(kMinSpeed, vehicle_constraints.max_horizontal_speed);
_vehicle_constraints.max_down_speed = math::max(kMinSpeed, vehicle_constraints.max_down_speed);
_vehicle_constraints.max_up_speed = math::max(kMinSpeed, vehicle_constraints.max_up_speed);
_vehicle_constraints.max_horizontal_accel = math::max(VelocitySmoothing::kMinAccel,
_vehicle_constraints.max_horizontal_accel = math::max(0.f,
vehicle_constraints.max_horizontal_accel);
_vehicle_constraints.max_down_accel = math::max(VelocitySmoothing::kMinAccel, vehicle_constraints.max_down_accel);
_vehicle_constraints.max_up_accel = math::max(VelocitySmoothing::kMinAccel, vehicle_constraints.max_up_accel);
_vehicle_constraints.max_jerk = math::max(VelocitySmoothing::kMinJerk, vehicle_constraints.max_jerk);
_vehicle_constraints.max_heading_rate = math::max(HeadingSmoother::kMinHeadingRate,
_vehicle_constraints.max_down_accel = math::max(0.f, vehicle_constraints.max_down_accel);
_vehicle_constraints.max_up_accel = math::max(0.f, vehicle_constraints.max_up_accel);
_vehicle_constraints.max_jerk = math::max(0.f, vehicle_constraints.max_jerk);
_vehicle_constraints.max_heading_rate = math::max(0.f,
vehicle_constraints.max_heading_rate);
_vehicle_constraints.max_heading_accel = math::max(HeadingSmoother::kMinHeadingAccel,
_vehicle_constraints.max_heading_accel = math::max(0.f,
vehicle_constraints.max_heading_accel);
}

Expand Down Expand Up @@ -151,7 +152,7 @@ class GotoControl

VehicleConstraints _vehicle_constraints{};
PositionSmoothing _position_smoother;
HeadingSmoother _heading_smoother;
HeadingSmoothing _heading_smoother;

// flags that the next update() requires a valid current vehicle position to reset the smoothers
bool _need_smoother_reset{true};
Expand Down

0 comments on commit 355af09

Please sign in to comment.