Skip to content

Commit

Permalink
Add odom resets
Browse files Browse the repository at this point in the history
  • Loading branch information
NoozAbooz committed Dec 17, 2024
1 parent e1c3131 commit 27314d3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 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;
}
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 27314d3

Please sign in to comment.