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