Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into V2
  • Loading branch information
NoozAbooz committed Jan 5, 2025
2 parents 7544f78 + 6744447 commit 967aa6a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
4 changes: 3 additions & 1 deletion include/libKS/drivetrain/odom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ namespace ks
extern Position odom_pos;

extern void odomThread();
extern void resetOdomPosition();
extern void setOdomPosition(double x_new, double y_new, double theta_new);
extern void initializeOdom();
extern pros::Task odom_task;
}
35 changes: 17 additions & 18 deletions src/auton/autonomous.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ void testBM() {
chassis.moveToPose(52, 6, 320, 1000, {.forwards = false});
}

rd::Selector gui_selector({
{"E 5 Ring", Five_Ring},
{"Q 4 Ring + Bar", four_ring_bar},
{"Q SAWP 2 Mogo", SAWP_4},
{"Skills", skills},
});
void autonomous() {
//initializeColourSort();
chassis.setPose(0, 0, 0);
field_status = "autonomous";
console.println("Running auton...");
gui_selector.run_auton();
}


/* Legacy Auton Routines */
void four_ring_bar() {
if (alliance == "red" || alliance == "na") {
wallStake.move_voltage(10000); // Start
Expand Down Expand Up @@ -322,21 +338,4 @@ void skills() {
pros::delay(100);
intake.move_voltage(12000);
pros::delay(500);
}

rd::Selector gui_selector({
{"E 5 Ring", Five_Ring},
{"Q 4 Ring + Bar", four_ring_bar},
{"Q SAWP 2 Mogo", SAWP_4},
{"Skills", skills},
});
void autonomous() {
//initializeColourSort();
chassis.setPose(0, 0, 0);
field_status = "autonomous";
console.println("Running auton...");
gui_selector.run_auton();
}


/* Legacy Auton Routines */
}
5 changes: 1 addition & 4 deletions src/init/initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ void initialize() {
// pros::Task([] {
// chassis.calibrate();
// });

pros::Task([] {
ks::odomThread();
});
ks::initializeOdom();

optical.set_led_pwm(75); // enable led on optical sensor for accuracy
optical.set_integration_time(10); // refresh every 10ms
Expand Down
20 changes: 14 additions & 6 deletions src/libKS/drivetrain/odom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,28 @@ double avg_heading;
double deltaXLocal;
double deltaYLocal;

void ks::resetOdomPosition() {
x = 0;
y = 0;
void ks::initializeOdom() {
pros::Task odom_task(ks::odomThread);
}

void ks::setOdomPosition(double x_new = 0, double y_new = 0, double theta_new = 0) {
odom_task.suspend();
x = x_new;
y = y_new;

verticalEncoder.reset_position();
horizontalEncoder.reset_position();

vertical_pos = 0;
horizontal_pos = 0;

prev_vertical_pos = 0;
prev_horizontal_pos = 0;
prev_heading = 0;

inertial1.set_heading(0);
inertial2.set_heading(0);
inertial1.set_heading(theta_new);
inertial2.set_heading(theta_new);
odom_task.resume();
}

void ks::odomThread() {
Expand Down Expand Up @@ -141,7 +150,6 @@ void ks::odomThread() {
theta += 360;
}

// funky stuff for alliance colours :(
chassis.setPose(x, y, get_imu_rotation());
pros::delay(5);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void opcontrol() {

// Report temperature telemetry 😭
double drivetrainTemps = ks::vector_average(leftDrive.get_temperature_all());
controller.print(0, 0, "DT%.0lf|INT%.0lf|%.0lf ", drivetrainTemps, intake.get_temperature(), chassis.getPose().theta);
controller.print(0, 0, "DT%.0lf|INT%.0lf|%.0lf ", drivetrainTemps, intake.get_temperature(), ks::odom_pos.theta);
pros::delay(10); // Delay to save resources on brain
}
}

0 comments on commit 967aa6a

Please sign in to comment.