Skip to content

Commit

Permalink
Revert odom abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Oct 12, 2023
1 parent a8d3444 commit 6c9b02c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 30 deletions.
2 changes: 1 addition & 1 deletion include/lemlib/odom/arc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Arc : public Odom {
* @brief Calibrate the sensors used for odom
*
*/
void calibrate(int timeout = 3000) override;
void calibrate() override;
/**
* @brief Update te position of odom
*
Expand Down
2 changes: 1 addition & 1 deletion include/lemlib/odom/odom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Odom {
* @brief Calibrate the sensors used for odom
*
*/
virtual void calibrate(int timeout = 3000) = 0;
virtual void calibrate() = 0;
/**
* @brief Update te position of odom
*
Expand Down
16 changes: 8 additions & 8 deletions include/lemlib/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ float angleError(float angle1, float angle2, bool radians = true);
*/
int sgn(float x);

/**
* @brief Return the average of a vector of numbers
*
* @param values
* @return float
*/
float avg(std::vector<float> values);

/**
* @brief Exponential moving average
*
Expand Down Expand Up @@ -115,12 +123,4 @@ Waypoint closestWaypoint(const std::vector<Waypoint>& waypoints, const Pose& tar
* multiple intersections, the first one will be returned
*/
Pose circleLineIntersect(Pose p1, Pose p2, Pose center, float radius);

/**
* @brief Check errno to see if a pros function has failed
*
* @return true errno indicates failure
* @return false errno does not indicate failure
*/
bool checkErrno();
} // namespace lemlib
15 changes: 1 addition & 14 deletions src/lemlib/odom/arc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <errno.h>
#include "lemlib/util.hpp"
#include "lemlib/odom/arc.hpp"

/**
Expand All @@ -22,19 +20,8 @@ lemlib::Arc::Arc(std::vector<TrackingWheel>& verticals, std::vector<TrackingWhee
* to save time, we should calibrate all available imus at the same time. But we
* still need to remove them if they fail after 5 attempts
*/
void lemlib::Arc::calibrate(int timeout) {
void lemlib::Arc::calibrate() {
// calibrate tracking wheels
for (TrackingWheel& tracker : verticals) tracker.reset();
for (TrackingWheel& tracker : horizontals) tracker.reset();
for (pros::Imu& imu : imus) imu.reset();
std::vector<pros::Imu> newImus;
while (true) {
for (auto it = imus.begin(); it < imus.end(); it++) {
if (!it->is_calibrating() && checkErrno()) {
newImus.push_back(*it);
it = imus.erase(it);
}
}
pros::delay(10);
}
}
6 changes: 0 additions & 6 deletions src/lemlib/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @copyright Copyright (c) 2023
*
*/
#include <errno.h>
#include <math.h>
#include <vector>
#include <string.h>
Expand Down Expand Up @@ -208,8 +207,3 @@ lemlib::Pose lemlib::circleLineIntersect(Pose p1, Pose p2, Pose center, float ra
// no intersection found
return center;
}

/**
* Check errno to see if a device setup has failed
*/
bool checkErrno() { return errno == INT32_MAX || errno == ENODEV || errno == ENXIO; }

0 comments on commit 6c9b02c

Please sign in to comment.