Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 1 | #include <math.h> |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | #include "aos/actions/actions.h" |
| 7 | #include "aos/init.h" |
| 8 | #include "aos/input/action_joystick_input.h" |
| 9 | #include "aos/input/driver_station_data.h" |
| 10 | #include "aos/input/drivetrain_input.h" |
| 11 | #include "aos/input/joystick_input.h" |
| 12 | #include "aos/logging/logging.h" |
| 13 | #include "aos/logging/logging.h" |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 14 | #include "aos/network/team_number.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 15 | #include "aos/util/log_interval.h" |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 16 | #include "aos/vision/events/udp.h" |
| 17 | #include "external/com_google_protobuf/src/google/protobuf/stubs/stringprintf.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 18 | #include "frc971/autonomous/auto.q.h" |
| 19 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 20 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 21 | |
| 22 | #include "y2019/control_loops/drivetrain/drivetrain_base.h" |
| 23 | #include "y2019/control_loops/superstructure/superstructure.q.h" |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 24 | #include "y2019/status_light.q.h" |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 25 | #include "y2019/vision.pb.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 26 | |
| 27 | using ::y2019::control_loops::superstructure::superstructure_queue; |
| 28 | using ::aos::input::driver_station::ButtonLocation; |
| 29 | using ::aos::input::driver_station::ControlBit; |
| 30 | using ::aos::input::driver_station::JoystickAxis; |
| 31 | using ::aos::input::driver_station::POVLocation; |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 32 | using ::aos::events::ProtoTXUdpSocket; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 33 | |
| 34 | namespace y2019 { |
| 35 | namespace input { |
| 36 | namespace joysticks { |
| 37 | |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 38 | using google::protobuf::StringPrintf; |
| 39 | |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 40 | const ButtonLocation kSuctionBall(3, 13); |
| 41 | const ButtonLocation kSuctionHatch(3, 12); |
| 42 | const ButtonLocation kDeployStilt(3, 8); |
| 43 | const ButtonLocation kFallOver(3, 9); |
Austin Schuh | 2cf16b8 | 2019-02-15 23:23:22 -0800 | [diff] [blame] | 44 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 45 | struct ElevatorWristPosition { |
| 46 | double elevator; |
| 47 | double wrist; |
| 48 | }; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 49 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 50 | const ButtonLocation kRocketForwardLower(5, 1); |
| 51 | const ButtonLocation kRocketForwardMiddle(5, 2); |
| 52 | const ButtonLocation kRocketForwardUpper(5, 4); |
| 53 | const ButtonLocation kCargoForward(5, 3); |
| 54 | |
| 55 | const POVLocation kRocketBackwardUnpressed(5, -1); |
| 56 | const POVLocation kRocketBackwardLower(5, 180); |
| 57 | const POVLocation kRocketBackwardMiddle(5, 90); |
| 58 | const POVLocation kRocketBackwardUpper(5, 0); |
| 59 | const POVLocation kCargoBackward(5, 270); |
| 60 | |
| 61 | const ButtonLocation kPanelSwitch(5, 7); |
| 62 | const ButtonLocation kCargoSwitch(5, 8); |
| 63 | |
| 64 | const ButtonLocation kBallHPIntakeForward(5, 6); |
| 65 | const ButtonLocation kBallHPIntakeBackward(5, 5); |
| 66 | const JoystickAxis kBallOutake(5, 3); |
| 67 | const JoystickAxis kBallIntake(5, 4); |
| 68 | |
| 69 | const ButtonLocation kPanelHPIntakeForward(5, 6); |
| 70 | const ButtonLocation kPanelHPIntakeBackward(5, 5); |
| 71 | |
| 72 | const ButtonLocation kRelease(2, 4); |
| 73 | |
| 74 | const ElevatorWristPosition kStowPos{0.36, 0.0}; |
| 75 | |
| 76 | const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.04, M_PI / 2.0}; |
Sabina Davis | e6fe6c5 | 2019-03-03 15:48:51 -0800 | [diff] [blame] | 77 | const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.05, -M_PI / 2.0}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 78 | |
| 79 | const ElevatorWristPosition kPanelForwardLowerPos{0.0, M_PI / 2.0}; |
| 80 | const ElevatorWristPosition kPanelBackwardLowerPos{0.0, -M_PI / 2.0}; |
| 81 | |
Sabina Davis | e48004f | 2019-03-02 23:15:24 -0800 | [diff] [blame] | 82 | const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0}; |
| 83 | const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 84 | |
Sabina Davis | e48004f | 2019-03-02 23:15:24 -0800 | [diff] [blame] | 85 | const ElevatorWristPosition kPanelForwardUpperPos{1.51, M_PI / 2.0}; |
| 86 | const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 87 | |
Sabina Davis | e6fe6c5 | 2019-03-03 15:48:51 -0800 | [diff] [blame] | 88 | const ElevatorWristPosition kPanelCargoForwardPos{0.0, M_PI / 2.0}; |
| 89 | const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0}; |
| 90 | |
| 91 | const ElevatorWristPosition kBallForwardLowerPos{0.46, M_PI / 2.0}; |
| 92 | const ElevatorWristPosition kBallBackwardLowerPos{0.15, -M_PI / 2.0}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 93 | |
Sabina Davis | e48004f | 2019-03-02 23:15:24 -0800 | [diff] [blame] | 94 | const ElevatorWristPosition kBallForwardMiddlePos{1.16, 1.546}; |
| 95 | const ElevatorWristPosition kBallBackwardMiddlePos{0.876021, -1.546}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 96 | |
Sabina Davis | e48004f | 2019-03-02 23:15:24 -0800 | [diff] [blame] | 97 | const ElevatorWristPosition kBallForwardUpperPos{1.50, 0.961}; |
| 98 | const ElevatorWristPosition kBallBackwardUpperPos{1.41, -1.217}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 99 | |
Sabina Davis | e48004f | 2019-03-02 23:15:24 -0800 | [diff] [blame] | 100 | const ElevatorWristPosition kBallCargoForwardPos{0.699044, 1.353}; |
| 101 | const ElevatorWristPosition kBallCargoBackwardPos{0.828265, -1.999}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 102 | |
Sabina Davis | e6fe6c5 | 2019-03-03 15:48:51 -0800 | [diff] [blame] | 103 | const ElevatorWristPosition kBallHPIntakeForwardPos{0.55, 1.097}; |
| 104 | const ElevatorWristPosition kBallHPIntakeBackwardPos{0.89, -2.018}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 105 | |
| 106 | const ElevatorWristPosition kBallIntakePos{0.29, 2.14}; |
Austin Schuh | 2cf16b8 | 2019-02-15 23:23:22 -0800 | [diff] [blame] | 107 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 108 | class Reader : public ::aos::input::ActionJoystickInput { |
| 109 | public: |
| 110 | Reader(::aos::EventLoop *event_loop) |
| 111 | : ::aos::input::ActionJoystickInput( |
| 112 | event_loop, |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 113 | ::y2019::control_loops::drivetrain::GetDrivetrainConfig()) { |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 114 | const uint16_t team = ::aos::network::GetTeamNumber(); |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 115 | superstructure_queue.goal.FetchLatest(); |
| 116 | if (superstructure_queue.goal.get()) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 117 | grab_piece_ = superstructure_queue.goal->suction.grab_piece; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 118 | } |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 119 | video_tx_.reset(new ProtoTXUdpSocket<VisionControl>( |
| 120 | StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000)); |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 121 | } |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 122 | |
| 123 | void HandleTeleop(const ::aos::input::driver_station::Data &data) { |
| 124 | superstructure_queue.position.FetchLatest(); |
| 125 | superstructure_queue.status.FetchLatest(); |
| 126 | if (!superstructure_queue.status.get() || |
| 127 | !superstructure_queue.position.get()) { |
| 128 | LOG(ERROR, "Got no superstructure status packet.\n"); |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | auto new_superstructure_goal = superstructure_queue.goal.MakeMessage(); |
| 133 | |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 134 | if (data.IsPressed(kSuctionBall)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 135 | grab_piece_ = true; |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 136 | } else if (data.IsPressed(kSuctionHatch)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 137 | grab_piece_ = true; |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 138 | } else if (data.IsPressed(kRelease) || |
| 139 | !superstructure_queue.status->has_piece) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 140 | grab_piece_ = false; |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 141 | } |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 142 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 143 | if (data.IsPressed(kRocketBackwardUnpressed)) { |
| 144 | elevator_wrist_pos_ = kStowPos; |
| 145 | } |
| 146 | new_superstructure_goal->intake.unsafe_goal = -1.2; |
| 147 | new_superstructure_goal->roller_voltage = 0.0; |
| 148 | |
| 149 | const bool kDoBallIntake = data.GetAxis(kBallIntake) > 0.9; |
| 150 | const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9; |
| 151 | |
| 152 | if (data.IsPressed(kPanelSwitch)) { |
| 153 | switch_ball_ = false; |
| 154 | } else if (data.IsPressed(kCargoSwitch)) { |
| 155 | switch_ball_ = true; |
| 156 | } |
| 157 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 158 | // TODO(sabina): max height please? |
Austin Schuh | 77ac321 | 2019-02-19 16:50:14 -0800 | [diff] [blame] | 159 | if (data.IsPressed(kFallOver)) { |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 160 | new_superstructure_goal->stilts.unsafe_goal = 0.71; |
Michael Schuh | 587dcb5 | 2019-02-28 21:31:03 -0800 | [diff] [blame] | 161 | new_superstructure_goal->stilts.profile_params.max_velocity = 0.65; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 162 | new_superstructure_goal->stilts.profile_params.max_acceleration = 2.0; |
Austin Schuh | 77ac321 | 2019-02-19 16:50:14 -0800 | [diff] [blame] | 163 | } else if (data.IsPressed(kDeployStilt)) { |
| 164 | new_superstructure_goal->stilts.unsafe_goal = 0.50; |
Michael Schuh | 587dcb5 | 2019-02-28 21:31:03 -0800 | [diff] [blame] | 165 | new_superstructure_goal->stilts.profile_params.max_velocity = 0.65; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 166 | if (stilts_was_above_) { |
| 167 | new_superstructure_goal->stilts.profile_params.max_acceleration = 0.75; |
| 168 | } else { |
| 169 | new_superstructure_goal->stilts.profile_params.max_acceleration = 2.0; |
| 170 | } |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 171 | } else { |
Austin Schuh | 2cf16b8 | 2019-02-15 23:23:22 -0800 | [diff] [blame] | 172 | new_superstructure_goal->stilts.unsafe_goal = 0.01; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 173 | new_superstructure_goal->stilts.profile_params.max_velocity = 0.25; |
| 174 | new_superstructure_goal->stilts.profile_params.max_acceleration = 2.0; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 177 | if (superstructure_queue.status->stilts.position > 0.65) { |
| 178 | stilts_was_above_ = true; |
| 179 | } else if (superstructure_queue.status->stilts.position < 0.1) { |
| 180 | stilts_was_above_ = false; |
Austin Schuh | 2cf16b8 | 2019-02-15 23:23:22 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 183 | if (switch_ball_) { |
| 184 | if (superstructure_queue.status->has_piece) { |
| 185 | new_superstructure_goal->wrist.profile_params.max_acceleration = 20; |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 186 | } |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 187 | |
| 188 | // Go to intake position and apply vacuum |
| 189 | if (data.IsPressed(kBallHPIntakeForward)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 190 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 191 | elevator_wrist_pos_ = kBallHPIntakeForwardPos; |
| 192 | } else if (data.IsPressed(kBallHPIntakeBackward)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 193 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 194 | elevator_wrist_pos_ = kBallHPIntakeBackwardPos; |
| 195 | } |
| 196 | |
| 197 | // Go to elevator/wrist position. Overrides intake position if pressed so |
| 198 | // we can re-grab the ball. |
| 199 | if (data.IsPressed(kRocketForwardLower)) { |
| 200 | elevator_wrist_pos_ = kBallForwardLowerPos; |
| 201 | } else if (data.IsPressed(kRocketBackwardLower)) { |
| 202 | elevator_wrist_pos_ = kBallBackwardLowerPos; |
| 203 | } else if (data.IsPressed(kRocketForwardMiddle)) { |
| 204 | elevator_wrist_pos_ = kBallForwardMiddlePos; |
| 205 | } else if (data.IsPressed(kRocketBackwardMiddle)) { |
| 206 | elevator_wrist_pos_ = kBallBackwardMiddlePos; |
| 207 | } else if (data.IsPressed(kRocketForwardUpper)) { |
| 208 | elevator_wrist_pos_ = kBallForwardUpperPos; |
| 209 | } else if (data.IsPressed(kRocketBackwardUpper)) { |
| 210 | elevator_wrist_pos_ = kBallBackwardUpperPos; |
| 211 | } else if (data.IsPressed(kCargoForward)) { |
| 212 | elevator_wrist_pos_ = kBallCargoForwardPos; |
| 213 | } else if (data.IsPressed(kCargoBackward)) { |
| 214 | elevator_wrist_pos_ = kBallCargoBackwardPos; |
| 215 | } |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 216 | } else { |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 217 | if (data.IsPressed(kPanelHPIntakeForward)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 218 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 219 | elevator_wrist_pos_ = kPanelHPIntakeForwrdPos; |
| 220 | } else if (data.IsPressed(kPanelHPIntakeBackward)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 221 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 222 | elevator_wrist_pos_ = kPanelHPIntakeBackwardPos; |
| 223 | } |
| 224 | |
| 225 | // Go to elevator/wrist position. Overrides intake position if pressed so |
| 226 | // we can re-grab the panel. |
| 227 | if (data.IsPressed(kRocketForwardLower)) { |
| 228 | elevator_wrist_pos_ = kPanelForwardLowerPos; |
| 229 | } else if (data.IsPressed(kRocketBackwardLower)) { |
| 230 | elevator_wrist_pos_ = kPanelBackwardLowerPos; |
| 231 | } else if (data.IsPressed(kRocketForwardMiddle)) { |
| 232 | elevator_wrist_pos_ = kPanelForwardMiddlePos; |
| 233 | } else if (data.IsPressed(kRocketBackwardMiddle)) { |
| 234 | elevator_wrist_pos_ = kPanelBackwardMiddlePos; |
| 235 | } else if (data.IsPressed(kRocketForwardUpper)) { |
| 236 | elevator_wrist_pos_ = kPanelForwardUpperPos; |
| 237 | } else if (data.IsPressed(kRocketBackwardUpper)) { |
| 238 | elevator_wrist_pos_ = kPanelBackwardUpperPos; |
Sabina Davis | e6fe6c5 | 2019-03-03 15:48:51 -0800 | [diff] [blame] | 239 | } else if (data.IsPressed(kCargoForward)) { |
| 240 | elevator_wrist_pos_ = kPanelCargoForwardPos; |
| 241 | } else if (data.IsPressed(kCargoBackward)) { |
| 242 | elevator_wrist_pos_ = kPanelCargoBackwardPos; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 243 | } |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 246 | if (switch_ball_) { |
| 247 | if (kDoBallOutake || |
| 248 | (kDoBallIntake && !superstructure_queue.status->has_piece)) { |
| 249 | new_superstructure_goal->intake.unsafe_goal = 0.959327; |
| 250 | } |
Austin Schuh | 23a5163 | 2019-02-19 16:50:36 -0800 | [diff] [blame] | 251 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 252 | if (kDoBallIntake && !superstructure_queue.status->has_piece) { |
| 253 | elevator_wrist_pos_ = kBallIntakePos; |
| 254 | new_superstructure_goal->roller_voltage = 9.0; |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 255 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 256 | } else { |
| 257 | if (kDoBallOutake) { |
| 258 | new_superstructure_goal->roller_voltage = -6.0; |
| 259 | } else { |
| 260 | new_superstructure_goal->intake.unsafe_goal = -1.2; |
| 261 | new_superstructure_goal->roller_voltage = 0.0; |
| 262 | } |
| 263 | } |
Austin Schuh | 23a5163 | 2019-02-19 16:50:36 -0800 | [diff] [blame] | 264 | } |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 265 | |
| 266 | if (data.IsPressed(kRelease)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 267 | grab_piece_ = false; |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 268 | } |
| 269 | |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 270 | if (switch_ball_) { |
| 271 | new_superstructure_goal->suction.gamepiece_mode = 0; |
| 272 | } else { |
| 273 | new_superstructure_goal->suction.gamepiece_mode = 1; |
| 274 | } |
| 275 | |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 276 | vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0); |
| 277 | |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 278 | new_superstructure_goal->suction.grab_piece = grab_piece_; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 279 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 280 | new_superstructure_goal->elevator.unsafe_goal = |
| 281 | elevator_wrist_pos_.elevator; |
| 282 | new_superstructure_goal->wrist.unsafe_goal = elevator_wrist_pos_.wrist; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 283 | |
| 284 | LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal); |
| 285 | if (!new_superstructure_goal.Send()) { |
| 286 | LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 287 | } |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 288 | |
| 289 | video_tx_->Send(vision_control_); |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | private: |
| 293 | // Current goals here. |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 294 | ElevatorWristPosition elevator_wrist_pos_ = kStowPos; |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 295 | bool grab_piece_ = false; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 296 | |
| 297 | bool switch_ball_ = false; |
| 298 | bool stilts_was_above_ = false; |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame^] | 299 | |
| 300 | VisionControl vision_control_; |
| 301 | ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | } // namespace joysticks |
| 305 | } // namespace input |
| 306 | } // namespace y2019 |
| 307 | |
| 308 | int main() { |
| 309 | ::aos::Init(-1); |
| 310 | ::aos::ShmEventLoop event_loop; |
| 311 | ::y2019::input::joysticks::Reader reader(&event_loop); |
| 312 | reader.Run(); |
| 313 | ::aos::Cleanup(); |
| 314 | } |