blob: 18e85ae27154e316042a7c6af860f0af7233bd8c [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
Daniel Pettidfc90ba2015-02-17 21:42:15 -080039 // How tall a tote is in meters.
40 double tote_height;
41
Brian Silverman1a6590d2013-11-04 14:46:46 -080042 // The gear ratios from motor shafts to the drivetrain wheels for high and low
43 // gear.
44 double low_gear_ratio;
45 double high_gear_ratio;
Brian Silverman6eb51f12013-11-02 14:39:01 -070046 ShifterHallEffect left_drive, right_drive;
Brian Silverman1a6590d2013-11-04 14:46:46 -080047 bool clutch_transmission;
48
Brian Silvermanad9e0002014-04-13 14:55:57 -070049 double turn_width;
50
Brian Silverman2c590c32013-11-04 18:08:54 -080051 ::std::function<StateFeedbackLoop<2, 2, 2>()> make_v_drivetrain_loop;
52 ::std::function<StateFeedbackLoop<4, 2, 2>()> make_drivetrain_loop;
Brian Silvermandfdcd582014-02-16 20:50:09 -080053
Ben Fredrickson890c3fe2014-03-02 00:15:16 +000054 double drivetrain_done_distance;
55 double drivetrain_max_speed;
Comran Morshed79bd3db2015-02-07 14:51:13 +000056
Comran Morshed79bd3db2015-02-07 14:51:13 +000057 // Superstructure Values /////
58
59 struct ZeroingConstants {
Austin Schuh703b8d42015-02-01 14:56:34 -080060 // The number of samples in the moving average filter.
Comran Morshed79bd3db2015-02-07 14:51:13 +000061 int average_filter_size;
Brian Silverman5d712fc2015-02-15 03:39:31 -050062 // The difference in scaled units between two index pulses.
Comran Morshed79bd3db2015-02-07 14:51:13 +000063 double index_difference;
Brian Silverman5d712fc2015-02-15 03:39:31 -050064 // The absolute position in scaled units of one of the index pulses.
Austin Schuh703b8d42015-02-01 14:56:34 -080065 double measured_index_position;
Comran Morshed79bd3db2015-02-07 14:51:13 +000066 };
67
Comran Morshed79bd3db2015-02-07 14:51:13 +000068 // Defines a range of motion for a subsystem.
Brian Silverman5d712fc2015-02-15 03:39:31 -050069 // These are all absolute positions in scaled units.
Comran Morshed79bd3db2015-02-07 14:51:13 +000070 struct Range {
71 double lower_hard_limit;
72 double upper_hard_limit;
73 double lower_limit;
74 double upper_limit;
75 };
76
77 struct Claw {
78 Range wrist;
Daniel Pettia7827412015-02-13 20:55:57 -080079 ZeroingConstants zeroing;
Brian Silverman5d712fc2015-02-15 03:39:31 -050080 // The value to add to potentiometer readings after they have been converted
81 // to radians so that the resulting value is 0 when the claw is at absolute
82 // 0 (horizontal straight out the front).
83 double potentiometer_offset;
Daniel Petti9cf68c82015-02-14 14:57:17 -080084
85 // Time between sending commands to claw opening pistons and them reaching
86 // the new state.
87 double piston_switch_time;
88 // How far on either side we look for the index pulse before we give up.
89 double zeroing_range;
Comran Morshed79bd3db2015-02-07 14:51:13 +000090 };
91 Claw claw;
92
93 struct Fridge {
94 Range elevator;
95 Range arm;
Daniel Pettia7827412015-02-13 20:55:57 -080096
97 ZeroingConstants left_elev_zeroing;
98 ZeroingConstants right_elev_zeroing;
99 ZeroingConstants left_arm_zeroing;
100 ZeroingConstants right_arm_zeroing;
Brian Silverman5d712fc2015-02-15 03:39:31 -0500101
102 // Values to add to scaled potentiometer readings so 0 lines up with the
103 // physical absolute 0.
104 double left_elevator_potentiometer_offset;
105 double right_elevator_potentiometer_offset;
106 double left_arm_potentiometer_offset;
107 double right_arm_potentiometer_offset;
Daniel Pettie1bb13e2015-02-17 13:59:15 -0800108
109 // How high the elevator has to be before we start zeroing the arm.
110 double arm_zeroing_height;
Comran Morshed79bd3db2015-02-07 14:51:13 +0000111 };
112 Fridge fridge;
Austin Schuh703b8d42015-02-01 14:56:34 -0800113
114 double max_allowed_left_right_arm_difference;
115 double max_allowed_left_right_elevator_difference;
Brian Silverman431500a2013-10-28 19:50:15 -0700116};
117
Brian Silverman0a151c92014-05-02 15:28:44 -0700118// Creates (once) a Values instance for ::aos::network::GetTeamNumber() and
119// returns a reference to it.
Brian Silverman431500a2013-10-28 19:50:15 -0700120const Values &GetValues();
Brian Silverman0a151c92014-05-02 15:28:44 -0700121
122// Creates Values instances for each team number it is called with and returns
123// them.
Ben Fredricksona9dcfa42014-02-23 02:05:59 +0000124const Values &GetValuesForTeam(uint16_t team_number);
brians343bc112013-02-10 01:53:46 +0000125
126} // namespace constants
127} // namespace frc971
Brian Silverman431500a2013-10-28 19:50:15 -0700128
129#endif // FRC971_CONSTANTS_H_