blob: 83c401d91bf4162606f079c9c20d620a2ea360b0 [file] [log] [blame]
James Kuszmaulfb0e0ae2014-03-25 07:04:47 -07001#ifndef FRC971_CONTROL_LOOPS_COERCE_GOAL_H_
2#define FRC971_CONTROL_LOOPS_COERCE_GOAL_H_
3
4#include "Eigen/Dense"
5
Briana6553ed2014-04-02 21:26:46 -07006#include "aos/common/controls/polytope.h"
James Kuszmaulfb0e0ae2014-03-25 07:04:47 -07007
8namespace frc971 {
9namespace control_loops {
10
Austin Schuhc7a0a3d2016-10-15 16:22:47 -070011Eigen::Matrix<double, 2, 1> DoCoerceGoal(
12 const aos::controls::HVPolytope<2, 4, 4> &region,
13 const Eigen::Matrix<double, 1, 2> &K, double w,
14 const Eigen::Matrix<double, 2, 1> &R, bool *is_inside);
Brian Silverman6dd2c532014-03-29 23:34:39 -070015
James Kuszmaulfb0e0ae2014-03-25 07:04:47 -070016// Intersects a line with a region, and finds the closest point to R.
17// Finds a point that is closest to R inside the region, and on the line
18// defined by K X = w. If it is not possible to find a point on the line,
19// finds a point that is inside the region and closest to the line.
Austin Schuhc7a0a3d2016-10-15 16:22:47 -070020static inline Eigen::Matrix<double, 2, 1> CoerceGoal(
21 const aos::controls::HVPolytope<2, 4, 4> &region,
22 const Eigen::Matrix<double, 1, 2> &K, double w,
23 const Eigen::Matrix<double, 2, 1> &R) {
Brian Silverman6dd2c532014-03-29 23:34:39 -070024 return DoCoerceGoal(region, K, w, R, nullptr);
25}
James Kuszmaulfb0e0ae2014-03-25 07:04:47 -070026
27} // namespace control_loops
28} // namespace frc971
29
30#endif // FRC971_CONTROL_LOOPS_COERCE_GOAL_H_