Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -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" |
Austin Schuh | 06cbbf1 | 2014-02-22 02:07:31 -0800 | [diff] [blame] | 8 | #include "aos/common/input/driver_station_data.h" |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 9 | #include "aos/common/logging/logging.h" |
| 10 | |
| 11 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 12 | #include "frc971/queues/othersensors.q.h" |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 13 | #include "frc971/autonomous/auto.q.h" |
Brian Silverman | fac5c29 | 2014-02-17 15:26:57 -0800 | [diff] [blame] | 14 | #include "frc971/control_loops/claw/claw.q.h" |
| 15 | #include "frc971/control_loops/shooter/shooter.q.h" |
Ben Fredrickson | aa45045 | 2014-03-01 09:41:18 +0000 | [diff] [blame] | 16 | #include "frc971/actions/shoot_action.q.h" |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 17 | |
| 18 | using ::frc971::control_loops::drivetrain; |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 19 | using ::frc971::sensors::othersensors; |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 20 | |
| 21 | using ::aos::input::driver_station::ButtonLocation; |
| 22 | using ::aos::input::driver_station::JoystickAxis; |
| 23 | using ::aos::input::driver_station::ControlBit; |
| 24 | |
| 25 | namespace frc971 { |
| 26 | namespace input { |
| 27 | namespace joysticks { |
| 28 | |
| 29 | const ButtonLocation kDriveControlLoopEnable1(1, 7), |
| 30 | kDriveControlLoopEnable2(1, 11); |
| 31 | const JoystickAxis kSteeringWheel(1, 1), kDriveThrottle(2, 2); |
| 32 | const ButtonLocation kShiftHigh(2, 1), kShiftLow(2, 3); |
| 33 | const ButtonLocation kQuickTurn(1, 5); |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 34 | |
Austin Schuh | 06cbbf1 | 2014-02-22 02:07:31 -0800 | [diff] [blame] | 35 | const ButtonLocation kFire(3, 11); |
Austin Schuh | 9cb836e | 2014-02-23 19:25:55 -0800 | [diff] [blame] | 36 | const ButtonLocation kUnload(2, 11); |
| 37 | const ButtonLocation kReload(2, 6); |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 38 | |
| 39 | const ButtonLocation kRollersOut(3, 12); |
| 40 | const ButtonLocation kRollersIn(3, 10); |
| 41 | |
| 42 | const ButtonLocation kTuck(3, 8); |
Austin Schuh | 9cb836e | 2014-02-23 19:25:55 -0800 | [diff] [blame] | 43 | const ButtonLocation kIntakeOpenPosition(3, 9); |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 44 | const ButtonLocation kIntakePosition(3, 7); |
| 45 | |
| 46 | const ButtonLocation kLongShot(3, 5); |
| 47 | const ButtonLocation kMediumShot(3, 3); |
| 48 | const ButtonLocation kShortShot(3, 6); |
| 49 | |
| 50 | struct ClawGoal { |
| 51 | double angle; |
| 52 | double separation; |
| 53 | }; |
| 54 | |
| 55 | const ClawGoal kTuckGoal = {-2.273474, -0.749484}; |
| 56 | const ClawGoal kIntakeGoal = {-2.273474, 0.0}; |
Austin Schuh | 9cb836e | 2014-02-23 19:25:55 -0800 | [diff] [blame] | 57 | const ClawGoal kIntakeOpenGoal = {-2.0, 1.2}; |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 58 | |
Austin Schuh | 9cb836e | 2014-02-23 19:25:55 -0800 | [diff] [blame] | 59 | const ClawGoal kLongShotGoal = {-M_PI / 2.0 + 0.43, 0.10}; |
| 60 | const ClawGoal kMediumShotGoal = {-0.9, 0.10}; |
| 61 | const ClawGoal kShortShotGoal = {-0.04, 0.11}; |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 62 | |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 63 | class Action { |
| 64 | public: |
| 65 | // Cancels the action. |
| 66 | void Cancel() { DoCancel(); } |
| 67 | // Returns true if the action is currently running. |
| 68 | bool Running() { return DoRunning(); } |
| 69 | // Starts the action. |
| 70 | void Start() { DoStart(); } |
| 71 | |
Austin Schuh | f870499 | 2014-03-02 14:02:53 -0800 | [diff] [blame^] | 72 | virtual ~Action() {} |
| 73 | |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 74 | private: |
| 75 | virtual void DoCancel() = 0; |
| 76 | virtual bool DoRunning() = 0; |
| 77 | virtual void DoStart() = 0; |
| 78 | }; |
| 79 | |
| 80 | // Templated subclass to hold the type information. |
| 81 | template <typename T> |
| 82 | class TypedAction : public Action { |
| 83 | public: |
| 84 | typedef typename std::remove_reference< |
| 85 | decltype(*(static_cast<T *>(NULL)->goal.MakeMessage().get()))>::type |
| 86 | GoalType; |
| 87 | |
| 88 | TypedAction(T *queue_group) |
| 89 | : queue_group_(queue_group), |
| 90 | goal_(queue_group_->goal.MakeMessage()), |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 91 | has_started_(false) {} |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 92 | |
| 93 | // Returns the current goal that will be sent when the action is sent. |
| 94 | GoalType *GetGoal() { return goal_.get(); } |
| 95 | |
Austin Schuh | f870499 | 2014-03-02 14:02:53 -0800 | [diff] [blame^] | 96 | virtual ~TypedAction() { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 97 | LOG(INFO, "Calling destructor\n"); |
| 98 | DoCancel(); |
| 99 | } |
| 100 | |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 101 | private: |
| 102 | // Cancels the action. |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 103 | virtual void DoCancel() { |
| 104 | LOG(INFO, "Canceling action\n"); |
| 105 | queue_group_->goal.MakeWithBuilder().run(false).Send(); |
| 106 | } |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 107 | |
| 108 | // Returns true if the action is running or we don't have an initial response |
| 109 | // back from it to signal whether or not it is running. |
| 110 | virtual bool DoRunning() { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 111 | if (has_started_) { |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 112 | queue_group_->status.FetchLatest(); |
| 113 | } else if (queue_group_->status.FetchLatest()) { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 114 | if (queue_group_->status->running) { |
| 115 | // Wait until it reports that it is running to start. |
| 116 | has_started_ = true; |
| 117 | } |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 118 | } |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 119 | return !has_started_ || |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 120 | (queue_group_->status.get() && queue_group_->status->running); |
| 121 | } |
| 122 | |
| 123 | // Starts the action if a goal has been created. |
| 124 | virtual void DoStart() { |
| 125 | if (goal_) { |
| 126 | goal_->run = true; |
| 127 | goal_.Send(); |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 128 | has_started_ = false; |
| 129 | LOG(INFO, "Starting action\n"); |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 130 | } else { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 131 | has_started_ = true; |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
| 135 | T *queue_group_; |
| 136 | ::aos::ScopedMessagePtr<GoalType> goal_; |
| 137 | // Track if we have seen a response to the start message. |
| 138 | // If we haven't, we are considered running regardless. |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 139 | bool has_started_; |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | // Makes a new ShootAction action. |
| 143 | ::std::unique_ptr<TypedAction< ::frc971::actions::ShootActionQueueGroup>> |
| 144 | MakeShootAction() { |
| 145 | return ::std::unique_ptr< |
| 146 | TypedAction< ::frc971::actions::ShootActionQueueGroup>>( |
| 147 | new TypedAction< ::frc971::actions::ShootActionQueueGroup>( |
| 148 | &::frc971::actions::shoot_action)); |
| 149 | } |
| 150 | |
| 151 | // A queue which queues Actions and cancels them. |
| 152 | class ActionQueue { |
| 153 | public: |
| 154 | // Queues up an action for sending. |
| 155 | void QueueAction(::std::unique_ptr<Action> action) { |
| 156 | if (current_action_) { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 157 | LOG(INFO, "Queueing action, canceling prior\n"); |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 158 | current_action_->Cancel(); |
| 159 | next_action_ = ::std::move(action); |
| 160 | } else { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 161 | LOG(INFO, "Queueing action\n"); |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 162 | current_action_ = ::std::move(action); |
| 163 | current_action_->Start(); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Cancels the current action, and runs the next one when the current one has |
| 168 | // finished. |
| 169 | void CancelCurrentAction() { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 170 | LOG(INFO, "Canceling current action\n"); |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 171 | if (current_action_) { |
| 172 | current_action_->Cancel(); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | // Cancels all running actions. |
| 177 | void CancelAllActions() { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 178 | LOG(INFO, "Canceling all actions\n"); |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 179 | if (current_action_) { |
| 180 | current_action_->Cancel(); |
| 181 | } |
| 182 | next_action_.reset(); |
| 183 | } |
| 184 | |
| 185 | // Runs the next action when the current one is finished running. |
| 186 | void Tick() { |
| 187 | if (current_action_) { |
| 188 | if (!current_action_->Running()) { |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 189 | LOG(INFO, "Action is done.\n"); |
| 190 | current_action_ = ::std::move(next_action_); |
| 191 | if (current_action_) { |
| 192 | LOG(INFO, "Running next action\n"); |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 193 | current_action_->Start(); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // Returns true if any action is running or could be running. |
| 200 | // For a one cycle faster response, call Tick before running this. |
| 201 | bool Running() { return (bool)current_action_; } |
| 202 | |
| 203 | private: |
| 204 | ::std::unique_ptr<Action> current_action_; |
| 205 | ::std::unique_ptr<Action> next_action_; |
| 206 | }; |
| 207 | |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 208 | class Reader : public ::aos::input::JoystickInput { |
| 209 | public: |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 210 | Reader() |
| 211 | : is_high_gear_(false), |
Austin Schuh | 9cb836e | 2014-02-23 19:25:55 -0800 | [diff] [blame] | 212 | shot_power_(80.0), |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 213 | goal_angle_(0.0), |
| 214 | separation_angle_(0.0) {} |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 215 | |
| 216 | virtual void RunIteration(const ::aos::input::driver_station::Data &data) { |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 217 | if (data.GetControlBit(ControlBit::kAutonomous)) { |
| 218 | if (data.PosEdge(ControlBit::kEnabled)){ |
| 219 | LOG(INFO, "Starting auto mode\n"); |
| 220 | ::frc971::autonomous::autonomous.MakeWithBuilder() |
| 221 | .run_auto(true).Send(); |
| 222 | } else if (data.NegEdge(ControlBit::kEnabled)) { |
| 223 | LOG(INFO, "Stopping auto mode\n"); |
| 224 | ::frc971::autonomous::autonomous.MakeWithBuilder() |
| 225 | .run_auto(false).Send(); |
| 226 | } |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 227 | } else { |
| 228 | HandleTeleop(data); |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 229 | } |
| 230 | } |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 231 | |
| 232 | void HandleDrivetrain(const ::aos::input::driver_station::Data &data) { |
| 233 | bool is_control_loop_driving = false; |
| 234 | double left_goal = 0.0; |
| 235 | double right_goal = 0.0; |
| 236 | const double wheel = -data.GetAxis(kSteeringWheel); |
| 237 | const double throttle = -data.GetAxis(kDriveThrottle); |
| 238 | const double kThrottleGain = 1.0 / 2.5; |
| 239 | if (false && (data.IsPressed(kDriveControlLoopEnable1) || |
| 240 | data.IsPressed(kDriveControlLoopEnable2))) { |
| 241 | // TODO(austin): Static sucks! |
| 242 | static double distance = 0.0; |
| 243 | static double angle = 0.0; |
| 244 | static double filtered_goal_distance = 0.0; |
| 245 | if (data.PosEdge(kDriveControlLoopEnable1) || |
| 246 | data.PosEdge(kDriveControlLoopEnable2)) { |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 247 | if (drivetrain.position.FetchLatest() && othersensors.FetchLatest()) { |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 248 | distance = (drivetrain.position->left_encoder + |
| 249 | drivetrain.position->right_encoder) / |
| 250 | 2.0 - |
| 251 | throttle * kThrottleGain / 2.0; |
Ben Fredrickson | 81ba2d5 | 2014-03-02 08:21:46 +0000 | [diff] [blame] | 252 | angle = othersensors->gyro_angle; |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 253 | filtered_goal_distance = distance; |
| 254 | } |
| 255 | } |
| 256 | is_control_loop_driving = true; |
| 257 | |
| 258 | // const double gyro_angle = Gyro.View().angle; |
| 259 | const double goal_theta = angle - wheel * 0.27; |
| 260 | const double goal_distance = distance + throttle * kThrottleGain; |
| 261 | const double robot_width = 22.0 / 100.0 * 2.54; |
| 262 | const double kMaxVelocity = 0.6; |
| 263 | if (goal_distance > kMaxVelocity * 0.02 + filtered_goal_distance) { |
| 264 | filtered_goal_distance += kMaxVelocity * 0.02; |
| 265 | } else if (goal_distance < |
| 266 | -kMaxVelocity * 0.02 + filtered_goal_distance) { |
| 267 | filtered_goal_distance -= kMaxVelocity * 0.02; |
| 268 | } else { |
| 269 | filtered_goal_distance = goal_distance; |
| 270 | } |
| 271 | left_goal = filtered_goal_distance - robot_width * goal_theta / 2.0; |
| 272 | right_goal = filtered_goal_distance + robot_width * goal_theta / 2.0; |
| 273 | is_high_gear_ = false; |
| 274 | |
| 275 | LOG(DEBUG, "Left goal %f Right goal %f\n", left_goal, right_goal); |
| 276 | } |
| 277 | if (!drivetrain.goal.MakeWithBuilder() |
| 278 | .steering(wheel) |
| 279 | .throttle(throttle) |
| 280 | .highgear(is_high_gear_) |
| 281 | .quickturn(data.IsPressed(kQuickTurn)) |
| 282 | .control_loop_driving(is_control_loop_driving) |
| 283 | .left_goal(left_goal) |
| 284 | .right_goal(right_goal) |
| 285 | .Send()) { |
| 286 | LOG(WARNING, "sending stick values failed\n"); |
| 287 | } |
| 288 | if (data.PosEdge(kShiftHigh)) { |
| 289 | is_high_gear_ = false; |
| 290 | } |
| 291 | if (data.PosEdge(kShiftLow)) { |
| 292 | is_high_gear_ = true; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | void SetGoal(ClawGoal goal) { |
| 297 | goal_angle_ = goal.angle; |
| 298 | separation_angle_ = goal.separation; |
| 299 | } |
| 300 | |
| 301 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
| 302 | HandleDrivetrain(data); |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 303 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 304 | action_queue_.CancelAllActions(); |
| 305 | } |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 306 | |
Austin Schuh | 9cb836e | 2014-02-23 19:25:55 -0800 | [diff] [blame] | 307 | if (data.IsPressed(kIntakeOpenPosition)) { |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 308 | action_queue_.CancelAllActions(); |
Austin Schuh | 9cb836e | 2014-02-23 19:25:55 -0800 | [diff] [blame] | 309 | SetGoal(kIntakeOpenGoal); |
| 310 | } else if (data.IsPressed(kIntakePosition)) { |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 311 | action_queue_.CancelAllActions(); |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 312 | SetGoal(kIntakeGoal); |
| 313 | } else if (data.IsPressed(kTuck)) { |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 314 | action_queue_.CancelAllActions(); |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 315 | SetGoal(kTuckGoal); |
| 316 | } |
| 317 | |
Ben Fredrickson | aa45045 | 2014-03-01 09:41:18 +0000 | [diff] [blame] | 318 | if (data.PosEdge(kLongShot)) { |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 319 | auto shoot_action = MakeShootAction(); |
| 320 | |
| 321 | shot_power_ = 160.0; |
| 322 | shoot_action->GetGoal()->shot_power = shot_power_; |
| 323 | shoot_action->GetGoal()->shot_angle = kLongShotGoal.angle; |
| 324 | SetGoal(kLongShotGoal); |
| 325 | |
| 326 | action_queue_.QueueAction(::std::move(shoot_action)); |
Ben Fredrickson | f465a06 | 2014-03-02 00:18:59 +0000 | [diff] [blame] | 327 | } else if (data.PosEdge(kMediumShot)) { |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 328 | auto shoot_action = MakeShootAction(); |
| 329 | |
| 330 | shot_power_ = 100.0; |
| 331 | shoot_action->GetGoal()->shot_power = shot_power_; |
| 332 | shoot_action->GetGoal()->shot_angle = kMediumShotGoal.angle; |
| 333 | SetGoal(kMediumShotGoal); |
| 334 | |
| 335 | action_queue_.QueueAction(::std::move(shoot_action)); |
Ben Fredrickson | f465a06 | 2014-03-02 00:18:59 +0000 | [diff] [blame] | 336 | } else if (data.PosEdge(kShortShot)) { |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 337 | auto shoot_action = MakeShootAction(); |
| 338 | |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 339 | shot_power_ = 20.0; |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 340 | shoot_action->GetGoal()->shot_power = shot_power_; |
| 341 | shoot_action->GetGoal()->shot_angle = kShortShotGoal.angle; |
| 342 | SetGoal(kShortShotGoal); |
| 343 | |
| 344 | action_queue_.QueueAction(::std::move(shoot_action)); |
| 345 | } |
| 346 | |
| 347 | action_queue_.Tick(); |
Austin Schuh | c95c2b7 | 2014-03-02 11:56:49 -0800 | [diff] [blame] | 348 | if (data.IsPressed(kUnload) || data.IsPressed(kReload)) { |
| 349 | action_queue_.CancelAllActions(); |
| 350 | } |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 351 | |
| 352 | // Send out the claw and shooter goals if no actions are running. |
| 353 | if (!action_queue_.Running()) { |
| 354 | if (!control_loops::claw_queue_group.goal.MakeWithBuilder() |
| 355 | .bottom_angle(goal_angle_) |
| 356 | .separation_angle(separation_angle_) |
| 357 | .intake(data.IsPressed(kRollersIn) |
| 358 | ? 12.0 |
| 359 | : (data.IsPressed(kRollersOut) ? -12.0 : 0.0)) |
| 360 | .centering(data.IsPressed(kRollersIn) ? 12.0 : 0.0) |
| 361 | .Send()) { |
| 362 | LOG(WARNING, "sending claw goal failed\n"); |
| 363 | } |
| 364 | |
| 365 | if (!control_loops::shooter_queue_group.goal.MakeWithBuilder() |
| 366 | .shot_power(shot_power_) |
| 367 | .shot_requested(data.IsPressed(kFire)) |
| 368 | .unload_requested(data.IsPressed(kUnload)) |
| 369 | .load_requested(data.IsPressed(kReload)) |
| 370 | .Send()) { |
| 371 | LOG(WARNING, "sending shooter goal failed\n"); |
| 372 | } |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
Austin Schuh | 01c652b | 2014-02-21 23:13:42 -0800 | [diff] [blame] | 376 | private: |
Austin Schuh | 58d2368 | 2014-02-23 01:39:50 -0800 | [diff] [blame] | 377 | bool is_high_gear_; |
| 378 | double shot_power_; |
| 379 | double goal_angle_; |
| 380 | double separation_angle_; |
Austin Schuh | b7dfabc | 2014-03-01 18:57:42 -0800 | [diff] [blame] | 381 | |
| 382 | ActionQueue action_queue_; |
Brian Silverman | 756f9ff | 2014-01-17 23:40:23 -0800 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | } // namespace joysticks |
| 386 | } // namespace input |
| 387 | } // namespace frc971 |
| 388 | |
| 389 | int main() { |
| 390 | ::aos::Init(); |
| 391 | ::frc971::input::joysticks::Reader reader; |
| 392 | reader.Run(); |
| 393 | ::aos::Cleanup(); |
| 394 | } |