blob: 7ff0498544918e5c25cc710ae4224073209827cd [file] [log] [blame]
Austin Schuh6d1ee0c2015-11-21 14:36:04 -08001package y2015_bot3.control_loops;
Comran Morshed0d6cf9b2015-06-17 19:29:57 +00002
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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +00006struct GearLogging {
Brian Silverman51091a02015-12-26 15:56:58 -08007 // Which controller is being used.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +00008 int8_t controller_index;
Brian Silverman51091a02015-12-26 15:56:58 -08009 // Whether the left loop is the high-gear one.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000010 bool left_loop_high;
Brian Silverman51091a02015-12-26 15:56:58 -080011 // Whether the right loop is the high-gear one.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000012 bool right_loop_high;
Brian Silverman51091a02015-12-26 15:56:58 -080013 // The state of the left shifter.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000014 int8_t left_state;
Brian Silverman51091a02015-12-26 15:56:58 -080015 // The state of the right shifter.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000016 int8_t right_state;
17};
18
Brian Silverman51091a02015-12-26 15:56:58 -080019// For logging information about the state of the shifters.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000020struct CIMLogging {
Brian Silverman51091a02015-12-26 15:56:58 -080021 // Whether the code thinks the left side is currently in gear.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000022 bool left_in_gear;
Brian Silverman51091a02015-12-26 15:56:58 -080023 // Whether the code thinks the right side is currently in gear.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000024 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000027 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000030 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000033 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000036 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).
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000045 double steering;
Brian Silverman51091a02015-12-26 15:56:58 -080046 // Position of the throttle (positive forwards).
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000047 double throttle;
Brian Silverman51091a02015-12-26 15:56:58 -080048 // True to shift into high, false to shift into low.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000049 //bool highgear;
Brian Silverman51091a02015-12-26 15:56:58 -080050 // True to activate quickturn.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000051 bool quickturn;
Brian Silverman51091a02015-12-26 15:56:58 -080052 // True to have the closed-loop controller take over.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000053 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000056 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000059 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000062 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000065 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.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000070 double left_encoder;
Brian Silverman51091a02015-12-26 15:56:58 -080071 // Relative position of the right side in meters.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000072 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).
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000080 //double left_shifter_position;
Brian Silverman51091a02015-12-26 15:56:58 -080081 // Position of the right shifter (smaller = towards low gear).
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000082 //double right_shifter_position;
83 };
84
85 message Output {
Brian Silverman51091a02015-12-26 15:56:58 -080086 // Voltage to send to the left motor(s).
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000087 double left_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080088 // Voltage to send to the right motor(s).
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000089 double right_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080090 // True to set the left shifter piston for high gear.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000091 bool left_high;
Brian Silverman51091a02015-12-26 15:56:58 -080092 // True to set the right shifter piston for high gear.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000093 bool right_high;
94 };
95
96 message Status {
Brian Silverman51091a02015-12-26 15:56:58 -080097 // Estimated speed of the center of the robot in m/s (positive forwards).
Comran Morshed0d6cf9b2015-06-17 19:29:57 +000098 double robot_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080099 // Estimated relative position of the left side in meters.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +0000100 double filtered_left_position;
Brian Silverman51091a02015-12-26 15:56:58 -0800101 // Estimated relative position of the right side in meters.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +0000102 double filtered_right_position;
Brian Silverman51091a02015-12-26 15:56:58 -0800103 // Estimated velocity of the left side in m/s.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +0000104 double filtered_left_velocity;
Brian Silverman51091a02015-12-26 15:56:58 -0800105 // Estimated velocity of the right side in m/s.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +0000106 double filtered_right_velocity;
107
Brian Silverman51091a02015-12-26 15:56:58 -0800108 // The voltage we wanted to send to the left side last cycle.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +0000109 double uncapped_left_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -0800110 // The voltage we wanted to send to the right side last cycle.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +0000111 double uncapped_right_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -0800112 // True if the output voltage was capped last cycle.
Comran Morshed0d6cf9b2015-06-17 19:29:57 +0000113 bool output_was_capped;
Comran Morshed0d6cf9b2015-06-17 19:29:57 +0000114 };
115
116 queue Goal goal;
117 queue Position position;
118 queue Output output;
119 queue Status status;
120};
121
122queue_group DrivetrainQueue drivetrain_queue;