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