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