blob: 3edd33f34ce30695b9165b6f2f16921aff6609ea [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001package frc971.control_loops;
2
Briana6553ed2014-04-02 21:26:46 -07003import "aos/common/controls/control_loops.q";
brians343bc112013-02-10 01:53:46 +00004
Brian Silverman51091a02015-12-26 15:56:58 -08005// For logging information about what the code is doing with the shifters.
Brian Silverman61e41fd2014-02-16 19:08:50 -08006struct GearLogging {
Brian Silverman51091a02015-12-26 15:56:58 -08007 // Which controller is being used.
Brian Silverman61e41fd2014-02-16 19:08:50 -08008 int8_t controller_index;
Brian Silverman51091a02015-12-26 15:56:58 -08009 // Whether the left loop is the high-gear one.
Brian Silverman61e41fd2014-02-16 19:08:50 -080010 bool left_loop_high;
Brian Silverman51091a02015-12-26 15:56:58 -080011 // Whether the right loop is the high-gear one.
Brian Silverman61e41fd2014-02-16 19:08:50 -080012 bool right_loop_high;
Brian Silverman51091a02015-12-26 15:56:58 -080013 // The state of the left shifter.
Brian Silverman61e41fd2014-02-16 19:08:50 -080014 int8_t left_state;
Brian Silverman51091a02015-12-26 15:56:58 -080015 // The state of the right shifter.
Brian Silverman61e41fd2014-02-16 19:08:50 -080016 int8_t right_state;
17};
18
Brian Silverman51091a02015-12-26 15:56:58 -080019// For logging information about the state of the shifters.
Brian Silverman61e41fd2014-02-16 19:08:50 -080020struct CIMLogging {
Brian Silverman51091a02015-12-26 15:56:58 -080021 // Whether the code thinks the left side is currently in gear.
Brian Silverman61e41fd2014-02-16 19:08:50 -080022 bool left_in_gear;
Brian Silverman51091a02015-12-26 15:56:58 -080023 // Whether the code thinks the right side is currently in gear.
Brian Silverman61e41fd2014-02-16 19:08:50 -080024 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 Silverman61e41fd2014-02-16 19:08:50 -080027 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 Silverman61e41fd2014-02-16 19:08:50 -080030 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 Silverman61e41fd2014-02-16 19:08:50 -080033 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 Silverman61e41fd2014-02-16 19:08:50 -080036 double right_velocity;
37};
38
Brian Silvermanada5f2c2015-02-01 02:41:14 -050039queue_group DrivetrainQueue {
brians343bc112013-02-10 01:53:46 +000040 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 Silvermanb94069c2014-04-17 14:34:24 -070045 double steering;
Brian Silverman51091a02015-12-26 15:56:58 -080046 // Position of the throttle (positive forwards).
Brian Silvermanb94069c2014-04-17 14:34:24 -070047 double throttle;
Brian Silverman51091a02015-12-26 15:56:58 -080048 // True to shift into high, false to shift into low.
Brian Silverman93335ae2015-01-26 20:43:39 -050049 //bool highgear;
Brian Silverman51091a02015-12-26 15:56:58 -080050 // True to activate quickturn.
brians343bc112013-02-10 01:53:46 +000051 bool quickturn;
Brian Silverman51091a02015-12-26 15:56:58 -080052 // True to have the closed-loop controller take over.
brians343bc112013-02-10 01:53:46 +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.
Brian Silvermanb94069c2014-04-17 14:34:24 -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 Silvermanb94069c2014-04-17 14:34:24 -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 Silvermanb94069c2014-04-17 14:34:24 -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 Silvermanb94069c2014-04-17 14:34:24 -070065 double right_velocity_goal;
brians343bc112013-02-10 01:53:46 +000066 };
67
68 message Position {
Brian Silverman51091a02015-12-26 15:56:58 -080069 // Relative position of the left side in meters.
brians343bc112013-02-10 01:53:46 +000070 double left_encoder;
Brian Silverman51091a02015-12-26 15:56:58 -080071 // Relative position of the right side in meters.
brians343bc112013-02-10 01:53:46 +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).
Brian Silverman93335ae2015-01-26 20:43:39 -050080 //double left_shifter_position;
Brian Silverman51091a02015-12-26 15:56:58 -080081 // Position of the right shifter (smaller = towards low gear).
Brian Silverman93335ae2015-01-26 20:43:39 -050082 //double right_shifter_position;
brians343bc112013-02-10 01:53:46 +000083 };
84
85 message Output {
Brian Silverman51091a02015-12-26 15:56:58 -080086 // Voltage to send to the left motor(s).
Brian Silvermanb94069c2014-04-17 14:34:24 -070087 double left_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080088 // Voltage to send to the right motor(s).
Brian Silvermanb94069c2014-04-17 14:34:24 -070089 double right_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080090 // True to set the left shifter piston for high gear.
Ben Fredrickson890c3fe2014-03-02 00:15:16 +000091 bool left_high;
Brian Silverman51091a02015-12-26 15:56:58 -080092 // True to set the right shifter piston for high gear.
Ben Fredrickson890c3fe2014-03-02 00:15:16 +000093 bool right_high;
brians343bc112013-02-10 01:53:46 +000094 };
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).
Ben Fredrickson890c3fe2014-03-02 00:15:16 +000098 double robot_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080099 // Estimated relative position of the left side in meters.
Austin Schuh093535c2016-03-05 23:21:00 -0800100 double estimated_left_position;
Brian Silverman51091a02015-12-26 15:56:58 -0800101 // Estimated relative position of the right side in meters.
Austin Schuh093535c2016-03-05 23:21:00 -0800102 double estimated_right_position;
Brian Silverman51091a02015-12-26 15:56:58 -0800103 // Estimated velocity of the left side in m/s.
Austin Schuh093535c2016-03-05 23:21:00 -0800104 double estimated_left_velocity;
Brian Silverman51091a02015-12-26 15:56:58 -0800105 // Estimated velocity of the right side in m/s.
Austin Schuh093535c2016-03-05 23:21:00 -0800106 double estimated_right_velocity;
Brian Silvermanb94069c2014-04-17 14:34:24 -0700107
Brian Silverman51091a02015-12-26 15:56:58 -0800108 // The voltage we wanted to send to the left side last cycle.
Brian Silvermanb94069c2014-04-17 14:34:24 -0700109 double uncapped_left_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -0800110 // The voltage we wanted to send to the right side last cycle.
Brian Silvermanb94069c2014-04-17 14:34:24 -0700111 double uncapped_right_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -0800112 // True if the output voltage was capped last cycle.
Brian Silvermanb94069c2014-04-17 14:34:24 -0700113 bool output_was_capped;
brians343bc112013-02-10 01:53:46 +0000114 };
115
116 queue Goal goal;
117 queue Position position;
118 queue Output output;
119 queue Status status;
120};
121
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500122queue_group DrivetrainQueue drivetrain_queue;