blob: 85c06bb484c5b20d5cd56acb67e38f839cd20319 [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
54
55 // Superstructure Values /////
56
57 struct ZeroingConstants {
Austin Schuh703b8d42015-02-01 14:56:34 -080058 // The number of samples in the moving average filter.
Comran Morshed79bd3db2015-02-07 14:51:13 +000059 int average_filter_size;
Brian Silverman5d712fc2015-02-15 03:39:31 -050060 // The difference in scaled units between two index pulses.
Comran Morshed79bd3db2015-02-07 14:51:13 +000061 double index_difference;
Brian Silverman5d712fc2015-02-15 03:39:31 -050062 // The absolute position in scaled units of one of the index pulses.
Austin Schuh703b8d42015-02-01 14:56:34 -080063 double measured_index_position;
Comran Morshed79bd3db2015-02-07 14:51:13 +000064 };
65
Comran Morshed79bd3db2015-02-07 14:51:13 +000066 // Defines a range of motion for a subsystem.
Brian Silverman5d712fc2015-02-15 03:39:31 -050067 // These are all absolute positions in scaled units.
Comran Morshed79bd3db2015-02-07 14:51:13 +000068 struct Range {
69 double lower_hard_limit;
70 double upper_hard_limit;
71 double lower_limit;
72 double upper_limit;
73 };
74
75 struct Claw {
76 Range wrist;
Daniel Pettia7827412015-02-13 20:55:57 -080077 ZeroingConstants zeroing;
Brian Silverman5d712fc2015-02-15 03:39:31 -050078 // The value to add to potentiometer readings after they have been converted
79 // to radians so that the resulting value is 0 when the claw is at absolute
80 // 0 (horizontal straight out the front).
81 double potentiometer_offset;
Daniel Petti9cf68c82015-02-14 14:57:17 -080082
83 // Time between sending commands to claw opening pistons and them reaching
84 // the new state.
85 double piston_switch_time;
86 // How far on either side we look for the index pulse before we give up.
87 double zeroing_range;
Comran Morshed79bd3db2015-02-07 14:51:13 +000088 };
89 Claw claw;
90
91 struct Fridge {
92 Range elevator;
93 Range arm;
Daniel Pettia7827412015-02-13 20:55:57 -080094
95 ZeroingConstants left_elev_zeroing;
96 ZeroingConstants right_elev_zeroing;
97 ZeroingConstants left_arm_zeroing;
98 ZeroingConstants right_arm_zeroing;
Brian Silverman5d712fc2015-02-15 03:39:31 -050099
100 // Values to add to scaled potentiometer readings so 0 lines up with the
101 // physical absolute 0.
102 double left_elevator_potentiometer_offset;
103 double right_elevator_potentiometer_offset;
104 double left_arm_potentiometer_offset;
105 double right_arm_potentiometer_offset;
Comran Morshed79bd3db2015-02-07 14:51:13 +0000106 };
107 Fridge fridge;
Austin Schuh703b8d42015-02-01 14:56:34 -0800108
109 double max_allowed_left_right_arm_difference;
110 double max_allowed_left_right_elevator_difference;
Brian Silverman431500a2013-10-28 19:50:15 -0700111};
112
Brian Silverman0a151c92014-05-02 15:28:44 -0700113// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
114// returns a reference to it.
Brian Silverman431500a2013-10-28 19:50:15 -0700115const Values &GetValues();
Brian Silverman0a151c92014-05-02 15:28:44 -0700116
117// Creates Values instances for each team number it is called with and returns
118// them.
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000119const Values &GetValuesForTeam(uint16_t team_number);
brians343bc112013-02-10 01:53:46 +0000120
121} // namespace constants
122} // namespace frc971
Brian Silverman431500a2013-10-28 19:50:15 -0700123
124#endif // FRC971_CONSTANTS_H_