1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
controller.cpp
Go to the documentation of this file.
1#include "electronic/controller.h"
2#include "globals.h"
3#include "pros/misc.h"
4#include <cstdint>
5#include <string>
6
7using namespace Robot;
8using namespace Robot::Globals;
9
10void Controller::notifier() {
11
12 // No direct translation to morse code.
13 if (partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_Y)) {
14 controller.rumble("..-");
15 }
16 // Stands for "R" in morse code.
17 if (partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_X)) {
18 controller.rumble(".-.");
19 }
20 // No direct translation to morse code.
21 if (partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_UP)) {
22 controller.rumble("-..");
23 }
24 // Stands for "K" in morse code.
25 if (partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_RIGHT)) {
26 controller.rumble("-.-");
27 }
28
29 // Special rumble in order to notify of only 15 seconds remaining.
30 if (partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_R1)) {
31 controller.rumble("...");
32 }
33}
34
35void Controller::switchControl() {
36 // Dynamic controller switching - Switches which controller is main between the dual controllers
37 if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_LEFT) && partner.is_connected()) {
38 pros::Controller temp = controller;
39
41 partner = temp;
42
43 controller.print(0, 0, "Main Controller");
44
45 pros::delay(50);
46
47 partner.print(0, 0, "Partner Controller");
48 }
49}
50
51void Controller::notify_motor_disconnect(void *param) {
52 std::vector<pros::Motor> all_motors = pros::Motor::get_all_devices();
53 std::vector<unsigned char> disconnected;
54 std::vector<unsigned char> last_disconnected;
55 bool is_notified = false;
56 uint32_t now = pros::millis();
57
58 constexpr int TASK_DELAY_MILLIS = 1000;
59 constexpr int CONTROLLER_DELAY_MILLIS = 50;
60
61 while (true) {
62 std::string disc_motors = "MD: ";
63 bool are_motors_disconnected = false;
64
65 for (pros::Motor i : all_motors) {
66 if (!i.is_installed()) {
67 unsigned char port = i.get_port();
68 disconnected.push_back(port);
69 disc_motors = disc_motors + " " + std::to_string(port);
70 are_motors_disconnected = true;
71 }
72 }
73 // Controller screen commands must be delayed by 50ms due to polling limitations
74 if (are_motors_disconnected) {
75 controller.clear_line(0);
76 pros::delay(CONTROLLER_DELAY_MILLIS);
77 controller.set_text(0, 0, disc_motors);
78 is_notified = true;
79 pros::delay(CONTROLLER_DELAY_MILLIS);
80 }
81 if (disconnected.size() > last_disconnected.size()) {
82 controller.rumble(". . .");
83 } else if (disconnected.size() < last_disconnected.size()) {
84 controller.rumble("-");
85 } else if (!are_motors_disconnected && is_notified) {
86 controller.clear_line(0);
87 is_notified = false;
88 }
89 last_disconnected = disconnected;
90 disconnected.clear();
91 pros::Task::delay_until(&now, TASK_DELAY_MILLIS);
92 }
93}
94
95Controller::Controller() { ; }
pros::Controller controller(pros::E_CONTROLLER_MASTER)
pros::Controller partner(pros::E_CONTROLLER_PARTNER)
Definition auton.h:8