Skip to content

Commit

Permalink
Fix IMU getRotationDelta, fix Pose ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
SizzinSeal committed Nov 1, 2023
1 parent 170c6ec commit 4a78895
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions include/lemlib/chassis/chassis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class Chassis {

float prevDist = 0; // the previous distance travelled by the movement

std::unique_ptr<Odom> odom;
std::unique_ptr<Movement> movement;
std::unique_ptr<pros::Task> task;
std::unique_ptr<Odom> odom = nullptr;
std::unique_ptr<Movement> movement = nullptr;
std::unique_ptr<pros::Task> task = nullptr;
};
} // namespace lemlib
3 changes: 2 additions & 1 deletion include/lemlib/devices/gyro/gyro.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cstdint>
#include <math.h>

namespace lemlib {
class Gyro {
Expand Down Expand Up @@ -74,6 +75,6 @@ class Gyro {
*/
virtual std::uint8_t getPort() = 0;
protected:
float lastAngle = 0;
float lastAngle = M_PI_2;
};
} // namespace lemlib
4 changes: 3 additions & 1 deletion include/lemlib/odom/odom.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <math.h>
#include "lemlib/pose.hpp"

namespace lemlib {
Expand Down Expand Up @@ -30,6 +31,7 @@ class Odom {
*/
void setPose(Pose pose);
protected:
Pose pose = Pose(0, 0, 0);
// heading set to M_PI_2 because odom should default to IMU 0 angle
Pose pose = Pose(0, 0, M_PI_2);
};
} // namespace lemlib
6 changes: 3 additions & 3 deletions src/lemlib/devices/gyro/imu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool Imu::isCalibrating() const { return imu.is_calibrating(); }
*
* This function checks if the Imu is connected, is not calibrating,
*/
bool Imu::isCalibrated() { return (isConnected() && !imu.is_calibrating() && !std::isinf(imu.get_heading())); }
bool Imu::isCalibrated() { return isConnected() && !imu.is_calibrating() && !std::isinf(imu.get_heading()); }

/**
* return whether the IMU is installed
Expand All @@ -70,9 +70,9 @@ float Imu::getHeading() {
* Get the rotation of the imu in radians and in standard position
*/
float Imu::getRotation() {
const float rotation = imu.get_rotation();
const float rotation = M_PI_2 - degToRad(imu.get_rotation());
lastAngle = rotation;
return (M_PI - degToRad(imu.get_rotation()));
return rotation;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/lemlib/pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ namespace lemlib {
* @param y component
* @param theta heading. Defaults to 0
*/
Pose::Pose(float x, float y, float theta) {
x = x;
y = y;
theta = theta;
}
Pose::Pose(float x, float y, float theta)
:x(x),
y(y),
theta(theta)
{}

/**
* @brief Add a pose to this pose
Expand Down

0 comments on commit 4a78895

Please sign in to comment.