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