blob: 59049c542d64dcbe78900db329a5ad765c7023b3 [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
6#include "aos/controls/polytope.h"
7
8namespace frc971 {
9namespace control_loops {
10
Brian Silverman6dd2c532014-03-29 23:34:39 -070011Eigen::Matrix<double, 2, 1> DoCoerceGoal(const aos::controls::HPolytope<2> &region,
12 const Eigen::Matrix<double, 1, 2> &K,
13 double w,
14 const Eigen::Matrix<double, 2, 1> &R,
15 bool *is_inside);
16
James Kuszmaulfb0e0ae2014-03-25 07:04:47 -070017// Intersects a line with a region, and finds the closest point to R.
18// Finds a point that is closest to R inside the region, and on the line
19// defined by K X = w. If it is not possible to find a point on the line,
20// finds a point that is inside the region and closest to the line.
Brian Silverman6dd2c532014-03-29 23:34:39 -070021static inline Eigen::Matrix<double, 2, 1>
22 CoerceGoal(const aos::controls::HPolytope<2> &region,
23 const Eigen::Matrix<double, 1, 2> &K,
24 double w,
25 const Eigen::Matrix<double, 2, 1> &R) {
26 return DoCoerceGoal(region, K, w, R, nullptr);
27}
James Kuszmaulfb0e0ae2014-03-25 07:04:47 -070028
29} // namespace control_loops
30} // namespace frc971
31
32#endif // FRC971_CONTROL_LOOPS_COERCE_GOAL_H_