Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Navigation][Trajectory] solve the discontinued problem of yaw rotation #634

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PolynomialTrajectory : public ReferenceBase {
PolyType y_;
PolyType z_;
PolyType yaw_;
QuadState prev_constraint_;

std::vector<QuadState> states_;

Expand Down
5 changes: 4 additions & 1 deletion aerial_robot_control/src/flight_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,10 @@ void BaseNavigator::generateNewTrajectory(geometry_msgs::PoseStamped pose)
}

double du_tran = (end_state.p - start_state.p).norm() / trajectory_mean_vel_;
double du_rot = fabs(end_state.getYaw() - start_state.getYaw()) / trajectory_mean_yaw_rate_;
double delta_yaw = end_state.getYaw() - start_state.getYaw();
if (delta_yaw > M_PI) delta_yaw -= 2 * M_PI;
if (delta_yaw < -M_PI) delta_yaw += 2 * M_PI;
double du_rot = fabs(delta_yaw) / trajectory_mean_yaw_rate_;
double du = std::max(du_tran, trajectory_min_du_);
if (!enable_latch_yaw_trajectory_)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ PolynomialTrajectory<PolyType>::PolynomialTrajectory(
yaw_.scale(start_state_.t, duration_);

addStateConstraint(start_state_);
addStateConstraint(end_state_);

for (size_t i = 1; i < states_.size() - 1; i++) {
addStateConstraint(states_.at(i), 0); // only consider the position constraints for the intermediate points
}

addStateConstraint(end_state_);

if (!x_.solve()) std::cout << "Could not solve x-axis!" << std::endl;
if (!y_.solve()) std::cout << "Could not solve y-axis!" << std::endl;
Expand Down Expand Up @@ -116,9 +114,21 @@ bool PolynomialTrajectory<PolyType>::addStateConstraint(const QuadState& state,
z_.addConstraint(state.t, constraints.row(2).transpose());

// ToDo: Yaw relative to initial yaw.
const Scalar yaw_angle = state.getYaw();
Scalar yaw_angle = state.getYaw();
if (std::isfinite(yaw_angle))
yaw_.addConstraint(state.t, Vector<3>(yaw_angle, state.w.z(), 0));
{
if (std::isfinite(prev_constraint_.t))
{
Scalar prev_yaw_angle = prev_constraint_.getYaw();
Scalar diff = yaw_angle - prev_yaw_angle;
if (diff > M_PI) yaw_angle -= 2 * M_PI;
if (diff < -M_PI) yaw_angle += 2 * M_PI;
}
yaw_.addConstraint(state.t, Vector<3>(yaw_angle, state.w.z(), 0));
}


prev_constraint_ = state;

return true;
}
Expand Down
Loading