blob: e12a27fcb6c16edaa681a168697c0aeed6e1e4e7 [file] [log] [blame]
Brian Silverman431500a2013-10-28 19:50:15 -07001#ifndef FRC971_CONSTANTS_H_
2#define FRC971_CONSTANTS_H_
brians343bc112013-02-10 01:53:46 +00003#include <stdint.h>
4
Brian Silverman2c590c32013-11-04 18:08:54 -08005#include "frc971/control_loops/state_feedback_loop.h"
Daniel Pettiaece37f2014-10-25 17:13:44 -07006#include "frc971/shifter_hall_effect.h"
Brian Silverman2c590c32013-11-04 18:08:54 -08007
brians343bc112013-02-10 01:53:46 +00008namespace frc971 {
9namespace constants {
10
11// Has all of the numbers that change for both robots and makes it easy to
12// retrieve the values for the current one.
brians343bc112013-02-10 01:53:46 +000013
Brian Silverman5d712fc2015-02-15 03:39:31 -050014// Everything is in SI units (volts, radians, meters, seconds, etc).
15// Some of these values are related to the conversion between raw values
16// (encoder counts, voltage, etc) to scaled units (radians, meters, etc).
17
Brian Silverman431500a2013-10-28 19:50:15 -070018// This structure contains current values for all of the things that change.
19struct Values {
Comran Morshed79bd3db2015-02-07 14:51:13 +000020 // Drivetrain Values /////
Brian Silverman2c793712014-02-16 19:32:32 -080021
Brian Silverman1a6590d2013-11-04 14:46:46 -080022 // The ratio from the encoder shaft to the drivetrain wheels.
23 double drivetrain_encoder_ratio;
Daniel Pettia7827412015-02-13 20:55:57 -080024 // The ratio from the encoder shaft to the arm joint.
25 double arm_encoder_ratio;
26 // The ratio from the pot shaft to the arm joint.
27 double arm_pot_ratio;
28 // The ratio from the encoder shaft to the elevator output pulley.
29 double elev_encoder_ratio;
30 // The ratio from the pot shaft to the elevator output pulley.
31 double elev_pot_ratio;
32 // How far the elevator moves (meters) per radian on the output pulley.
33 double elev_distance_per_radian;
34 // The ratio from the encoder shaft to the claw joint.
35 double claw_encoder_ratio;
36 // The ratio from the pot shaft to the claw joint.
37 double claw_pot_ratio;
Brian Silverman1a6590d2013-11-04 14:46:46 -080038
39 // The gear ratios from motor shafts to the drivetrain wheels for high and low
40 // gear.
41 double low_gear_ratio;
42 double high_gear_ratio;
Brian Silverman6eb51f12013-11-02 14:39:01 -070043 ShifterHallEffect left_drive, right_drive;
Brian Silverman1a6590d2013-11-04 14:46:46 -080044 bool clutch_transmission;
45
Brian Silvermanad9e0002014-04-13 14:55:57 -070046 double turn_width;
47
Brian Silverman2c590c32013-11-04 18:08:54 -080048 ::std::function<StateFeedbackLoop<2, 2, 2>()> make_v_drivetrain_loop;
49 ::std::function<StateFeedbackLoop<4, 2, 2>()> make_drivetrain_loop;
Brian Silvermandfdcd582014-02-16 20:50:09 -080050
Ben Fredrickson890c3fe2014-03-02 00:15:16 +000051 double drivetrain_done_distance;
52 double drivetrain_max_speed;
Comran Morshed79bd3db2015-02-07 14:51:13 +000053
Comran Morshed79bd3db2015-02-07 14:51:13 +000054 // Superstructure Values /////
55
56 struct ZeroingConstants {
Austin Schuh703b8d42015-02-01 14:56:34 -080057 // The number of samples in the moving average filter.
Comran Morshed79bd3db2015-02-07 14:51:13 +000058 int average_filter_size;
Brian Silverman5d712fc2015-02-15 03:39:31 -050059 // The difference in scaled units between two index pulses.
Comran Morshed79bd3db2015-02-07 14:51:13 +000060 double index_difference;
Brian Silverman5d712fc2015-02-15 03:39:31 -050061 // The absolute position in scaled units of one of the index pulses.
Austin Schuh703b8d42015-02-01 14:56:34 -080062 double measured_index_position;
Comran Morshed79bd3db2015-02-07 14:51:13 +000063 };
64
Comran Morshed79bd3db2015-02-07 14:51:13 +000065 // Defines a range of motion for a subsystem.
Brian Silverman5d712fc2015-02-15 03:39:31 -050066 // These are all absolute positions in scaled units.
Comran Morshed79bd3db2015-02-07 14:51:13 +000067 struct Range {
68 double lower_hard_limit;
69 double upper_hard_limit;
70 double lower_limit;
71 double upper_limit;
72 };
73
74 struct Claw {
75 Range wrist;
Daniel Pettia7827412015-02-13 20:55:57 -080076 ZeroingConstants zeroing;
Brian Silverman5d712fc2015-02-15 03:39:31 -050077 // The value to add to potentiometer readings after they have been converted
78 // to radians so that the resulting value is 0 when the claw is at absolute
79 // 0 (horizontal straight out the front).
80 double potentiometer_offset;
Daniel Petti9cf68c82015-02-14 14:57:17 -080081
82 // Time between sending commands to claw opening pistons and them reaching
83 // the new state.
84 double piston_switch_time;
85 // How far on either side we look for the index pulse before we give up.
86 double zeroing_range;
Comran Morshed79bd3db2015-02-07 14:51:13 +000087 };
88 Claw claw;
89
90 struct Fridge {
91 Range elevator;
92 Range arm;
Daniel Pettia7827412015-02-13 20:55:57 -080093
94 ZeroingConstants left_elev_zeroing;
95 ZeroingConstants right_elev_zeroing;
96 ZeroingConstants left_arm_zeroing;
97 ZeroingConstants right_arm_zeroing;
Brian Silverman5d712fc2015-02-15 03:39:31 -050098
99 // Values to add to scaled potentiometer readings so 0 lines up with the
100 // physical absolute 0.
101 double left_elevator_potentiometer_offset;
102 double right_elevator_potentiometer_offset;
103 double left_arm_potentiometer_offset;
104 double right_arm_potentiometer_offset;
Daniel Pettie1bb13e2015-02-17 13:59:15 -0800105
106 // How high the elevator has to be before we start zeroing the arm.
107 double arm_zeroing_height;
Comran Morshed79bd3db2015-02-07 14:51:13 +0000108 };
109 Fridge fridge;
Austin Schuh703b8d42015-02-01 14:56:34 -0800110
111 double max_allowed_left_right_arm_difference;
112 double max_allowed_left_right_elevator_difference;
Brian Silverman431500a2013-10-28 19:50:15 -0700113};
114
Brian Silverman0a151c92014-05-02 15:28:44 -0700115// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
116// returns a reference to it.
Brian Silverman431500a2013-10-28 19:50:15 -0700117const Values &GetValues();
Brian Silverman0a151c92014-05-02 15:28:44 -0700118
119// Creates Values instances for each team number it is called with and returns
120// them.
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000121const Values &GetValuesForTeam(uint16_t team_number);
brians343bc112013-02-10 01:53:46 +0000122
123} // namespace constants
124} // namespace frc971
Brian Silverman431500a2013-10-28 19:50:15 -0700125
126#endif // FRC971_CONSTANTS_H_