Skip to content
Snippets Groups Projects
Commit c3a4fff0 authored by bresch's avatar bresch Committed by Roman Bapst
Browse files

Auto traj - generate heading from trajectory velocity vector if possible

parent 066d1f50
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,7 @@ bool FlightTaskAutoLineSmoothVel::activate()
_trajectory[i].reset(0.f, _velocity(i), _position(i));
}
_yaw_sp_prev = _yaw;
_updateTrajConstraints();
return ret;
......@@ -71,21 +72,37 @@ void FlightTaskAutoLineSmoothVel::_setDefaultConstraints()
void FlightTaskAutoLineSmoothVel::_generateSetpoints()
{
_prepareSetpoints();
_generateTrajectory();
if (!PX4_ISFINITE(_yaw_setpoint)) {
// no valid heading -> set heading along track
// TODO: Generate heading along trajectory velocity vector
_generateHeadingAlongTrack();
// no valid heading -> generate heading in this flight task
_generateHeading();
}
}
_prepareSetpoints();
_generateTrajectory();
void FlightTaskAutoLineSmoothVel::_generateHeading()
{
// Generate heading along trajectory if possible, otherwise hold the previous yaw setpoint
if (!_generateHeadingAlongTraj()) {
_yaw_setpoint = _yaw_sp_prev;
}
_yaw_sp_prev = _yaw_setpoint;
}
void FlightTaskAutoLineSmoothVel::_generateHeadingAlongTrack()
bool FlightTaskAutoLineSmoothVel::_generateHeadingAlongTraj()
{
Vector2f prev_to_dest(_target - _prev_wp);
_compute_heading_from_2D_vector(_yaw_setpoint, prev_to_dest);
bool res = false;
Vector2f vel_sp_xy(_velocity_setpoint);
if (vel_sp_xy.length() > .01f) {
// Generate heading from velocity vector, only if it is long enough
_compute_heading_from_2D_vector(_yaw_setpoint, vel_sp_xy);
res = true;
}
return res;
}
/* Constrain some value vith a constrain depending on the sign of the constrain
......
......@@ -69,9 +69,11 @@ protected:
void _setDefaultConstraints() override;
inline float constrain_one_side(float val, float constrain);
void _generateHeadingAlongTrack(); /**< Generates heading along track. */
void _generateHeading();
bool _generateHeadingAlongTraj(); /**< Generates heading along trajectory. */
void _updateTrajConstraints();
void _prepareSetpoints(); /**< Generate velocity target points for the trajectory generator. */
void _generateTrajectory();
VelocitySmoothing _trajectory[3]; ///< Trajectories in x, y and z directions
float _yaw_sp_prev;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment