blob: d1fce7ade15cc8479cb8f918715cae955f9ef7c9 [file] [log] [blame]
Brian Silverman8d3816a2017-07-03 18:52:15 -07001#ifndef MOTORS_ALGORITHMS_H_
2#define MOTORS_ALGORITHMS_H_
3
4#include <stdint.h>
5
6namespace frc971 {
7namespace salsa {
8
9struct 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
20struct 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.
27BalancedReadings BalanceReadings(ReadingsToBalance to_balance);
28
29} // namespace salsa
30} // namespace frc971
31
32#endif // MOTORS_ALGORITHMS_H_