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