Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <unistd.h> |
| 4 | #include <math.h> |
| 5 | |
| 6 | #include "aos/linux_code/init.h" |
| 7 | #include "aos/prime/input/joystick_input.h" |
| 8 | #include "aos/common/input/driver_station_data.h" |
| 9 | #include "aos/common/logging/logging.h" |
| 10 | #include "aos/common/util/log_interval.h" |
| 11 | #include "aos/common/time.h" |
Ben Fredrickson | d69f38b | 2015-01-28 20:06:15 -0800 | [diff] [blame] | 12 | #include "aos/common/actions/actions.h" |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 13 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 14 | #include "frc971/control_loops/claw/claw.q.h" |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 15 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 16 | #include "frc971/control_loops/fridge/fridge.q.h" |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 17 | #include "frc971/constants.h" |
| 18 | #include "frc971/queues/gyro.q.h" |
| 19 | #include "frc971/autonomous/auto.q.h" |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 20 | #include "frc971/actors/pickup_actor.h" |
| 21 | #include "frc971/actors/stack_actor.h" |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 22 | #include "frc971/actors/stack_and_lift_actor.h" |
| 23 | #include "frc971/actors/stack_and_hold_actor.h" |
| 24 | #include "frc971/actors/held_to_lift_actor.h" |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 25 | #include "frc971/actors/lift_actor.h" |
Austin Schuh | 994d42c | 2015-03-01 00:02:17 -0800 | [diff] [blame] | 26 | #include "frc971/actors/can_pickup_actor.h" |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 27 | #include "frc971/actors/horizontal_can_pickup_actor.h" |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 28 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 29 | using ::frc971::control_loops::claw_queue; |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 30 | using ::frc971::control_loops::drivetrain_queue; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 31 | using ::frc971::control_loops::fridge_queue; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 32 | using ::frc971::sensors::gyro_reading; |
| 33 | |
| 34 | using ::aos::input::driver_station::ButtonLocation; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 35 | using ::aos::input::driver_station::POVLocation; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 36 | using ::aos::input::driver_station::JoystickAxis; |
| 37 | using ::aos::input::driver_station::ControlBit; |
| 38 | |
| 39 | namespace frc971 { |
| 40 | namespace input { |
| 41 | namespace joysticks { |
| 42 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 43 | // Actions needed. |
| 44 | |
| 45 | // Human Player Station Intake Button |
| 46 | // Claw open |
| 47 | // Claw close |
| 48 | // Claw down |
| 49 | |
| 50 | // Stack + Lift (together) |
| 51 | // Place |
| 52 | |
| 53 | // Hold stack |
| 54 | |
| 55 | // Horizontal can pickup |
| 56 | // Vertical can pickup |
| 57 | |
| 58 | // TODO(austin): Pull a lot of the constants below out up here so they can be |
| 59 | // globally changed easier. |
| 60 | |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 61 | // preset motion limits |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 62 | constexpr actors::ProfileParams kArmMove{1.00, 1.0}; |
| 63 | constexpr actors::ProfileParams kElevatorMove{1.00, 3.2}; |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 64 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 65 | const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2); |
| 66 | const ButtonLocation kShiftHigh(2, 1), kShiftLow(2, 3); |
| 67 | const ButtonLocation kQuickTurn(1, 5); |
| 68 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 69 | //const ButtonLocation kClawClosed(3, 5); |
| 70 | //const ButtonLocation kFridgeClosed(3, 1); |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 71 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 72 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 73 | const ButtonLocation kRollersIn(4, 5); |
| 74 | const ButtonLocation kClawToggle(4, 1); |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 75 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 76 | const POVLocation kElevatorCanUp(3, 0); |
| 77 | |
| 78 | // POV stick 3, 180 |
| 79 | const POVLocation kCanPickup(4, 180); |
| 80 | const ButtonLocation kToteChute(4, 6); |
| 81 | const ButtonLocation kStackAndLift(4, 7); |
| 82 | const ButtonLocation kStackAndHold(2, 5); |
| 83 | |
| 84 | // Pull in the 6th tote. |
| 85 | const ButtonLocation kSixthTote(4, 10); |
| 86 | |
| 87 | const ButtonLocation kHeldToLift(4, 11); |
| 88 | const ButtonLocation kPickup(4, 9); |
| 89 | |
| 90 | const ButtonLocation kStack(4, 2); |
| 91 | |
| 92 | // Move the fridge out with the stack in preparation for scoring. |
| 93 | // PosEdge(4, 8) |
| 94 | |
| 95 | // Release the stack and retract back in. |
| 96 | // PosEdge(4, 12) |
| 97 | |
| 98 | const POVLocation kFridgeOpen(4, 270); |
| 99 | const ButtonLocation kSpit(4, 3); |
| 100 | |
| 101 | // Set stack down in the bot. |
| 102 | // TODO(austin): Make this work. |
| 103 | //const POVLocation kSetStackDownAndHold(4, 90); |
| 104 | |
| 105 | const double kClawTotePackAngle = 0.95; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 106 | |
| 107 | class Reader : public ::aos::input::JoystickInput { |
| 108 | public: |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 109 | Reader() : was_running_(false) {} |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 110 | |
| 111 | virtual void RunIteration(const ::aos::input::driver_station::Data &data) { |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 112 | bool last_auto_running = auto_running_; |
| 113 | auto_running_ = data.GetControlBit(ControlBit::kAutonomous) && |
Brian Silverman | e1103e6 | 2015-02-15 02:03:38 -0500 | [diff] [blame] | 114 | data.GetControlBit(ControlBit::kEnabled); |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 115 | if (auto_running_ != last_auto_running) { |
| 116 | if (auto_running_) { |
| 117 | StartAuto(); |
| 118 | } else { |
| 119 | StopAuto(); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 120 | } |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | if (!data.GetControlBit(ControlBit::kAutonomous)) { |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 124 | HandleDrivetrain(data); |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 125 | HandleTeleop(data); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | void HandleDrivetrain(const ::aos::input::driver_station::Data &data) { |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 130 | const double wheel = -data.GetAxis(kSteeringWheel); |
| 131 | const double throttle = -data.GetAxis(kDriveThrottle); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 132 | |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 133 | if (!drivetrain_queue.goal.MakeWithBuilder() |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 134 | .steering(wheel) |
| 135 | .throttle(throttle) |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 136 | .quickturn(data.IsPressed(kQuickTurn)) |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 137 | .control_loop_driving(false) |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 138 | .Send()) { |
| 139 | LOG(WARNING, "sending stick values failed\n"); |
| 140 | } |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 144 | double intake_power = 0.0; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 145 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 146 | action_queue_.CancelAllActions(); |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 147 | LOG(DEBUG, "Canceling\n"); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 150 | if (data.IsPressed(kRollersIn)) { |
| 151 | intake_power = 10.0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 152 | claw_goal_ = 0.0; |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 153 | } |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 154 | if (data.IsPressed(kSpit)) { |
| 155 | intake_power = -12.0; |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 156 | } |
Austin Schuh | 994d42c | 2015-03-01 00:02:17 -0800 | [diff] [blame] | 157 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 158 | // Toggle button for the claw |
| 159 | if (data.PosEdge(kClawToggle)) { |
| 160 | claw_rollers_closed_ = !claw_rollers_closed_; |
Austin Schuh | 994d42c | 2015-03-01 00:02:17 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 163 | /* |
| 164 | if (data.IsPressed(kClawClosed)) { |
| 165 | claw_rollers_closed_ = true; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 166 | } |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 167 | */ |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 168 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 169 | // Horizontal can pickup. |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 170 | if (data.PosEdge(kElevatorCanUp)) { |
| 171 | actors::HorizontalCanPickupParams params; |
| 172 | params.elevator_height = 0.3; |
| 173 | params.pickup_angle = 0.54; |
| 174 | params.suck_time = 0.05; |
| 175 | params.suck_power = 8.0; |
| 176 | |
| 177 | params.claw_settle_time = 0.05; |
| 178 | params.claw_settle_power = 5.0; |
| 179 | params.claw_full_lift_angle = 1.35; |
| 180 | params.claw_end_angle = 0.5; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 181 | |
| 182 | params.elevator_end_height = 0.68; |
| 183 | params.arm_end_angle = 0.2; |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 184 | action_queue_.EnqueueAction( |
| 185 | actors::MakeHorizontalCanPickupAction(params)); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 186 | fridge_closed_ = true; |
| 187 | } |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 188 | |
| 189 | // -0.942503 arm, 0.374752 elevator |
| 190 | // Vertical can pickup. |
| 191 | if (data.PosEdge(kCanPickup)) { |
| 192 | actors::CanPickupParams params; |
| 193 | params.pickup_angle = -0.93; |
| 194 | params.pickup_height = 0.265; |
| 195 | params.lift_height = 0.65; |
| 196 | params.end_height = 0.68; |
| 197 | params.end_angle = 0.2; |
| 198 | action_queue_.EnqueueAction(actors::MakeCanPickupAction(params)); |
| 199 | fridge_closed_ = true; |
| 200 | } |
| 201 | |
| 202 | // Tote chute pull in when button is pressed, pack when done. |
| 203 | if (data.IsPressed(kToteChute)) { |
| 204 | claw_goal_ = 0.8; |
| 205 | intake_power = 7.0; |
| 206 | } |
| 207 | if (data.NegEdge(kToteChute)) { |
| 208 | claw_goal_ = kClawTotePackAngle; |
| 209 | } |
| 210 | |
| 211 | if (data.PosEdge(kStackAndLift)) { |
| 212 | actors::StackAndLiftParams params; |
| 213 | params.stack_params.claw_out_angle = 0.6; |
| 214 | params.stack_params.bottom = 0.020; |
| 215 | params.stack_params.over_box_before_place_height = 0.39; |
| 216 | |
| 217 | params.grab_after_stack = true; |
| 218 | params.clamp_pause_time = 0.1; |
| 219 | params.lift_params.lift_height = 0.45; |
| 220 | params.lift_params.lift_arm = 0.3; |
| 221 | params.grab_after_lift = true; |
| 222 | fridge_closed_ = true; |
| 223 | |
| 224 | action_queue_.EnqueueAction(actors::MakeStackAndLiftAction(params)); |
| 225 | } |
| 226 | |
| 227 | if (data.PosEdge(kStackAndHold)) { |
| 228 | actors::StackAndHoldParams params; |
| 229 | params.bottom = 0.020; |
| 230 | params.over_box_before_place_height = 0.39; |
| 231 | |
| 232 | params.arm_clearance = -0.05; |
| 233 | params.clamp_pause_time = 0.25; |
| 234 | |
| 235 | params.hold_height = 0.68; |
| 236 | |
| 237 | action_queue_.EnqueueAction(actors::MakeStackAndHoldAction(params)); |
| 238 | fridge_closed_ = true; |
| 239 | } |
| 240 | |
| 241 | // TODO(austin): Figure out what action needed to pull the 6th tote into the |
| 242 | // claw. |
| 243 | |
| 244 | // Lower the fridge from holding the stack, grab the stack, and then lift. |
| 245 | if (data.PosEdge(kHeldToLift)) { |
| 246 | actors::HeldToLiftParams params; |
| 247 | params.arm_clearance = -0.05; |
| 248 | params.clamp_pause_time = 0.1; |
| 249 | params.bottom_height = 0.020; |
| 250 | params.claw_out_angle = 0.6; |
| 251 | params.lift_params.lift_height = 0.45; |
| 252 | params.lift_params.lift_arm = 0.3; |
| 253 | fridge_closed_ = true; |
| 254 | |
| 255 | action_queue_.EnqueueAction(actors::MakeHeldToLiftAction(params)); |
| 256 | } |
| 257 | |
| 258 | // Pick up a tote from the ground and put it in the bottom of the bot. |
| 259 | if (data.PosEdge(kPickup)) { |
| 260 | actors::PickupParams params; |
| 261 | // Lift to here initially. |
| 262 | params.pickup_angle = 0.9; |
| 263 | // Start sucking here |
| 264 | params.suck_angle = 0.8; |
| 265 | // Go back down to here to finish sucking. |
| 266 | params.suck_angle_finish = 0.4; |
| 267 | // Pack the box back in here. |
| 268 | params.pickup_finish_angle = kClawTotePackAngle; |
| 269 | params.intake_time = 0.8; |
| 270 | params.intake_voltage = 7.0; |
| 271 | action_queue_.EnqueueAction(actors::MakePickupAction(params)); |
| 272 | } |
| 273 | |
| 274 | // Place stack on a tote in the tray, and grab it. |
| 275 | if (data.PosEdge(kStack)) { |
| 276 | actors::StackParams params; |
| 277 | params.claw_out_angle = 0.6; |
| 278 | params.bottom = 0.020; |
| 279 | params.over_box_before_place_height = 0.39; |
| 280 | action_queue_.EnqueueAction(actors::MakeStackAction(params)); |
| 281 | claw_rollers_closed_ = true; |
| 282 | } |
| 283 | |
| 284 | // TODO(austin): Set down? |
| 285 | |
| 286 | // TODO(austin): Score! |
| 287 | |
| 288 | // TODO(austin): Release. |
| 289 | |
| 290 | // Unknown actions... |
| 291 | |
| 292 | //if (data.PosEdge(kFridgeClosed)) { |
| 293 | //fridge_closed_ = true; |
| 294 | //} |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 295 | if (data.PosEdge(kFridgeOpen)) { |
| 296 | fridge_closed_ = false; |
| 297 | } |
| 298 | |
| 299 | if (data.PosEdge(ControlBit::kEnabled)) { |
| 300 | // If we got enabled, wait for everything to zero. |
| 301 | LOG(INFO, "Waiting for zero.\n"); |
| 302 | waiting_for_zero_ = true; |
| 303 | } |
| 304 | |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 305 | claw_queue.status.FetchLatest(); |
| 306 | fridge_queue.status.FetchLatest(); |
| 307 | if (!claw_queue.status.get()) { |
| 308 | LOG(ERROR, "Got no claw status packet.\n"); |
| 309 | // Not safe to continue. |
| 310 | return; |
| 311 | } |
| 312 | if (!fridge_queue.status.get()) { |
| 313 | LOG(ERROR, "Got no fridge status packet.\n"); |
| 314 | return; |
| 315 | } |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 316 | |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 317 | if (claw_queue.status->zeroed && fridge_queue.status->zeroed) { |
| 318 | if (waiting_for_zero_) { |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 319 | LOG(INFO, "Zeroed! Starting teleop mode.\n"); |
| 320 | waiting_for_zero_ = false; |
| 321 | |
| 322 | // Set the initial goals to where we are now. |
| 323 | elevator_goal_ = fridge_queue.status->goal_height; |
| 324 | arm_goal_ = fridge_queue.status->goal_angle; |
| 325 | claw_goal_ = claw_queue.status->angle; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 326 | } |
| 327 | } else { |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 328 | waiting_for_zero_ = true; |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | if (!waiting_for_zero_) { |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 333 | if (!action_queue_.Running()) { |
| 334 | auto new_fridge_goal = fridge_queue.goal.MakeMessage(); |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 335 | new_fridge_goal->max_velocity = elevator_params_.velocity; |
| 336 | new_fridge_goal->max_acceleration = elevator_params_.acceleration; |
Austin Schuh | 1d44bd4 | 2015-03-15 16:40:45 -0700 | [diff] [blame^] | 337 | new_fridge_goal->profiling_type = 0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 338 | new_fridge_goal->height = elevator_goal_; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 339 | new_fridge_goal->velocity = 0.0; |
| 340 | new_fridge_goal->max_angular_velocity = arm_params_.velocity; |
| 341 | new_fridge_goal->max_angular_acceleration = arm_params_.acceleration; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 342 | new_fridge_goal->angle = arm_goal_; |
| 343 | new_fridge_goal->angular_velocity = 0.0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 344 | new_fridge_goal->grabbers.top_front = fridge_closed_; |
| 345 | new_fridge_goal->grabbers.top_back = fridge_closed_; |
| 346 | new_fridge_goal->grabbers.bottom_front = fridge_closed_; |
| 347 | new_fridge_goal->grabbers.bottom_back = fridge_closed_; |
| 348 | |
| 349 | if (!new_fridge_goal.Send()) { |
| 350 | LOG(ERROR, "Sending fridge goal failed.\n"); |
| 351 | } else { |
| 352 | LOG(DEBUG, "sending goals: elevator: %f, arm: %f\n", elevator_goal_, |
| 353 | arm_goal_); |
| 354 | } |
| 355 | if (!claw_queue.goal.MakeWithBuilder() |
| 356 | .angle(claw_goal_) |
| 357 | .rollers_closed(claw_rollers_closed_) |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 358 | .intake(intake_power) |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 359 | .Send()) { |
| 360 | LOG(ERROR, "Sending claw goal failed.\n"); |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 365 | if (action_queue_.Running()) { |
| 366 | // If we are running an action, update our goals to the current goals. |
| 367 | control_loops::fridge_queue.status.FetchLatest(); |
| 368 | if (control_loops::fridge_queue.status.get()) { |
| 369 | arm_goal_ = control_loops::fridge_queue.status->goal_angle; |
| 370 | elevator_goal_ = control_loops::fridge_queue.status->goal_height; |
| 371 | } else { |
| 372 | LOG(ERROR, "No fridge status!\n"); |
| 373 | } |
| 374 | |
| 375 | // If we are running an action, update our goals to the current goals. |
| 376 | control_loops::claw_queue.status.FetchLatest(); |
| 377 | if (control_loops::claw_queue.status.get()) { |
| 378 | claw_goal_ = control_loops::claw_queue.status->goal_angle; |
| 379 | } else { |
| 380 | LOG(ERROR, "No fridge status!\n"); |
| 381 | } |
| 382 | } |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 383 | action_queue_.Tick(); |
| 384 | was_running_ = action_queue_.Running(); |
| 385 | } |
| 386 | |
| 387 | private: |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 388 | void StartAuto() { |
| 389 | LOG(INFO, "Starting auto mode\n"); |
| 390 | ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(true).Send(); |
| 391 | } |
| 392 | |
| 393 | void StopAuto() { |
| 394 | LOG(INFO, "Stopping auto mode\n"); |
| 395 | ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(false).Send(); |
| 396 | } |
| 397 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 398 | bool was_running_; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 399 | |
| 400 | // Previous goals for systems. |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 401 | double elevator_goal_ = 0.2; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 402 | double arm_goal_ = 0.0; |
| 403 | double claw_goal_ = 0.0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 404 | bool claw_rollers_closed_ = false; |
| 405 | bool fridge_closed_ = false; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 406 | actors::ProfileParams arm_params_ = kArmMove; |
| 407 | actors::ProfileParams elevator_params_ = kElevatorMove; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 408 | |
| 409 | // If we're waiting for the subsystems to zero. |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 410 | bool waiting_for_zero_ = true; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 411 | |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 412 | bool auto_running_ = false; |
| 413 | |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 414 | ::aos::common::actions::ActionQueue action_queue_; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 415 | |
| 416 | ::aos::util::SimpleLogInterval no_drivetrain_status_ = |
| 417 | ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING, |
| 418 | "no drivetrain status"); |
| 419 | }; |
| 420 | |
| 421 | } // namespace joysticks |
| 422 | } // namespace input |
| 423 | } // namespace frc971 |
| 424 | |
| 425 | int main() { |
| 426 | ::aos::Init(); |
| 427 | ::frc971::input::joysticks::Reader reader; |
| 428 | reader.Run(); |
| 429 | ::aos::Cleanup(); |
| 430 | } |