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" |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 20 | #include "frc971/actors/fridge_profile_actor.h" |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame^] | 21 | #include "frc971/actors/pickup_actor.h" |
| 22 | #include "frc971/actors/stack_actor.h" |
| 23 | #include "frc971/actors/lift_actor.h" |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 24 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 25 | using ::frc971::control_loops::claw_queue; |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 26 | using ::frc971::control_loops::drivetrain_queue; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 27 | using ::frc971::control_loops::fridge_queue; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 28 | using ::frc971::sensors::gyro_reading; |
| 29 | |
| 30 | using ::aos::input::driver_station::ButtonLocation; |
| 31 | using ::aos::input::driver_station::JoystickAxis; |
| 32 | using ::aos::input::driver_station::ControlBit; |
| 33 | |
| 34 | namespace frc971 { |
| 35 | namespace input { |
| 36 | namespace joysticks { |
| 37 | |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 38 | // preset motion limits |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame^] | 39 | static const double kArmDebugVelocity = 0.40; |
| 40 | static const double kArmDebugAcceleration = 1.0; |
| 41 | static const double kElevatorDebugVelocity = 0.5; |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 42 | static const double kElevatorDebugAcceleration = 2.2; |
| 43 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 44 | const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2); |
| 45 | const ButtonLocation kShiftHigh(2, 1), kShiftLow(2, 3); |
| 46 | const ButtonLocation kQuickTurn(1, 5); |
| 47 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 48 | // TODO(danielp): Real buttons for all of these. |
Austin Schuh | 8a436e8 | 2015-02-16 23:31:28 -0800 | [diff] [blame] | 49 | const ButtonLocation kElevatorUp(3, 10); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 50 | const ButtonLocation kElevatorDown(3, 3); |
Austin Schuh | 8a436e8 | 2015-02-16 23:31:28 -0800 | [diff] [blame] | 51 | const ButtonLocation kArmUp(3, 8); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 52 | const ButtonLocation kArmDown(2, 6); |
Austin Schuh | 8a436e8 | 2015-02-16 23:31:28 -0800 | [diff] [blame] | 53 | const ButtonLocation kClawUp(3, 7); |
| 54 | const ButtonLocation kClawDown(3, 6); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 55 | const ButtonLocation kClawOpen(3, 11); |
| 56 | const ButtonLocation kClawClosed(3, 5); |
| 57 | const ButtonLocation kFridgeOpen(3, 1); |
| 58 | const ButtonLocation kFridgeClosed(2, 11); |
| 59 | const ButtonLocation kRollersIn(3, 4); |
| 60 | const ButtonLocation kClawMiddle(3, 2); |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame^] | 61 | const ButtonLocation kPickup(2, 10); |
| 62 | const ButtonLocation kZero(2, 7); |
| 63 | |
| 64 | const ButtonLocation kStack(3, 9); |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 65 | |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 66 | // TODO(ben): Real buttons for all of these. |
| 67 | const ButtonLocation kArmPresetOne(99, 99); |
| 68 | const ButtonLocation kArmPresetTwo(99, 99); |
| 69 | const ButtonLocation kElevatorPresetOne(99, 99); |
| 70 | const ButtonLocation kElevatorPresetTwo(99, 99); |
| 71 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 72 | // Testing mode. |
Austin Schuh | 8a436e8 | 2015-02-16 23:31:28 -0800 | [diff] [blame] | 73 | const double kElevatorVelocity = 0.5; |
| 74 | const double kArmVelocity = 0.5; |
| 75 | const double kClawVelocity = 2.0; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 76 | // TODO(danielp): Verify. |
| 77 | const double kJoystickDt = 0.01; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 78 | |
| 79 | class Reader : public ::aos::input::JoystickInput { |
| 80 | public: |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 81 | Reader() : was_running_(false) {} |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 82 | |
| 83 | virtual void RunIteration(const ::aos::input::driver_station::Data &data) { |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 84 | bool last_auto_running = auto_running_; |
| 85 | auto_running_ = data.GetControlBit(ControlBit::kAutonomous) && |
Brian Silverman | e1103e6 | 2015-02-15 02:03:38 -0500 | [diff] [blame] | 86 | data.GetControlBit(ControlBit::kEnabled); |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 87 | if (auto_running_ != last_auto_running) { |
| 88 | if (auto_running_) { |
| 89 | StartAuto(); |
| 90 | } else { |
| 91 | StopAuto(); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 92 | } |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | if (!data.GetControlBit(ControlBit::kAutonomous)) { |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 96 | HandleDrivetrain(data); |
| 97 | if (data.GetControlBit(ControlBit::kTestMode)) { |
| 98 | HandleTest(data); |
| 99 | } else { |
| 100 | HandleTeleop(data); |
| 101 | } |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
| 105 | void HandleDrivetrain(const ::aos::input::driver_station::Data &data) { |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 106 | const double wheel = -data.GetAxis(kSteeringWheel); |
| 107 | const double throttle = -data.GetAxis(kDriveThrottle); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 108 | |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 109 | if (!drivetrain_queue.goal.MakeWithBuilder() |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 110 | .steering(wheel) |
| 111 | .throttle(throttle) |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 112 | .quickturn(data.IsPressed(kQuickTurn)) |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 113 | .control_loop_driving(false) |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 114 | .Send()) { |
| 115 | LOG(WARNING, "sending stick values failed\n"); |
| 116 | } |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 120 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 121 | action_queue_.CancelAllActions(); |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 122 | LOG(DEBUG, "Canceling\n"); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 123 | } |
| 124 | |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 125 | if (data.PosEdge(kElevatorUp)) { |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame^] | 126 | actors::LiftParams params; |
| 127 | params.lift_height = 0.45; |
| 128 | params.lift_arm = 0.2; |
| 129 | action_queue_.EnqueueAction(actors::MakeLiftAction(params)); |
| 130 | |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 131 | claw_goal_ = 0.0; |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame^] | 132 | if (!claw_queue.goal.MakeWithBuilder() |
| 133 | .angle(claw_goal_) |
| 134 | .rollers_closed(claw_rollers_closed_) |
| 135 | .intake(0.0) |
| 136 | .Send()) { |
| 137 | LOG(ERROR, "Sending claw goal failed.\n"); |
| 138 | } |
| 139 | } |
| 140 | if (data.PosEdge(kStack)) { |
| 141 | actors::StackParams params; |
| 142 | params.claw_out_angle = 0.6; |
| 143 | action_queue_.EnqueueAction(actors::MakeStackAction(params)); |
| 144 | } |
| 145 | if (data.PosEdge(kPickup)) { |
| 146 | actors::PickupParams params; |
| 147 | params.pickup_angle = 0.7; |
| 148 | params.suck_angle = 0.5; |
| 149 | params.suck_angle_finish = 0.4; |
| 150 | params.pickup_finish_angle = 0.87; |
| 151 | params.intake_time = 0.5; |
| 152 | params.intake_voltage = 12.0; |
| 153 | action_queue_.EnqueueAction(actors::MakePickupAction(params)); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 154 | } |
| 155 | if (data.PosEdge(kElevatorDown)) { |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 156 | claw_goal_ = 0.0; |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame^] | 157 | |
| 158 | actors::FridgeProfileParams fridge_params; |
| 159 | fridge_params.arm_max_velocity = kArmDebugVelocity; |
| 160 | fridge_params.arm_max_acceleration = kArmDebugAcceleration; |
| 161 | fridge_params.elevator_max_velocity = kElevatorDebugVelocity; |
| 162 | fridge_params.elevator_max_acceleration = kElevatorDebugAcceleration; |
| 163 | |
| 164 | fridge_params.arm_angle = 0.0; |
| 165 | fridge_params.elevator_height = 0.035; |
| 166 | |
| 167 | fridge_params.top_front_grabber = fridge_closed_; |
| 168 | fridge_params.top_back_grabber = fridge_closed_; |
| 169 | fridge_params.bottom_front_grabber = fridge_closed_; |
| 170 | fridge_params.bottom_back_grabber = fridge_closed_; |
| 171 | action_queue_.EnqueueAction(MakeFridgeProfileAction(fridge_params)); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | if (data.PosEdge(kClawMiddle)) { |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame^] | 175 | claw_goal_ = 0.8; |
| 176 | } |
| 177 | |
| 178 | if (data.PosEdge(kZero)) { |
| 179 | elevator_goal_ = 0.0; |
| 180 | arm_goal_ = 0.0; |
| 181 | claw_goal_ = 0.0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | if (data.PosEdge(kClawClosed)) { |
| 185 | claw_rollers_closed_ = true; |
| 186 | } |
| 187 | if (data.PosEdge(kClawOpen)) { |
| 188 | claw_rollers_closed_ = false; |
| 189 | } |
| 190 | |
| 191 | if (data.PosEdge(kFridgeClosed)) { |
| 192 | fridge_closed_ = true; |
| 193 | } |
| 194 | if (data.PosEdge(kFridgeOpen)) { |
| 195 | fridge_closed_ = false; |
| 196 | } |
| 197 | |
| 198 | if (data.PosEdge(ControlBit::kEnabled)) { |
| 199 | // If we got enabled, wait for everything to zero. |
| 200 | LOG(INFO, "Waiting for zero.\n"); |
| 201 | waiting_for_zero_ = true; |
| 202 | } |
| 203 | |
| 204 | if (waiting_for_zero_) { |
| 205 | claw_queue.status.FetchLatest(); |
| 206 | fridge_queue.status.FetchLatest(); |
| 207 | if (!claw_queue.status.get()) { |
| 208 | LOG(ERROR, "Got no claw status packet.\n"); |
| 209 | // Not safe to continue. |
| 210 | return; |
| 211 | } |
| 212 | if (!fridge_queue.status.get()) { |
| 213 | LOG(ERROR, "Got no fridge status packet.\n"); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | if (claw_queue.status->zeroed && fridge_queue.status->zeroed) { |
| 218 | LOG(INFO, "Zeroed! Starting teleop mode.\n"); |
| 219 | waiting_for_zero_ = false; |
| 220 | |
| 221 | // Set the initial goals to where we are now. |
| 222 | elevator_goal_ = fridge_queue.status->goal_height; |
| 223 | arm_goal_ = fridge_queue.status->goal_angle; |
| 224 | claw_goal_ = claw_queue.status->angle; |
| 225 | } else { |
| 226 | return; |
| 227 | } |
| 228 | } else { |
| 229 | if (!action_queue_.Running()) { |
| 230 | auto new_fridge_goal = fridge_queue.goal.MakeMessage(); |
| 231 | new_fridge_goal->height = elevator_goal_; |
| 232 | new_fridge_goal->angle = arm_goal_; |
| 233 | new_fridge_goal->angular_velocity = 0.0; |
| 234 | new_fridge_goal->velocity = 0.0; |
| 235 | new_fridge_goal->grabbers.top_front = fridge_closed_; |
| 236 | new_fridge_goal->grabbers.top_back = fridge_closed_; |
| 237 | new_fridge_goal->grabbers.bottom_front = fridge_closed_; |
| 238 | new_fridge_goal->grabbers.bottom_back = fridge_closed_; |
| 239 | |
| 240 | if (!new_fridge_goal.Send()) { |
| 241 | LOG(ERROR, "Sending fridge goal failed.\n"); |
| 242 | } else { |
| 243 | LOG(DEBUG, "sending goals: elevator: %f, arm: %f\n", elevator_goal_, |
| 244 | arm_goal_); |
| 245 | } |
| 246 | if (!claw_queue.goal.MakeWithBuilder() |
| 247 | .angle(claw_goal_) |
| 248 | .rollers_closed(claw_rollers_closed_) |
| 249 | .intake(data.IsPressed(kRollersIn) ? 12.0 : 0.0) |
| 250 | .Send()) { |
| 251 | LOG(ERROR, "Sending claw goal failed.\n"); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame^] | 256 | if (action_queue_.Running()) { |
| 257 | // If we are running an action, update our goals to the current goals. |
| 258 | control_loops::fridge_queue.status.FetchLatest(); |
| 259 | if (control_loops::fridge_queue.status.get()) { |
| 260 | arm_goal_ = control_loops::fridge_queue.status->goal_angle; |
| 261 | elevator_goal_ = control_loops::fridge_queue.status->goal_height; |
| 262 | } else { |
| 263 | LOG(ERROR, "No fridge status!\n"); |
| 264 | } |
| 265 | |
| 266 | // If we are running an action, update our goals to the current goals. |
| 267 | control_loops::claw_queue.status.FetchLatest(); |
| 268 | if (control_loops::claw_queue.status.get()) { |
| 269 | claw_goal_ = control_loops::claw_queue.status->goal_angle; |
| 270 | } else { |
| 271 | LOG(ERROR, "No fridge status!\n"); |
| 272 | } |
| 273 | } |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 274 | action_queue_.Tick(); |
| 275 | was_running_ = action_queue_.Running(); |
| 276 | } |
| 277 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 278 | void HandleTest(const ::aos::input::driver_station::Data &data) { |
| 279 | if (action_queue_.Running()) { |
| 280 | // We don't really want any actions running. |
| 281 | LOG(DEBUG, "Cancelling actions for test mode.\n"); |
| 282 | action_queue_.CancelAllActions(); |
| 283 | } |
| 284 | |
| 285 | if (data.GetControlBit(ControlBit::kEnabled)) { |
| 286 | if (data.PosEdge(ControlBit::kEnabled)) { |
| 287 | // If we got enabled, wait for everything to zero. |
| 288 | LOG(INFO, "Waiting for zero.\n"); |
| 289 | waiting_for_zero_ = true; |
| 290 | } |
| 291 | if (waiting_for_zero_) { |
| 292 | claw_queue.status.FetchLatest(); |
| 293 | fridge_queue.status.FetchLatest(); |
| 294 | if (!claw_queue.status.get()) { |
| 295 | LOG(ERROR, "Got no claw status packet.\n"); |
| 296 | // Not safe to continue. |
| 297 | return; |
| 298 | } |
| 299 | if (!fridge_queue.status.get()) { |
| 300 | LOG(ERROR, "Got no fridge status packet.\n"); |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | if (claw_queue.status->zeroed && fridge_queue.status->zeroed) { |
| 305 | LOG(INFO, "Zeroed! Starting test mode.\n"); |
| 306 | waiting_for_zero_ = false; |
| 307 | |
| 308 | // Set the initial goals to where we are now. |
| 309 | elevator_goal_ = fridge_queue.status->height; |
| 310 | arm_goal_ = fridge_queue.status->angle; |
| 311 | claw_goal_ = claw_queue.status->angle; |
| 312 | } else { |
| 313 | return; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | // These buttons move a subsystem up or down for as long as they are |
| 318 | // pressed, at low velocity. |
| 319 | if (data.IsPressed(kElevatorUp)) { |
| 320 | elevator_goal_ += kElevatorVelocity * kJoystickDt; |
| 321 | } |
| 322 | if (data.IsPressed(kElevatorDown)) { |
| 323 | elevator_goal_ -= kElevatorVelocity * kJoystickDt; |
| 324 | } |
| 325 | if (data.IsPressed(kArmUp)) { |
| 326 | arm_goal_ += kArmVelocity * kJoystickDt; |
| 327 | } |
| 328 | if (data.IsPressed(kArmDown)) { |
| 329 | arm_goal_ -= kArmVelocity * kJoystickDt; |
| 330 | } |
| 331 | if (data.IsPressed(kClawUp)) { |
| 332 | claw_goal_ += kClawVelocity * kJoystickDt; |
| 333 | } |
| 334 | if (data.IsPressed(kClawDown)) { |
| 335 | claw_goal_ -= kClawVelocity * kJoystickDt; |
| 336 | } |
| 337 | |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 338 | if (!action_queue_.Running()) { |
| 339 | if (!fridge_queue.goal.MakeWithBuilder() |
| 340 | .height(elevator_goal_) |
| 341 | .angle(arm_goal_) |
| 342 | .Send()) { |
| 343 | LOG(ERROR, "Sending fridge goal failed.\n"); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 344 | } else { |
| 345 | LOG(DEBUG, "sending goals: elevator: %f, arm: %f\n", elevator_goal_, |
| 346 | arm_goal_); |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 347 | } |
| 348 | if (!claw_queue.goal.MakeWithBuilder().angle(claw_goal_).Send()) { |
| 349 | LOG(ERROR, "Sending claw goal failed.\n"); |
| 350 | } |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 351 | } |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 352 | /* |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 353 | if (data.IsPressed(kArmPresetOne) || data.IsPressed(kArmPresetTwo)) { |
| 354 | actors::FridgeProfileParams fridge_params; |
| 355 | fridge_params.arm_max_velocity = kArmDebugVelocity; |
| 356 | fridge_params.arm_max_acceleration = kArmDebugAcceleration; |
| 357 | if (data.IsPressed(kArmPresetOne)) { |
| 358 | LOG(INFO, "Preset asked for test arm position one position.\n"); |
| 359 | fridge_params.arm_angle = M_PI / 4.0; |
| 360 | fridge_params.top_front_grabber = false; |
| 361 | fridge_params.top_back_grabber = false; |
| 362 | fridge_params.bottom_front_grabber = false; |
| 363 | fridge_params.bottom_back_grabber = false; |
| 364 | action_queue_.EnqueueAction(MakeFridgeProfileAction(fridge_params)); |
| 365 | } else if (data.IsPressed(kArmPresetTwo)) { |
| 366 | LOG(INFO, "Preset asked for test arm position two position.\n"); |
| 367 | fridge_params.arm_angle = -M_PI / 4.0; |
| 368 | fridge_params.top_front_grabber = true; |
| 369 | fridge_params.top_back_grabber = true; |
| 370 | fridge_params.bottom_front_grabber = true; |
| 371 | fridge_params.bottom_back_grabber = true; |
| 372 | action_queue_.EnqueueAction(MakeFridgeProfileAction(fridge_params)); |
| 373 | } |
| 374 | } else if (data.IsPressed(kElevatorPresetOne) || |
| 375 | data.IsPressed(kElevatorPresetOne)) { |
| 376 | actors::FridgeProfileParams fridge_params; |
| 377 | fridge_params.elevator_max_velocity = kElevatorDebugVelocity; |
| 378 | fridge_params.elevator_max_acceleration = kElevatorDebugAcceleration; |
| 379 | if (data.IsPressed(kElevatorPresetOne)) { |
| 380 | LOG(INFO, "Preset asked for test elevator position one position.\n"); |
| 381 | fridge_params.elevator_height = 0.5; |
| 382 | fridge_params.top_front_grabber = false; |
| 383 | fridge_params.top_back_grabber = false; |
| 384 | fridge_params.bottom_front_grabber = false; |
| 385 | fridge_params.bottom_back_grabber = false; |
| 386 | action_queue_.EnqueueAction(MakeFridgeProfileAction(fridge_params)); |
| 387 | } else if (data.IsPressed(kElevatorPresetTwo)) { |
| 388 | LOG(INFO, "Preset asked for test elevator position two position.\n"); |
| 389 | fridge_params.elevator_height = 1.2; |
| 390 | fridge_params.top_front_grabber = true; |
| 391 | fridge_params.top_back_grabber = true; |
| 392 | fridge_params.bottom_front_grabber = true; |
| 393 | fridge_params.bottom_back_grabber = true; |
| 394 | action_queue_.EnqueueAction(MakeFridgeProfileAction(fridge_params)); |
| 395 | } |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 396 | } |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 397 | */ |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 401 | private: |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 402 | void StartAuto() { |
| 403 | LOG(INFO, "Starting auto mode\n"); |
| 404 | ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(true).Send(); |
| 405 | } |
| 406 | |
| 407 | void StopAuto() { |
| 408 | LOG(INFO, "Stopping auto mode\n"); |
| 409 | ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(false).Send(); |
| 410 | } |
| 411 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 412 | bool was_running_; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 413 | |
| 414 | // Previous goals for systems. |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 415 | double elevator_goal_ = 0.2; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 416 | double arm_goal_ = 0.0; |
| 417 | double claw_goal_ = 0.0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 418 | bool claw_rollers_closed_ = false; |
| 419 | bool fridge_closed_ = false; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 420 | |
| 421 | // If we're waiting for the subsystems to zero. |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 422 | bool waiting_for_zero_ = true; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 423 | |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 424 | bool auto_running_ = false; |
| 425 | |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 426 | ::aos::common::actions::ActionQueue action_queue_; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 427 | |
| 428 | ::aos::util::SimpleLogInterval no_drivetrain_status_ = |
| 429 | ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING, |
| 430 | "no drivetrain status"); |
| 431 | }; |
| 432 | |
| 433 | } // namespace joysticks |
| 434 | } // namespace input |
| 435 | } // namespace frc971 |
| 436 | |
| 437 | int main() { |
| 438 | ::aos::Init(); |
| 439 | ::frc971::input::joysticks::Reader reader; |
| 440 | reader.Run(); |
| 441 | ::aos::Cleanup(); |
| 442 | } |