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 | |
Brian Silverman | b691f5e | 2015-08-02 11:37:55 -0700 | [diff] [blame^] | 14 | #include "y2015/control_loops/claw/claw.q.h" |
| 15 | #include "y2015/control_loops/drivetrain/drivetrain.q.h" |
| 16 | #include "y2015/control_loops/fridge/fridge.q.h" |
| 17 | #include "y2015/constants.h" |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 18 | #include "frc971/queues/gyro.q.h" |
| 19 | #include "frc971/autonomous/auto.q.h" |
Brian Silverman | b691f5e | 2015-08-02 11:37:55 -0700 | [diff] [blame^] | 20 | #include "y2015/actors/pickup_actor.h" |
| 21 | #include "y2015/actors/stack_actor.h" |
| 22 | #include "y2015/actors/score_actor.h" |
| 23 | #include "y2015/actors/stack_and_lift_actor.h" |
| 24 | #include "y2015/actors/stack_and_hold_actor.h" |
| 25 | #include "y2015/actors/held_to_lift_actor.h" |
| 26 | #include "y2015/actors/lift_actor.h" |
| 27 | #include "y2015/actors/can_pickup_actor.h" |
| 28 | #include "y2015/actors/horizontal_can_pickup_actor.h" |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 29 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 30 | using ::frc971::control_loops::claw_queue; |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 31 | using ::frc971::control_loops::drivetrain_queue; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 32 | using ::frc971::control_loops::fridge_queue; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 33 | using ::frc971::sensors::gyro_reading; |
| 34 | |
| 35 | using ::aos::input::driver_station::ButtonLocation; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 36 | using ::aos::input::driver_station::POVLocation; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 37 | using ::aos::input::driver_station::JoystickAxis; |
| 38 | using ::aos::input::driver_station::ControlBit; |
| 39 | |
| 40 | namespace frc971 { |
| 41 | namespace input { |
| 42 | namespace joysticks { |
| 43 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 44 | // Actions needed. |
| 45 | |
| 46 | // Human Player Station Intake Button |
| 47 | // Claw open |
| 48 | // Claw close |
| 49 | // Claw down |
| 50 | |
| 51 | // Stack + Lift (together) |
| 52 | // Place |
| 53 | |
| 54 | // Hold stack |
| 55 | |
| 56 | // Horizontal can pickup |
| 57 | // Vertical can pickup |
| 58 | |
| 59 | // TODO(austin): Pull a lot of the constants below out up here so they can be |
| 60 | // globally changed easier. |
| 61 | |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 62 | // preset motion limits |
Brian Silverman | cb615cf | 2015-03-21 21:42:35 -0700 | [diff] [blame] | 63 | constexpr actors::ProfileParams kArmMove{0.5, 1.0}; |
| 64 | constexpr actors::ProfileParams kElevatorMove{0.3, 1.0}; |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 65 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 66 | const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2); |
| 67 | const ButtonLocation kShiftHigh(2, 1), kShiftLow(2, 3); |
| 68 | const ButtonLocation kQuickTurn(1, 5); |
| 69 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 70 | //const ButtonLocation kClawClosed(3, 5); |
| 71 | //const ButtonLocation kFridgeClosed(3, 1); |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 72 | |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 73 | |
Austin Schuh | a534ebe | 2015-03-29 18:23:35 -0700 | [diff] [blame] | 74 | const ButtonLocation kStackAndHold(3, 5); |
| 75 | const ButtonLocation kRollersIn(3, 2); |
| 76 | const ButtonLocation kHorizontalCanRollersIn(4, 5); |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 77 | const ButtonLocation kClawToggle(4, 1); |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 78 | |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 79 | const POVLocation kElevatorCanUp(4, 0); |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 80 | |
| 81 | // POV stick 3, 180 |
| 82 | const POVLocation kCanPickup(4, 180); |
| 83 | const ButtonLocation kToteChute(4, 6); |
| 84 | const ButtonLocation kStackAndLift(4, 7); |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 85 | |
| 86 | // Pull in the 6th tote. |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 87 | //const ButtonLocation kSixthTote(4, 10); |
| 88 | const ButtonLocation kCanUp(4, 10); |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 89 | |
| 90 | const ButtonLocation kHeldToLift(4, 11); |
| 91 | const ButtonLocation kPickup(4, 9); |
| 92 | |
| 93 | const ButtonLocation kStack(4, 2); |
| 94 | |
| 95 | // Move the fridge out with the stack in preparation for scoring. |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 96 | const ButtonLocation kScore(4, 8); |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 97 | const ButtonLocation kCoopTop(3, 8); |
| 98 | const ButtonLocation kCoopTopRetract(3, 7); |
| 99 | const ButtonLocation kCoopBottom(3, 6); |
Brian Silverman | d427830 | 2015-03-28 00:21:15 -0400 | [diff] [blame] | 100 | const ButtonLocation kCoopBottomRetract(4, 12); |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 101 | |
Brian Silverman | d427830 | 2015-03-28 00:21:15 -0400 | [diff] [blame] | 102 | const ButtonLocation kCanReset(3, 9); |
Brian Silverman | b9811eb | 2015-03-20 16:54:41 -0700 | [diff] [blame] | 103 | |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 104 | const POVLocation kFridgeToggle(4, 270); |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 105 | const ButtonLocation kSpit(4, 3); |
| 106 | |
| 107 | // Set stack down in the bot. |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 108 | const POVLocation kSetStackDownAndHold(4, 90); |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 109 | |
Austin Schuh | 959d202 | 2015-03-29 13:51:11 -0700 | [diff] [blame] | 110 | const double kClawTotePackAngle = 0.90; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 111 | const double kArmRaiseLowerClearance = -0.08; |
Brian Silverman | 654b512 | 2015-03-20 16:58:04 -0700 | [diff] [blame] | 112 | const double kClawStackClearance = 0.55; |
Austin Schuh | a534ebe | 2015-03-29 18:23:35 -0700 | [diff] [blame] | 113 | const double kHorizontalCanClawAngle = 0.12; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 114 | |
Austin Schuh | 959d202 | 2015-03-29 13:51:11 -0700 | [diff] [blame] | 115 | const double kStackUpHeight = 0.60; |
| 116 | const double kStackUpArm = 0.0; |
Brian Silverman | 697d07b | 2015-03-19 23:41:11 -0700 | [diff] [blame] | 117 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 118 | class Reader : public ::aos::input::JoystickInput { |
| 119 | public: |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 120 | Reader() : was_running_(false) {} |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 121 | |
Brian Silverman | b9811eb | 2015-03-20 16:54:41 -0700 | [diff] [blame] | 122 | static actors::ScoreParams MakeScoreParams() { |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 123 | actors::ScoreParams r; |
Brian Silverman | b9811eb | 2015-03-20 16:54:41 -0700 | [diff] [blame] | 124 | r.move_the_stack = r.place_the_stack = true; |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 125 | r.upper_move_height = 0.14; |
| 126 | r.begin_horizontal_move_height = 0.13; |
| 127 | r.horizontal_move_target = -0.7; |
Austin Schuh | 45ee2c5 | 2015-03-29 13:47:26 -0700 | [diff] [blame] | 128 | r.horizontal_start_lowering = -0.65; |
| 129 | r.home_lift_horizontal_start_position = -0.60; |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 130 | r.place_height = -0.10; |
Austin Schuh | 45ee2c5 | 2015-03-29 13:47:26 -0700 | [diff] [blame] | 131 | r.home_return_height = 0.05; |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 132 | return r; |
| 133 | } |
| 134 | |
| 135 | static actors::ScoreParams MakeCoopTopParams(bool place_the_stack) { |
| 136 | actors::ScoreParams r; |
Brian Silverman | b9811eb | 2015-03-20 16:54:41 -0700 | [diff] [blame] | 137 | r.move_the_stack = !place_the_stack; |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 138 | r.place_the_stack = place_the_stack; |
| 139 | r.upper_move_height = 0.52; |
| 140 | r.begin_horizontal_move_height = 0.5; |
| 141 | r.horizontal_move_target = -0.48; |
Austin Schuh | 45ee2c5 | 2015-03-29 13:47:26 -0700 | [diff] [blame] | 142 | r.horizontal_start_lowering = r.horizontal_move_target; |
| 143 | r.home_lift_horizontal_start_position = -0.3; |
Austin Schuh | a534ebe | 2015-03-29 18:23:35 -0700 | [diff] [blame] | 144 | r.place_height = 0.35; |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 145 | r.home_return_height = 0.1; |
| 146 | return r; |
| 147 | } |
| 148 | |
| 149 | static actors::ScoreParams MakeCoopBottomParams(bool place_the_stack) { |
| 150 | actors::ScoreParams r; |
Brian Silverman | b9811eb | 2015-03-20 16:54:41 -0700 | [diff] [blame] | 151 | r.move_the_stack = !place_the_stack; |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 152 | r.place_the_stack = place_the_stack; |
| 153 | r.upper_move_height = 0.17; |
| 154 | r.begin_horizontal_move_height = 0.16; |
| 155 | r.horizontal_move_target = -0.7; |
Austin Schuh | 45ee2c5 | 2015-03-29 13:47:26 -0700 | [diff] [blame] | 156 | r.horizontal_start_lowering = r.horizontal_move_target; |
| 157 | r.home_lift_horizontal_start_position = -0.3; |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 158 | r.place_height = 0.0; |
| 159 | r.home_return_height = 0.1; |
| 160 | return r; |
| 161 | } |
| 162 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 163 | virtual void RunIteration(const ::aos::input::driver_station::Data &data) { |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 164 | bool last_auto_running = auto_running_; |
| 165 | auto_running_ = data.GetControlBit(ControlBit::kAutonomous) && |
Brian Silverman | e1103e6 | 2015-02-15 02:03:38 -0500 | [diff] [blame] | 166 | data.GetControlBit(ControlBit::kEnabled); |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 167 | if (auto_running_ != last_auto_running) { |
| 168 | if (auto_running_) { |
| 169 | StartAuto(); |
| 170 | } else { |
| 171 | StopAuto(); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 172 | } |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | if (!data.GetControlBit(ControlBit::kAutonomous)) { |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 176 | HandleDrivetrain(data); |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 177 | HandleTeleop(data); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| 181 | void HandleDrivetrain(const ::aos::input::driver_station::Data &data) { |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 182 | const double wheel = -data.GetAxis(kSteeringWheel); |
| 183 | const double throttle = -data.GetAxis(kDriveThrottle); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 184 | |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 185 | if (!drivetrain_queue.goal.MakeWithBuilder() |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 186 | .steering(wheel) |
| 187 | .throttle(throttle) |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 188 | .quickturn(data.IsPressed(kQuickTurn)) |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 189 | .control_loop_driving(false) |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 190 | .Send()) { |
| 191 | LOG(WARNING, "sending stick values failed\n"); |
| 192 | } |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 196 | double intake_power = 0.0; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 197 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 198 | action_queue_.CancelAllActions(); |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 199 | LOG(DEBUG, "Canceling\n"); |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 202 | if (data.IsPressed(kRollersIn)) { |
| 203 | intake_power = 10.0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 204 | claw_goal_ = 0.0; |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 205 | } |
Austin Schuh | a534ebe | 2015-03-29 18:23:35 -0700 | [diff] [blame] | 206 | if (data.IsPressed(kHorizontalCanRollersIn)) { |
| 207 | intake_power = 10.0; |
| 208 | claw_goal_ = kHorizontalCanClawAngle; |
| 209 | } |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 210 | if (data.IsPressed(kSpit)) { |
| 211 | intake_power = -12.0; |
Austin Schuh | a534ebe | 2015-03-29 18:23:35 -0700 | [diff] [blame] | 212 | action_queue_.CancelAllActions(); |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 213 | } |
Austin Schuh | 994d42c | 2015-03-01 00:02:17 -0800 | [diff] [blame] | 214 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 215 | // Toggle button for the claw |
| 216 | if (data.PosEdge(kClawToggle)) { |
| 217 | claw_rollers_closed_ = !claw_rollers_closed_; |
Austin Schuh | 994d42c | 2015-03-01 00:02:17 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 220 | /* |
| 221 | if (data.IsPressed(kClawClosed)) { |
| 222 | claw_rollers_closed_ = true; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 223 | } |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 224 | */ |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 225 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 226 | // Horizontal can pickup. |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 227 | if (data.PosEdge(kElevatorCanUp)) { |
| 228 | actors::HorizontalCanPickupParams params; |
| 229 | params.elevator_height = 0.3; |
Austin Schuh | 4db921a | 2015-04-19 19:59:24 -0700 | [diff] [blame] | 230 | params.pickup_angle = 0.80 + kHorizontalCanClawAngle; |
| 231 | params.spit_time = 0.01; |
| 232 | params.spit_power = -8.0; |
| 233 | |
Austin Schuh | a534ebe | 2015-03-29 18:23:35 -0700 | [diff] [blame] | 234 | params.suck_time = 0.10; |
| 235 | params.suck_power = 10.0; |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 236 | |
| 237 | params.claw_settle_time = 0.05; |
| 238 | params.claw_settle_power = 5.0; |
| 239 | params.claw_full_lift_angle = 1.35; |
| 240 | params.claw_end_angle = 0.5; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 241 | |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 242 | // End low so we don't drop it. |
Austin Schuh | 335fd0d | 2015-04-19 20:02:38 -0700 | [diff] [blame] | 243 | params.elevator_end_height = 0.28; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 244 | params.arm_end_angle = 0.0; |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 245 | action_queue_.EnqueueAction( |
| 246 | actors::MakeHorizontalCanPickupAction(params)); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 247 | fridge_closed_ = true; |
| 248 | } |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 249 | |
| 250 | // -0.942503 arm, 0.374752 elevator |
| 251 | // Vertical can pickup. |
| 252 | if (data.PosEdge(kCanPickup)) { |
| 253 | actors::CanPickupParams params; |
Austin Schuh | 90f2854 | 2015-03-29 13:46:03 -0700 | [diff] [blame] | 254 | params.pickup_x = 0.6; |
| 255 | params.pickup_y = 0.1; |
Austin Schuh | 335fd0d | 2015-04-19 20:02:38 -0700 | [diff] [blame] | 256 | params.lift_height = 0.25; |
Austin Schuh | 90f2854 | 2015-03-29 13:46:03 -0700 | [diff] [blame] | 257 | params.pickup_goal_before_move_height = 0.3; |
| 258 | params.start_lowering_x = 0.1; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 259 | // End low so the can is supported. |
Austin Schuh | 90f2854 | 2015-03-29 13:46:03 -0700 | [diff] [blame] | 260 | params.before_place_height = 0.4; |
Austin Schuh | 335fd0d | 2015-04-19 20:02:38 -0700 | [diff] [blame] | 261 | params.end_height = 0.28; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 262 | params.end_angle = 0.0; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 263 | action_queue_.EnqueueAction(actors::MakeCanPickupAction(params)); |
| 264 | fridge_closed_ = true; |
| 265 | } |
| 266 | |
Brian Silverman | cb615cf | 2015-03-21 21:42:35 -0700 | [diff] [blame] | 267 | if (data.PosEdge(kCanReset)) { |
| 268 | action_queue_.CancelAllActions(); |
Austin Schuh | 335fd0d | 2015-04-19 20:02:38 -0700 | [diff] [blame] | 269 | elevator_goal_ = 0.28; |
Brian Silverman | cb615cf | 2015-03-21 21:42:35 -0700 | [diff] [blame] | 270 | arm_goal_ = 0.0; |
| 271 | } |
| 272 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 273 | // Tote chute pull in when button is pressed, pack when done. |
| 274 | if (data.IsPressed(kToteChute)) { |
Austin Schuh | e301c71 | 2015-04-17 19:29:21 -0700 | [diff] [blame] | 275 | claw_goal_ = 0.8; |
| 276 | intake_power = 6.0; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 277 | } |
| 278 | if (data.NegEdge(kToteChute)) { |
| 279 | claw_goal_ = kClawTotePackAngle; |
| 280 | } |
| 281 | |
| 282 | if (data.PosEdge(kStackAndLift)) { |
| 283 | actors::StackAndLiftParams params; |
Austin Schuh | 959d202 | 2015-03-29 13:51:11 -0700 | [diff] [blame] | 284 | params.stack_params.claw_out_angle = kClawTotePackAngle; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 285 | params.stack_params.bottom = 0.020; |
| 286 | params.stack_params.over_box_before_place_height = 0.39; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 287 | params.stack_params.arm_clearance = kArmRaiseLowerClearance; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 288 | |
| 289 | params.grab_after_stack = true; |
Austin Schuh | 959d202 | 2015-03-29 13:51:11 -0700 | [diff] [blame] | 290 | params.clamp_pause_time = 0.0; |
Brian Silverman | 697d07b | 2015-03-19 23:41:11 -0700 | [diff] [blame] | 291 | params.lift_params.lift_height = kStackUpHeight; |
| 292 | params.lift_params.lift_arm = kStackUpArm; |
Austin Schuh | 3cba379 | 2015-04-19 20:01:22 -0700 | [diff] [blame] | 293 | params.lift_params.second_lift = false; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 294 | params.grab_after_lift = true; |
| 295 | fridge_closed_ = true; |
| 296 | |
| 297 | action_queue_.EnqueueAction(actors::MakeStackAndLiftAction(params)); |
| 298 | } |
| 299 | |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 300 | if (data.PosEdge(kStackAndHold) || data.PosEdge(kSetStackDownAndHold)) { |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 301 | actors::StackAndHoldParams params; |
| 302 | params.bottom = 0.020; |
| 303 | params.over_box_before_place_height = 0.39; |
| 304 | |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 305 | params.arm_clearance = kArmRaiseLowerClearance; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 306 | params.clamp_pause_time = 0.25; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 307 | params.claw_clamp_angle = kClawTotePackAngle; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 308 | |
| 309 | params.hold_height = 0.68; |
Austin Schuh | 959d202 | 2015-03-29 13:51:11 -0700 | [diff] [blame] | 310 | params.claw_out_angle = kClawTotePackAngle; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 311 | |
| 312 | if (data.PosEdge(kSetStackDownAndHold)) { |
| 313 | params.place_not_stack = true; |
| 314 | params.clamp_pause_time = 0.1; |
| 315 | //params.claw_clamp_angle = kClawTotePackAngle - 0.5; |
| 316 | } else { |
| 317 | params.place_not_stack = false; |
| 318 | } |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 319 | |
| 320 | action_queue_.EnqueueAction(actors::MakeStackAndHoldAction(params)); |
| 321 | fridge_closed_ = true; |
| 322 | } |
| 323 | |
| 324 | // TODO(austin): Figure out what action needed to pull the 6th tote into the |
| 325 | // claw. |
| 326 | |
| 327 | // Lower the fridge from holding the stack, grab the stack, and then lift. |
| 328 | if (data.PosEdge(kHeldToLift)) { |
| 329 | actors::HeldToLiftParams params; |
Austin Schuh | 4fef0df | 2015-04-17 19:29:32 -0700 | [diff] [blame] | 330 | params.arm_clearance = kArmRaiseLowerClearance; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 331 | params.clamp_pause_time = 0.1; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 332 | params.before_lift_settle_time = 0.1; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 333 | params.bottom_height = 0.020; |
Austin Schuh | 4fef0df | 2015-04-17 19:29:32 -0700 | [diff] [blame] | 334 | params.claw_out_angle = kClawStackClearance; |
Brian Silverman | 697d07b | 2015-03-19 23:41:11 -0700 | [diff] [blame] | 335 | params.lift_params.lift_height = kStackUpHeight; |
| 336 | params.lift_params.lift_arm = kStackUpArm; |
Austin Schuh | 3cba379 | 2015-04-19 20:01:22 -0700 | [diff] [blame] | 337 | params.lift_params.second_lift = false; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 338 | fridge_closed_ = true; |
| 339 | |
| 340 | action_queue_.EnqueueAction(actors::MakeHeldToLiftAction(params)); |
| 341 | } |
| 342 | |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 343 | // Lift the can up. |
| 344 | if (data.PosEdge(kCanUp)) { |
| 345 | actors::LiftParams params; |
| 346 | params.lift_height = 0.68; |
| 347 | params.lift_arm = 0.3; |
Brian Silverman | 697d07b | 2015-03-19 23:41:11 -0700 | [diff] [blame] | 348 | params.pack_claw = false; |
| 349 | params.pack_claw_angle = 0; |
Austin Schuh | 3cba379 | 2015-04-19 20:01:22 -0700 | [diff] [blame] | 350 | params.intermediate_lift_height = 0.37; |
| 351 | params.second_lift = true; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 352 | fridge_closed_ = true; |
| 353 | |
| 354 | action_queue_.EnqueueAction(actors::MakeLiftAction(params)); |
| 355 | } |
| 356 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 357 | // Pick up a tote from the ground and put it in the bottom of the bot. |
| 358 | if (data.PosEdge(kPickup)) { |
| 359 | actors::PickupParams params; |
Austin Schuh | 7f925ac | 2015-04-18 22:56:22 -0700 | [diff] [blame] | 360 | // TODO(austin): These parameters are coppied into auto right now, need |
| 361 | // to dedup... |
| 362 | |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 363 | // Lift to here initially. |
| 364 | params.pickup_angle = 0.9; |
| 365 | // Start sucking here |
| 366 | params.suck_angle = 0.8; |
| 367 | // Go back down to here to finish sucking. |
| 368 | params.suck_angle_finish = 0.4; |
| 369 | // Pack the box back in here. |
| 370 | params.pickup_finish_angle = kClawTotePackAngle; |
| 371 | params.intake_time = 0.8; |
| 372 | params.intake_voltage = 7.0; |
| 373 | action_queue_.EnqueueAction(actors::MakePickupAction(params)); |
| 374 | } |
| 375 | |
| 376 | // Place stack on a tote in the tray, and grab it. |
| 377 | if (data.PosEdge(kStack)) { |
| 378 | actors::StackParams params; |
Austin Schuh | 959d202 | 2015-03-29 13:51:11 -0700 | [diff] [blame] | 379 | params.claw_out_angle = kClawTotePackAngle; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 380 | params.bottom = 0.020; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 381 | params.only_place = false; |
| 382 | params.arm_clearance = kArmRaiseLowerClearance; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 383 | params.over_box_before_place_height = 0.39; |
| 384 | action_queue_.EnqueueAction(actors::MakeStackAction(params)); |
| 385 | claw_rollers_closed_ = true; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 386 | fridge_closed_ = true; |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 389 | if (data.PosEdge(kScore)) { |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 390 | action_queue_.EnqueueAction( |
Brian Silverman | b9811eb | 2015-03-20 16:54:41 -0700 | [diff] [blame] | 391 | actors::MakeScoreAction(MakeScoreParams())); |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 392 | fridge_closed_ = false; |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 393 | } |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 394 | |
Brian Silverman | 913eafa | 2015-03-19 23:42:16 -0700 | [diff] [blame] | 395 | if (data.PosEdge(kCoopTop)) { |
| 396 | action_queue_.EnqueueAction( |
| 397 | actors::MakeScoreAction(MakeCoopTopParams(false))); |
| 398 | } |
| 399 | if (data.PosEdge(kCoopTopRetract)) { |
| 400 | action_queue_.EnqueueAction( |
| 401 | actors::MakeScoreAction(MakeCoopTopParams(true))); |
| 402 | fridge_closed_ = false; |
| 403 | } |
| 404 | |
| 405 | if (data.PosEdge(kCoopBottom)) { |
| 406 | action_queue_.EnqueueAction( |
| 407 | actors::MakeScoreAction(MakeCoopBottomParams(false))); |
| 408 | } |
| 409 | if (data.PosEdge(kCoopBottomRetract)) { |
| 410 | action_queue_.EnqueueAction( |
| 411 | actors::MakeScoreAction(MakeCoopBottomParams(true))); |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 412 | fridge_closed_ = false; |
| 413 | } |
| 414 | |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 415 | if (data.PosEdge(kFridgeToggle)) { |
| 416 | fridge_closed_ = !fridge_closed_; |
| 417 | } |
| 418 | |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 419 | if (data.PosEdge(ControlBit::kEnabled)) { |
| 420 | // If we got enabled, wait for everything to zero. |
| 421 | LOG(INFO, "Waiting for zero.\n"); |
| 422 | waiting_for_zero_ = true; |
| 423 | } |
| 424 | |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 425 | claw_queue.status.FetchLatest(); |
| 426 | fridge_queue.status.FetchLatest(); |
| 427 | if (!claw_queue.status.get()) { |
| 428 | LOG(ERROR, "Got no claw status packet.\n"); |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 429 | } |
| 430 | if (!fridge_queue.status.get()) { |
| 431 | LOG(ERROR, "Got no fridge status packet.\n"); |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 432 | } |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 433 | |
Brian Silverman | ea91f59 | 2015-03-28 18:25:57 -0400 | [diff] [blame] | 434 | if (claw_queue.status.get() && fridge_queue.status.get() && |
| 435 | claw_queue.status->zeroed && fridge_queue.status->zeroed) { |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 436 | if (waiting_for_zero_) { |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 437 | LOG(INFO, "Zeroed! Starting teleop mode.\n"); |
| 438 | waiting_for_zero_ = false; |
| 439 | |
| 440 | // Set the initial goals to where we are now. |
Austin Schuh | 2cee0b5 | 2015-03-29 13:41:39 -0700 | [diff] [blame] | 441 | elevator_goal_ = 0.3; |
| 442 | arm_goal_ = 0.0; |
| 443 | claw_goal_ = 0.6; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 444 | } |
| 445 | } else { |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 446 | waiting_for_zero_ = true; |
Austin Schuh | 700b922 | 2015-03-01 03:03:15 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | if (!waiting_for_zero_) { |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 450 | if (!action_queue_.Running()) { |
| 451 | auto new_fridge_goal = fridge_queue.goal.MakeMessage(); |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 452 | new_fridge_goal->max_velocity = elevator_params_.velocity; |
| 453 | new_fridge_goal->max_acceleration = elevator_params_.acceleration; |
Austin Schuh | 1d44bd4 | 2015-03-15 16:40:45 -0700 | [diff] [blame] | 454 | new_fridge_goal->profiling_type = 0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 455 | new_fridge_goal->height = elevator_goal_; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 456 | new_fridge_goal->velocity = 0.0; |
| 457 | new_fridge_goal->max_angular_velocity = arm_params_.velocity; |
| 458 | new_fridge_goal->max_angular_acceleration = arm_params_.acceleration; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 459 | new_fridge_goal->angle = arm_goal_; |
| 460 | new_fridge_goal->angular_velocity = 0.0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 461 | new_fridge_goal->grabbers.top_front = fridge_closed_; |
| 462 | new_fridge_goal->grabbers.top_back = fridge_closed_; |
| 463 | new_fridge_goal->grabbers.bottom_front = fridge_closed_; |
| 464 | new_fridge_goal->grabbers.bottom_back = fridge_closed_; |
| 465 | |
| 466 | if (!new_fridge_goal.Send()) { |
| 467 | LOG(ERROR, "Sending fridge goal failed.\n"); |
| 468 | } else { |
| 469 | LOG(DEBUG, "sending goals: elevator: %f, arm: %f\n", elevator_goal_, |
| 470 | arm_goal_); |
| 471 | } |
| 472 | if (!claw_queue.goal.MakeWithBuilder() |
| 473 | .angle(claw_goal_) |
| 474 | .rollers_closed(claw_rollers_closed_) |
Austin Schuh | a534ebe | 2015-03-29 18:23:35 -0700 | [diff] [blame] | 475 | .max_velocity(5.0) |
Brian Silverman | 1004357 | 2015-03-21 23:43:50 -0700 | [diff] [blame] | 476 | .max_acceleration(6.0) |
Austin Schuh | f14727e | 2015-03-08 18:49:12 -0700 | [diff] [blame] | 477 | .intake(intake_power) |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 478 | .Send()) { |
| 479 | LOG(ERROR, "Sending claw goal failed.\n"); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 484 | if (action_queue_.Running()) { |
| 485 | // If we are running an action, update our goals to the current goals. |
| 486 | control_loops::fridge_queue.status.FetchLatest(); |
| 487 | if (control_loops::fridge_queue.status.get()) { |
| 488 | arm_goal_ = control_loops::fridge_queue.status->goal_angle; |
| 489 | elevator_goal_ = control_loops::fridge_queue.status->goal_height; |
| 490 | } else { |
| 491 | LOG(ERROR, "No fridge status!\n"); |
| 492 | } |
| 493 | |
| 494 | // If we are running an action, update our goals to the current goals. |
| 495 | control_loops::claw_queue.status.FetchLatest(); |
| 496 | if (control_loops::claw_queue.status.get()) { |
| 497 | claw_goal_ = control_loops::claw_queue.status->goal_angle; |
| 498 | } else { |
Brian Silverman | ea91f59 | 2015-03-28 18:25:57 -0400 | [diff] [blame] | 499 | LOG(ERROR, "No claw status!\n"); |
Austin Schuh | d8b2a24 | 2015-02-22 21:46:53 -0800 | [diff] [blame] | 500 | } |
| 501 | } |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 502 | action_queue_.Tick(); |
| 503 | was_running_ = action_queue_.Running(); |
| 504 | } |
| 505 | |
| 506 | private: |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 507 | void StartAuto() { |
| 508 | LOG(INFO, "Starting auto mode\n"); |
| 509 | ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(true).Send(); |
| 510 | } |
| 511 | |
| 512 | void StopAuto() { |
| 513 | LOG(INFO, "Stopping auto mode\n"); |
| 514 | ::frc971::autonomous::autonomous.MakeWithBuilder().run_auto(false).Send(); |
| 515 | } |
| 516 | |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 517 | bool was_running_; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 518 | |
| 519 | // Previous goals for systems. |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 520 | double elevator_goal_ = 0.2; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 521 | double arm_goal_ = 0.0; |
| 522 | double claw_goal_ = 0.0; |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 523 | bool claw_rollers_closed_ = false; |
| 524 | bool fridge_closed_ = false; |
Austin Schuh | 6e242ac | 2015-03-07 17:08:21 -0800 | [diff] [blame] | 525 | actors::ProfileParams arm_params_ = kArmMove; |
| 526 | actors::ProfileParams elevator_params_ = kElevatorMove; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 527 | |
| 528 | // If we're waiting for the subsystems to zero. |
Austin Schuh | cde7ffe | 2015-02-20 22:10:41 -0800 | [diff] [blame] | 529 | bool waiting_for_zero_ = true; |
Daniel Petti | 6189652 | 2015-02-15 18:01:43 -0800 | [diff] [blame] | 530 | |
Austin Schuh | 6182f8d | 2015-02-14 22:15:04 -0800 | [diff] [blame] | 531 | bool auto_running_ = false; |
| 532 | |
Austin Schuh | 331e13d | 2015-02-15 00:16:51 -0800 | [diff] [blame] | 533 | ::aos::common::actions::ActionQueue action_queue_; |
Brian Silverman | 20141f9 | 2015-01-05 17:39:01 -0800 | [diff] [blame] | 534 | |
| 535 | ::aos::util::SimpleLogInterval no_drivetrain_status_ = |
| 536 | ::aos::util::SimpleLogInterval(::aos::time::Time::InSeconds(0.2), WARNING, |
| 537 | "no drivetrain status"); |
| 538 | }; |
| 539 | |
| 540 | } // namespace joysticks |
| 541 | } // namespace input |
| 542 | } // namespace frc971 |
| 543 | |
| 544 | int main() { |
| 545 | ::aos::Init(); |
| 546 | ::frc971::input::joysticks::Reader reader; |
| 547 | reader.Run(); |
| 548 | ::aos::Cleanup(); |
| 549 | } |