purduesigbots / pros

Source code for PROS kernel: open source C/C++ development for the VEX V5 microcontroller
https://pros.cs.purdue.edu
Other
259 stars 76 forks source link

🚸 PROS 4: Update behavior of GPS to return a struct with offset, add get_position. #544

Closed WillXuCodes closed 1 year ago

WillXuCodes commented 1 year ago

Summary:

Updated behavior of GPS's get_offset to return a struct with offset, added a get_position while I was at it to return just the X and Y position.

Motivation:

Community pointed it out, I was always bothered by how we did this.

Test Plan:

WillXuCodes commented 1 year ago
void opcontrol() {
    pros::Controller master(pros::E_CONTROLLER_MASTER);

    pros::Motor left_mtr(1);
    pros::Motor right_mtr(2);
    printf("Initializing GPS\n");
    pros::Gps gps(11);
    DCHECKPOINT
    printf("GPS Initialized\n");
    pros::gps_position_s_t position;
    pros::gps_position_s_t offset;
    while (true) {
        // printf("Getting Position\n");
        DCHECKPOINT
        position = gps.get_position();
        DCHECKPOINT
        offset = gps.get_offset();
        DCHECKPOINT
        printf("Position: x: %.4lf %.4lf\n", position.x, position.y);
        printf("Offset: x: %.4lf %.4lf\n", offset.x, offset.y);
        int left = master.get_analog(ANALOG_LEFT_Y);
        int right = master.get_analog(ANALOG_RIGHT_Y);

        left_mtr = left;
        right_mtr = right;

        pros::delay(20);
    }
}

Works, outputs properly