blob: 96bd81728df7f2f7757d6d7e45361e2982e576e1 [file] [log] [blame]
Brian Silvermanb601d892015-12-20 18:24:38 -05001package y2014.control_loops;
Brian Silverman17f503e2015-08-02 18:17:18 -07002
3import "aos/common/controls/control_loops.q";
4
Brian Silverman51091a02015-12-26 15:56:58 -08005// For logging information about what the code is doing with the shifters.
Brian Silverman17f503e2015-08-02 18:17:18 -07006struct GearLogging {
Brian Silverman51091a02015-12-26 15:56:58 -08007 // Which controller is being used.
Brian Silverman17f503e2015-08-02 18:17:18 -07008 int8_t controller_index;
Brian Silverman51091a02015-12-26 15:56:58 -08009 // Whether the left loop is the high-gear one.
Brian Silverman17f503e2015-08-02 18:17:18 -070010 bool left_loop_high;
Brian Silverman51091a02015-12-26 15:56:58 -080011 // Whether the right loop is the high-gear one.
Brian Silverman17f503e2015-08-02 18:17:18 -070012 bool right_loop_high;
Brian Silverman51091a02015-12-26 15:56:58 -080013 // The state of the left shifter.
Brian Silverman17f503e2015-08-02 18:17:18 -070014 int8_t left_state;
Brian Silverman51091a02015-12-26 15:56:58 -080015 // The state of the right shifter.
Brian Silverman17f503e2015-08-02 18:17:18 -070016 int8_t right_state;
17};
18
Brian Silverman51091a02015-12-26 15:56:58 -080019// For logging information about the state of the shifters.
Brian Silverman17f503e2015-08-02 18:17:18 -070020struct CIMLogging {
Brian Silverman51091a02015-12-26 15:56:58 -080021 // Whether the code thinks the left side is currently in gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070022 bool left_in_gear;
Brian Silverman51091a02015-12-26 15:56:58 -080023 // Whether the code thinks the right side is currently in gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070024 bool right_in_gear;
Brian Silverman51091a02015-12-26 15:56:58 -080025 // The velocity in rad/s (positive forward) the code thinks the left motor
26 // is currently spinning at.
Brian Silverman17f503e2015-08-02 18:17:18 -070027 double left_motor_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080028 // The velocity in rad/s (positive forward) the code thinks the right motor
29 // is currently spinning at.
Brian Silverman17f503e2015-08-02 18:17:18 -070030 double right_motor_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080031 // The velocity estimate for the left side of the robot in m/s (positive
32 // forward) used for shifting.
Brian Silverman17f503e2015-08-02 18:17:18 -070033 double left_velocity;
Brian Silverman51091a02015-12-26 15:56:58 -080034 // The velocity estimate for the right side of the robot in m/s (positive
35 // forward) used for shifting.
Brian Silverman17f503e2015-08-02 18:17:18 -070036 double right_velocity;
37};
38
39queue_group DrivetrainQueue {
40 implements aos.control_loops.ControlLoop;
41
42 message Goal {
Brian Silverman51091a02015-12-26 15:56:58 -080043 // Position of the steering wheel (positive = turning left when going
44 // forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -070045 double steering;
Brian Silverman51091a02015-12-26 15:56:58 -080046 // Position of the throttle (positive forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -070047 double throttle;
Brian Silverman51091a02015-12-26 15:56:58 -080048 // True to shift into high, false to shift into low.
Brian Silverman17f503e2015-08-02 18:17:18 -070049 bool highgear;
Brian Silverman51091a02015-12-26 15:56:58 -080050 // True to activate quickturn.
Brian Silverman17f503e2015-08-02 18:17:18 -070051 bool quickturn;
Brian Silverman51091a02015-12-26 15:56:58 -080052 // True to have the closed-loop controller take over.
Brian Silverman17f503e2015-08-02 18:17:18 -070053 bool control_loop_driving;
Brian Silverman51091a02015-12-26 15:56:58 -080054 // Position goal for the left side in meters when the closed-loop controller
55 // is active.
Brian Silverman17f503e2015-08-02 18:17:18 -070056 double left_goal;
Brian Silverman51091a02015-12-26 15:56:58 -080057 // Velocity goal for the left side in m/s when the closed-loop controller
58 // is active.
Brian Silverman17f503e2015-08-02 18:17:18 -070059 double left_velocity_goal;
Brian Silverman51091a02015-12-26 15:56:58 -080060 // Position goal for the right side in meters when the closed-loop
61 // controller is active.
Brian Silverman17f503e2015-08-02 18:17:18 -070062 double right_goal;
Brian Silverman51091a02015-12-26 15:56:58 -080063 // Velocity goal for the right side in m/s when the closed-loop controller
64 // is active.
Brian Silverman17f503e2015-08-02 18:17:18 -070065 double right_velocity_goal;
66 };
67
68 message Position {
Brian Silverman51091a02015-12-26 15:56:58 -080069 // Relative position of the left side in meters.
Brian Silverman17f503e2015-08-02 18:17:18 -070070 double left_encoder;
Brian Silverman51091a02015-12-26 15:56:58 -080071 // Relative position of the right side in meters.
Brian Silverman17f503e2015-08-02 18:17:18 -070072 double right_encoder;
Brian Silverman51091a02015-12-26 15:56:58 -080073 // The speed in m/s of the left side from the most recent encoder pulse,
74 // or 0 if there was no edge within the last 5ms.
75 double left_speed;
76 // The speed in m/s of the right side from the most recent encoder pulse,
77 // or 0 if there was no edge within the last 5ms.
78 double right_speed;
79 // Position of the left shifter (smaller = towards low gear).
Brian Silverman17f503e2015-08-02 18:17:18 -070080 double left_shifter_position;
Brian Silverman51091a02015-12-26 15:56:58 -080081 // Position of the right shifter (smaller = towards low gear).
Brian Silverman17f503e2015-08-02 18:17:18 -070082 double right_shifter_position;
Austin Schuha0c1e152015-11-08 14:10:13 -080083 double low_left_hall;
84 double high_left_hall;
85 double low_right_hall;
86 double high_right_hall;
Brian Silverman17f503e2015-08-02 18:17:18 -070087 };
88
89 message Output {
Brian Silverman51091a02015-12-26 15:56:58 -080090 // Voltage to send to the left motor(s).
Brian Silverman17f503e2015-08-02 18:17:18 -070091 double left_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080092 // Voltage to send to the right motor(s).
Brian Silverman17f503e2015-08-02 18:17:18 -070093 double right_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080094 // True to set the left shifter piston for high gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070095 bool left_high;
Brian Silverman51091a02015-12-26 15:56:58 -080096 // True to set the right shifter piston for high gear.
Brian Silverman17f503e2015-08-02 18:17:18 -070097 bool right_high;
98 };
99
100 message Status {
Brian Silverman51091a02015-12-26 15:56:58 -0800101 // Estimated speed of the center of the robot in m/s (positive forwards).
Brian Silverman17f503e2015-08-02 18:17:18 -0700102 double robot_speed;
Brian Silverman51091a02015-12-26 15:56:58 -0800103 // Estimated relative position of the left side in meters.
Brian Silverman17f503e2015-08-02 18:17:18 -0700104 double filtered_left_position;
Brian Silverman51091a02015-12-26 15:56:58 -0800105 // Estimated relative position of the right side in meters.
Brian Silverman17f503e2015-08-02 18:17:18 -0700106 double filtered_right_position;
Brian Silverman51091a02015-12-26 15:56:58 -0800107 // Estimated velocity of the left side in m/s.
Brian Silverman17f503e2015-08-02 18:17:18 -0700108 double filtered_left_velocity;
Brian Silverman51091a02015-12-26 15:56:58 -0800109 // Estimated velocity of the left side in m/s.
Brian Silverman17f503e2015-08-02 18:17:18 -0700110 double filtered_right_velocity;
111
Brian Silverman51091a02015-12-26 15:56:58 -0800112 // The voltage we wanted to send to the left side last cycle.
Brian Silverman17f503e2015-08-02 18:17:18 -0700113 double uncapped_left_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -0800114 // The voltage we wanted to send to the right side last cycle.
Brian Silverman17f503e2015-08-02 18:17:18 -0700115 double uncapped_right_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -0800116 // True if the output voltage was capped last cycle.
Brian Silverman17f503e2015-08-02 18:17:18 -0700117 bool output_was_capped;
Brian Silverman17f503e2015-08-02 18:17:18 -0700118 };
119
120 queue Goal goal;
121 queue Position position;
122 queue Output output;
123 queue Status status;
124};
125
126queue_group DrivetrainQueue drivetrain_queue;