Brian Silverman | 8d3816a | 2017-07-03 18:52:15 -0700 | [diff] [blame^] | 1 | #ifndef MOTORS_ALGORITHMS_H_ |
| 2 | #define MOTORS_ALGORITHMS_H_ |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | namespace frc971 { |
| 7 | namespace salsa { |
| 8 | |
| 9 | struct ReadingsToBalance { |
| 10 | // Adds a single reading at index. |
| 11 | void Add(int index, int32_t value) { |
| 12 | sums[index] += value; |
| 13 | ++weights[index]; |
| 14 | } |
| 15 | |
| 16 | int32_t sums[3]; |
| 17 | int weights[3]; |
| 18 | }; |
| 19 | |
| 20 | struct BalancedReadings { |
| 21 | float readings[3]; |
| 22 | }; |
| 23 | |
| 24 | // Returns three readings which add up to 0 and are the same distances apart as |
| 25 | // the input ones (by weight). The distances between the averages of the inputs |
| 26 | // and the corresponding outputs will be inversely proportional to the weights. |
| 27 | BalancedReadings BalanceReadings(ReadingsToBalance to_balance); |
| 28 | |
| 29 | } // namespace salsa |
| 30 | } // namespace frc971 |
| 31 | |
| 32 | #endif // MOTORS_ALGORITHMS_H_ |