Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 1 | #include <math.h> |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | #include "aos/common/actions/actions.h" |
| 7 | #include "aos/common/input/driver_station_data.h" |
| 8 | #include "aos/common/logging/logging.h" |
| 9 | #include "aos/common/time.h" |
| 10 | #include "aos/common/util/log_interval.h" |
| 11 | #include "aos/input/drivetrain_input.h" |
| 12 | #include "aos/input/joystick_input.h" |
| 13 | #include "aos/linux_code/init.h" |
Austin Schuh | a3c148e | 2018-03-09 21:04:05 -0800 | [diff] [blame] | 14 | #include "frc971/autonomous/auto.q.h" |
| 15 | #include "frc971/autonomous/base_autonomous_actor.h" |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 16 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 17 | #include "y2018/control_loops/drivetrain/drivetrain_base.h" |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 18 | #include "y2018/control_loops/superstructure/arm/generated_graph.h" |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 19 | #include "y2018/control_loops/superstructure/superstructure.q.h" |
Austin Schuh | 1e2d498 | 2018-03-21 20:34:33 -0700 | [diff] [blame] | 20 | #include "y2018/status_light.q.h" |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 21 | |
| 22 | using ::frc971::control_loops::drivetrain_queue; |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 23 | using ::y2018::control_loops::superstructure_queue; |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 24 | |
| 25 | using ::aos::input::driver_station::ButtonLocation; |
| 26 | using ::aos::input::driver_station::ControlBit; |
| 27 | using ::aos::input::driver_station::JoystickAxis; |
| 28 | using ::aos::input::driver_station::POVLocation; |
| 29 | using ::aos::input::DrivetrainInputReader; |
| 30 | |
| 31 | namespace y2018 { |
| 32 | namespace input { |
| 33 | namespace joysticks { |
| 34 | |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 35 | namespace arm = ::y2018::control_loops::superstructure::arm; |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 36 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 37 | const ButtonLocation kIntakeClosed(3, 2); |
| 38 | const ButtonLocation kDuck(3, 9); |
| 39 | const ButtonLocation kSmallBox(3, 1); |
Austin Schuh | 47d7494 | 2018-03-04 01:15:59 -0800 | [diff] [blame] | 40 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 41 | const ButtonLocation kIntakeIn(3, 4); |
| 42 | const ButtonLocation kIntakeOut(3, 3); |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 43 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 44 | const ButtonLocation kArmFrontHighBox(4, 11); |
| 45 | const ButtonLocation kArmFrontExtraHighBox(4, 1); |
| 46 | const ButtonLocation kArmFrontMiddle2Box(4, 9); |
| 47 | const ButtonLocation kArmFrontMiddle1Box(4, 7); |
| 48 | const ButtonLocation kArmFrontLowBox(4, 5); |
| 49 | const ButtonLocation kArmFrontSwitch(3, 7); |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 50 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 51 | const ButtonLocation kArmBackHighBox(4, 12); |
| 52 | const ButtonLocation kArmBackExtraHighBox(3, 14); |
| 53 | const ButtonLocation kArmBackMiddle2Box(4, 10); |
| 54 | const ButtonLocation kArmBackMiddle1Box(4, 8); |
| 55 | const ButtonLocation kArmBackLowBox(4, 6); |
| 56 | const ButtonLocation kArmBackSwitch(3, 10); |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 57 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 58 | const ButtonLocation kArmAboveHang(3, 15); |
| 59 | const ButtonLocation kArmBelowHang(3, 16); |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 60 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 61 | const ButtonLocation kWinch(4, 2); |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 62 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 63 | const ButtonLocation kArmNeutral(3, 8); |
| 64 | const ButtonLocation kArmUp(3, 11); |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 65 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 66 | const ButtonLocation kArmStepUp(3, 13); |
| 67 | const ButtonLocation kArmStepDown(3, 12); |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 68 | |
Sabina Davis | 833ccf6 | 2018-04-06 20:52:31 -0700 | [diff] [blame^] | 69 | const ButtonLocation kArmPickupBoxFromIntake(4, 3); |
| 70 | |
| 71 | const ButtonLocation kClawOpen(4, 4); |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 72 | const ButtonLocation kDriverClawOpen(2, 4); |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 73 | |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 74 | std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_; |
| 75 | |
| 76 | class Reader : public ::aos::input::JoystickInput { |
| 77 | public: |
| 78 | Reader() { |
| 79 | drivetrain_input_reader_ = DrivetrainInputReader::Make( |
Austin Schuh | 2b1fce0 | 2018-03-02 20:05:20 -0800 | [diff] [blame] | 80 | DrivetrainInputReader::InputType::kPistol, |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 81 | ::y2018::control_loops::drivetrain::GetDrivetrainConfig()); |
| 82 | } |
| 83 | |
| 84 | void RunIteration(const ::aos::input::driver_station::Data &data) override { |
| 85 | bool last_auto_running = auto_running_; |
| 86 | auto_running_ = data.GetControlBit(ControlBit::kAutonomous) && |
| 87 | data.GetControlBit(ControlBit::kEnabled); |
| 88 | if (auto_running_ != last_auto_running) { |
| 89 | if (auto_running_) { |
| 90 | StartAuto(); |
| 91 | } else { |
| 92 | StopAuto(); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if (!auto_running_) { |
| 97 | HandleDrivetrain(data); |
| 98 | HandleTeleop(data); |
| 99 | } |
| 100 | |
| 101 | // Process any pending actions. |
| 102 | action_queue_.Tick(); |
| 103 | was_running_ = action_queue_.Running(); |
| 104 | } |
| 105 | |
| 106 | void HandleDrivetrain(const ::aos::input::driver_station::Data &data) { |
| 107 | drivetrain_input_reader_->HandleDrivetrain(data); |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Austin Schuh | 1e2d498 | 2018-03-21 20:34:33 -0700 | [diff] [blame] | 110 | void SendColors(float red, float green, float blue) { |
| 111 | auto new_status_light = status_light.MakeMessage(); |
| 112 | new_status_light->red = red; |
| 113 | new_status_light->green = green; |
| 114 | new_status_light->blue = blue; |
| 115 | |
| 116 | if (!new_status_light.Send()) { |
| 117 | LOG(ERROR, "Failed to send lights.\n"); |
| 118 | } |
| 119 | } |
| 120 | |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 121 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
| 122 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 123 | action_queue_.CancelAllActions(); |
| 124 | LOG(DEBUG, "Canceling\n"); |
| 125 | } |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 126 | |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 127 | superstructure_queue.position.FetchLatest(); |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 128 | superstructure_queue.status.FetchLatest(); |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 129 | if (!superstructure_queue.status.get() || |
| 130 | !superstructure_queue.position.get()) { |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 131 | LOG(ERROR, "Got no superstructure status packet.\n"); |
| 132 | return; |
| 133 | } |
| 134 | |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 135 | auto new_superstructure_goal = superstructure_queue.goal.MakeMessage(); |
| 136 | |
Sabina Davis | fdd7a11 | 2018-02-04 16:16:23 -0800 | [diff] [blame] | 137 | new_superstructure_goal->intake.left_intake_angle = intake_goal_; |
| 138 | new_superstructure_goal->intake.right_intake_angle = intake_goal_; |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 139 | |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 140 | if (data.IsPressed(kIntakeIn)) { |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 141 | // Turn on the rollers. |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 142 | new_superstructure_goal->intake.roller_voltage = 8.0; |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 143 | } else if (data.IsPressed(kIntakeOut)) { |
| 144 | // Turn off the rollers. |
Austin Schuh | 17dd089 | 2018-03-02 20:06:31 -0800 | [diff] [blame] | 145 | new_superstructure_goal->intake.roller_voltage = -12.0; |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 146 | } else { |
| 147 | // We don't want the rollers on. |
| 148 | new_superstructure_goal->intake.roller_voltage = 0.0; |
| 149 | } |
| 150 | |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 151 | if (superstructure_queue.position->box_back_beambreak_triggered) { |
| 152 | SendColors(0.0, 0.5, 0.0); |
| 153 | } else if (superstructure_queue.position->box_distance < 0.2) { |
| 154 | SendColors(0.0, 0.0, 0.5); |
| 155 | } else { |
| 156 | SendColors(0.0, 0.0, 0.0); |
| 157 | } |
| 158 | |
| 159 | if (data.IsPressed(kSmallBox)) { |
| 160 | // Deploy the intake. |
| 161 | if (superstructure_queue.position->box_back_beambreak_triggered) { |
| 162 | intake_goal_ = 0.30; |
| 163 | } else { |
| 164 | if (new_superstructure_goal->intake.roller_voltage > 0.1 && |
| 165 | superstructure_queue.position->box_distance < 0.15) { |
| 166 | intake_goal_ = 0.18; |
| 167 | } else { |
| 168 | intake_goal_ = -0.60; |
| 169 | } |
| 170 | } |
| 171 | } else if (data.IsPressed(kIntakeClosed)) { |
| 172 | // Deploy the intake. |
| 173 | if (superstructure_queue.position->box_back_beambreak_triggered) { |
| 174 | intake_goal_ = 0.30; |
| 175 | } else { |
| 176 | if (new_superstructure_goal->intake.roller_voltage > 0.1) { |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 177 | if (superstructure_queue.position->box_distance < 0.10) { |
| 178 | new_superstructure_goal->intake.roller_voltage -= 3.0; |
| 179 | intake_goal_ = 0.22; |
| 180 | } else if (superstructure_queue.position->box_distance < 0.17) { |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 181 | intake_goal_ = 0.13; |
| 182 | } else if (superstructure_queue.position->box_distance < 0.25) { |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 183 | intake_goal_ = 0.05; |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 184 | } else { |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 185 | intake_goal_ = -0.10; |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 186 | } |
| 187 | } else { |
| 188 | intake_goal_ = -0.60; |
| 189 | } |
| 190 | } |
| 191 | } else { |
| 192 | // Bring in the intake. |
| 193 | intake_goal_ = -3.3; |
| 194 | } |
| 195 | |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 196 | if (new_superstructure_goal->intake.roller_voltage > 0.1 && |
| 197 | intake_goal_ > 0.0) { |
| 198 | if (superstructure_queue.position->box_distance < 0.10) { |
| 199 | new_superstructure_goal->intake.roller_voltage -= 3.0; |
| 200 | } |
| 201 | new_superstructure_goal->intake.roller_voltage += 3.0; |
| 202 | } |
| 203 | |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 204 | // If we are disabled, stay at the node closest to where we start. This |
| 205 | // should remove long motions when enabled. |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 206 | if (!data.GetControlBit(ControlBit::kEnabled) || never_disabled_) { |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 207 | arm_goal_position_ = superstructure_queue.status->arm.current_node; |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 208 | never_disabled_ = false; |
Austin Schuh | b874fd3 | 2018-03-05 00:27:10 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 211 | bool grab_box = false; |
| 212 | if (data.IsPressed(kArmPickupBoxFromIntake)) { |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 213 | grab_box = true; |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 214 | } |
| 215 | if (data.PosEdge(kArmPickupBoxFromIntake)) { |
| 216 | arm_goal_position_ = arm::NeutralIndex(); |
| 217 | } else if (data.IsPressed(kDuck)) { |
| 218 | arm_goal_position_ = arm::DuckIndex(); |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 219 | } else if (data.IsPressed(kArmNeutral)) { |
| 220 | arm_goal_position_ = arm::NeutralIndex(); |
| 221 | } else if (data.IsPressed(kArmUp)) { |
| 222 | arm_goal_position_ = arm::UpIndex(); |
| 223 | } else if (data.IsPressed(kArmFrontSwitch)) { |
| 224 | arm_goal_position_ = arm::FrontSwitchIndex(); |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 225 | } else if (data.IsPressed(kArmFrontExtraHighBox)) { |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 226 | arm_goal_position_ = arm::FrontHighBoxIndex(); |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 227 | } else if (data.IsPressed(kArmFrontHighBox)) { |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 228 | arm_goal_position_ = arm::FrontMiddle2BoxIndex(); |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 229 | } else if (data.IsPressed(kArmFrontMiddle2Box)) { |
| 230 | arm_goal_position_ = arm::FrontMiddle3BoxIndex(); |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 231 | } else if (data.IsPressed(kArmFrontMiddle1Box)) { |
| 232 | arm_goal_position_ = arm::FrontMiddle1BoxIndex(); |
| 233 | } else if (data.IsPressed(kArmFrontLowBox)) { |
| 234 | arm_goal_position_ = arm::FrontLowBoxIndex(); |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 235 | } else if (data.IsPressed(kArmBackExtraHighBox)) { |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 236 | arm_goal_position_ = arm::BackHighBoxIndex(); |
Austin Schuh | 83cdd8a | 2018-03-21 20:49:02 -0700 | [diff] [blame] | 237 | } else if (data.IsPressed(kArmBackHighBox) || |
| 238 | data.IsPressed(kArmBackMiddle2Box)) { |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 239 | arm_goal_position_ = arm::BackMiddle2BoxIndex(); |
| 240 | } else if (data.IsPressed(kArmBackMiddle1Box)) { |
| 241 | arm_goal_position_ = arm::BackMiddle1BoxIndex(); |
| 242 | } else if (data.IsPressed(kArmBackLowBox)) { |
| 243 | arm_goal_position_ = arm::BackLowBoxIndex(); |
| 244 | } else if (data.IsPressed(kArmBackSwitch)) { |
| 245 | arm_goal_position_ = arm::BackSwitchIndex(); |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 246 | } else if (data.IsPressed(kArmAboveHang)) { |
| 247 | if (data.IsPressed(kIntakeIn)) { |
| 248 | arm_goal_position_ = arm::SelfHangIndex(); |
| 249 | } else if (data.IsPressed(kIntakeOut)) { |
| 250 | arm_goal_position_ = arm::PartnerHangIndex(); |
| 251 | } else { |
| 252 | arm_goal_position_ = arm::AboveHangIndex(); |
| 253 | } |
| 254 | } else if (data.IsPressed(kArmBelowHang)) { |
| 255 | arm_goal_position_ = arm::BelowHangIndex(); |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 258 | new_superstructure_goal->deploy_fork = |
| 259 | data.IsPressed(kArmAboveHang) && data.IsPressed(kClawOpen); |
| 260 | |
| 261 | if (new_superstructure_goal->deploy_fork) { |
| 262 | intake_goal_ = -2.0; |
| 263 | } |
| 264 | |
| 265 | if (data.IsPressed(kWinch)) { |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 266 | LOG(INFO, "Winching\n"); |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 267 | new_superstructure_goal->voltage_winch = 12.0; |
| 268 | } else { |
| 269 | new_superstructure_goal->voltage_winch = 0.0; |
| 270 | } |
| 271 | |
| 272 | new_superstructure_goal->hook_release = data.IsPressed(kArmBelowHang); |
| 273 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 274 | new_superstructure_goal->arm_goal_position = arm_goal_position_; |
| 275 | |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 276 | if ((data.IsPressed(kClawOpen) && data.IsPressed(kDriverClawOpen)) || |
| 277 | data.PosEdge(kArmPickupBoxFromIntake)) { |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 278 | new_superstructure_goal->open_claw = true; |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 279 | } else { |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 280 | new_superstructure_goal->open_claw = false; |
| 281 | } |
| 282 | |
Austin Schuh | ab15c4d | 2018-03-09 21:21:03 -0800 | [diff] [blame] | 283 | new_superstructure_goal->grab_box = grab_box; |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 284 | |
| 285 | LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal); |
| 286 | if (!new_superstructure_goal.Send()) { |
| 287 | LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 288 | } |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | private: |
Austin Schuh | a3c148e | 2018-03-09 21:04:05 -0800 | [diff] [blame] | 292 | void StartAuto() { |
| 293 | LOG(INFO, "Starting auto mode\n"); |
| 294 | |
| 295 | ::frc971::autonomous::AutonomousActionParams params; |
| 296 | ::frc971::autonomous::auto_mode.FetchLatest(); |
| 297 | if (::frc971::autonomous::auto_mode.get() != nullptr) { |
Austin Schuh | c231df4 | 2018-03-21 20:43:24 -0700 | [diff] [blame] | 298 | params.mode = ::frc971::autonomous::auto_mode->mode << 2; |
Austin Schuh | a3c148e | 2018-03-09 21:04:05 -0800 | [diff] [blame] | 299 | } else { |
| 300 | LOG(WARNING, "no auto mode values\n"); |
| 301 | params.mode = 0; |
| 302 | } |
Austin Schuh | c231df4 | 2018-03-21 20:43:24 -0700 | [diff] [blame] | 303 | // TODO(austin): use the mode later if we care. We don't care right now. |
| 304 | params.mode = static_cast<int>(::aos::joystick_state->switch_left) | |
| 305 | (static_cast<int>(::aos::joystick_state->scale_left) << 1); |
Austin Schuh | a3c148e | 2018-03-09 21:04:05 -0800 | [diff] [blame] | 306 | action_queue_.EnqueueAction( |
| 307 | ::frc971::autonomous::MakeAutonomousAction(params)); |
| 308 | } |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 309 | |
| 310 | void StopAuto() { |
| 311 | LOG(INFO, "Stopping auto mode\n"); |
| 312 | action_queue_.CancelAllActions(); |
| 313 | } |
| 314 | |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 315 | // Current goals to send to the robot. |
Austin Schuh | 17e484e | 2018-03-11 01:11:36 -0800 | [diff] [blame] | 316 | double intake_goal_ = 0.0; |
Neil Balch | 07fee58 | 2018-01-27 15:46:49 -0800 | [diff] [blame] | 317 | |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 318 | bool was_running_ = false; |
| 319 | bool auto_running_ = false; |
Neil Balch | ba9cbba | 2018-04-06 22:26:38 -0700 | [diff] [blame] | 320 | bool never_disabled_ = true; |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 321 | |
Austin Schuh | cb09171 | 2018-02-21 20:01:55 -0800 | [diff] [blame] | 322 | int arm_goal_position_ = 0; |
| 323 | |
Neil Balch | acfca5b | 2018-01-28 14:04:08 -0800 | [diff] [blame] | 324 | ::aos::common::actions::ActionQueue action_queue_; |
| 325 | }; |
| 326 | |
| 327 | } // namespace joysticks |
| 328 | } // namespace input |
| 329 | } // namespace y2018 |
| 330 | |
| 331 | int main() { |
| 332 | ::aos::Init(-1); |
| 333 | ::y2018::input::joysticks::Reader reader; |
| 334 | reader.Run(); |
| 335 | ::aos::Cleanup(); |
| 336 | } |