blob: f5f53bbb1e52eec37cee038d473596de21e8fad0 [file] [log] [blame]
Comran Morshed41ed7c22015-11-04 21:03:37 +00001package y2014_bot3.control_loops;
Comran Morshede9b12922015-11-04 19:46:48 +00002
3import "aos/common/controls/control_loops.q";
4
Brian Silverman51091a02015-12-26 15:56:58 -08005// For logging information about the state of the shifters.
Comran Morshede9b12922015-11-04 19:46:48 +00006struct CIMLogging {
Brian Silverman51091a02015-12-26 15:56:58 -08007 // Whether the code thinks the left side is currently in gear.
Comran Morshede9b12922015-11-04 19:46:48 +00008 bool left_in_gear;
Brian Silverman51091a02015-12-26 15:56:58 -08009 // Whether the code thinks the right side is currently in gear.
Comran Morshede9b12922015-11-04 19:46:48 +000010 bool right_in_gear;
Brian Silverman51091a02015-12-26 15:56:58 -080011 // The velocity in rad/s (positive forward) the code thinks the left motor
12 // is currently spinning at.
Comran Morshede9b12922015-11-04 19:46:48 +000013 double left_motor_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080014 // The velocity in rad/s (positive forward) the code thinks the right motor
15 // is currently spinning at.
Comran Morshede9b12922015-11-04 19:46:48 +000016 double right_motor_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080017 // The velocity estimate for the left side of the robot in m/s (positive
18 // forward) used for shifting.
Comran Morshede9b12922015-11-04 19:46:48 +000019 double left_velocity;
Brian Silverman51091a02015-12-26 15:56:58 -080020 // The velocity estimate for the right side of the robot in m/s (positive
21 // forward) used for shifting.
Comran Morshede9b12922015-11-04 19:46:48 +000022 double right_velocity;
23};
24
Comran Morshed41ed7c22015-11-04 21:03:37 +000025queue_group DrivetrainQueue {
Comran Morshede9b12922015-11-04 19:46:48 +000026 implements aos.control_loops.ControlLoop;
27
28 message Goal {
Brian Silverman51091a02015-12-26 15:56:58 -080029 // Position of the steering wheel (positive = turning left when going
30 // forwards).
Comran Morshede9b12922015-11-04 19:46:48 +000031 double steering;
Brian Silverman51091a02015-12-26 15:56:58 -080032 // Position of the throttle (positive forwards).
Comran Morshede9b12922015-11-04 19:46:48 +000033 double throttle;
Brian Silverman51091a02015-12-26 15:56:58 -080034 // True to shift into high, false to shift into low.
Comran Morshede9b12922015-11-04 19:46:48 +000035 bool highgear;
Brian Silverman51091a02015-12-26 15:56:58 -080036 // True to activate quickturn.
Comran Morshede9b12922015-11-04 19:46:48 +000037 bool quickturn;
Brian Silverman51091a02015-12-26 15:56:58 -080038 // True to have the closed-loop controller take over.
Comran Morshede9b12922015-11-04 19:46:48 +000039 bool control_loop_driving;
Brian Silverman51091a02015-12-26 15:56:58 -080040 // Position goal for the left side in meters when the closed-loop controller
41 // is active.
Comran Morshede9b12922015-11-04 19:46:48 +000042 double left_goal;
Brian Silverman51091a02015-12-26 15:56:58 -080043 // Velocity goal for the left side in m/s when the closed-loop controller
44 // is active.
Comran Morshede9b12922015-11-04 19:46:48 +000045 double left_velocity_goal;
Brian Silverman51091a02015-12-26 15:56:58 -080046 // Position goal for the right side in meters when the closed-loop
47 // controller is active.
Comran Morshede9b12922015-11-04 19:46:48 +000048 double right_goal;
Brian Silverman51091a02015-12-26 15:56:58 -080049 // Velocity goal for the right side in m/s when the closed-loop controller
50 // is active.
Comran Morshede9b12922015-11-04 19:46:48 +000051 double right_velocity_goal;
52 };
53
54 message Position {
Brian Silverman51091a02015-12-26 15:56:58 -080055 // Relative position of the left side in meters.
Comran Morshede9b12922015-11-04 19:46:48 +000056 double left_encoder;
Brian Silverman51091a02015-12-26 15:56:58 -080057 // Relative position of the right side in meters.
Comran Morshede9b12922015-11-04 19:46:48 +000058 double right_encoder;
Brian Silverman51091a02015-12-26 15:56:58 -080059 // The speed in m/s of the left side from the most recent encoder pulse,
60 // or 0 if there was no edge within the last 5ms.
61 double left_speed;
62 // The speed in m/s of the right side from the most recent encoder pulse,
63 // or 0 if there was no edge within the last 5ms.
64 double right_speed;
Comran Morshede9b12922015-11-04 19:46:48 +000065 };
66
67 message Output {
Brian Silverman51091a02015-12-26 15:56:58 -080068 // Voltage to send to the left motor(s).
Comran Morshede9b12922015-11-04 19:46:48 +000069 double left_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080070 // Voltage to send to the right motor(s).
Comran Morshede9b12922015-11-04 19:46:48 +000071 double right_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080072 // True to set the left shifter piston for high gear.
Comran Morshede9b12922015-11-04 19:46:48 +000073 bool left_high;
Brian Silverman51091a02015-12-26 15:56:58 -080074 // True to set the right shifter piston for high gear.
Comran Morshede9b12922015-11-04 19:46:48 +000075 bool right_high;
76 };
77
78 message Status {
Brian Silverman51091a02015-12-26 15:56:58 -080079 // Estimated speed of the center of the robot in m/s (positive forwards).
Comran Morshede9b12922015-11-04 19:46:48 +000080 double robot_speed;
Brian Silverman51091a02015-12-26 15:56:58 -080081 // Estimated relative position of the left side in meters.
Comran Morshede9b12922015-11-04 19:46:48 +000082 double filtered_left_position;
Brian Silverman51091a02015-12-26 15:56:58 -080083 // Estimated relative position of the right side in meters.
Comran Morshede9b12922015-11-04 19:46:48 +000084 double filtered_right_position;
Brian Silverman51091a02015-12-26 15:56:58 -080085 // Estimated velocity of the left side in m/s.
Comran Morshed41ed7c22015-11-04 21:03:37 +000086 double filtered_left_velocity;
Brian Silverman51091a02015-12-26 15:56:58 -080087 // Estimated velocity of the right side in m/s.
Comran Morshed41ed7c22015-11-04 21:03:37 +000088 double filtered_right_velocity;
Comran Morshede9b12922015-11-04 19:46:48 +000089
Brian Silverman51091a02015-12-26 15:56:58 -080090 // The voltage we wanted to send to the left side last cycle.
Comran Morshede9b12922015-11-04 19:46:48 +000091 double uncapped_left_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080092 // The voltage we wanted to send to the right side last cycle.
Comran Morshede9b12922015-11-04 19:46:48 +000093 double uncapped_right_voltage;
Brian Silverman51091a02015-12-26 15:56:58 -080094 // True if the output voltage was capped last cycle.
Comran Morshede9b12922015-11-04 19:46:48 +000095 bool output_was_capped;
Comran Morshede9b12922015-11-04 19:46:48 +000096 };
97
98 queue Goal goal;
99 queue Position position;
100 queue Output output;
101 queue Status status;
102};
103
Comran Morshed41ed7c22015-11-04 21:03:37 +0000104queue_group DrivetrainQueue drivetrain_queue;