From a05256c33747508a731e339b80aa34463a7bef3a Mon Sep 17 00:00:00 2001 From: ad101-lab <55064247+ad101-lab@users.noreply.github.com> Date: Mon, 25 Jul 2022 20:35:37 -0600 Subject: [PATCH] Fix build errors --- .../continuousOdometry/mecanumOdometry.hpp | 16 ++++++++-------- include/position/avgOdom.hpp | 9 +++++---- include/position/odomWheel.hpp | 8 ++++---- include/position/threeWireOdomWheel.hpp | 2 +- include/position/trackingWheel.hpp | 2 +- .../continuousOdometry/mecanumOdometry.cpp | 14 +++++++------- .../continuousOdometry/threeWheelOdom.cpp | 16 ++++++++-------- src/position/motorOdom.cpp | 2 +- src/utils/position.cpp | 4 ++-- src/utils/vector.cpp | 6 +++--- 10 files changed, 40 insertions(+), 39 deletions(-) diff --git a/include/odometry/continuousOdometry/mecanumOdometry.hpp b/include/odometry/continuousOdometry/mecanumOdometry.hpp index 8e436c7d..13265574 100644 --- a/include/odometry/continuousOdometry/mecanumOdometry.hpp +++ b/include/odometry/continuousOdometry/mecanumOdometry.hpp @@ -21,12 +21,12 @@ namespace Pronounce { pros::Imu* imu; - double xOffset; - double yOffset; + QLength xOffset; + QLength yOffset; public: MecanumOdometry(); - MecanumOdometry(double xOffset, double yOffset); - MecanumOdometry(OdomWheel* wheel1, OdomWheel* wheel2, OdomWheel* wheel3, OdomWheel* wheel4, pros::Imu* imu, double xOffset, double yOffset); + MecanumOdometry(QLength xOffset, QLength yOffset); + MecanumOdometry(OdomWheel* wheel1, OdomWheel* wheel2, OdomWheel* wheel3, OdomWheel* wheel4, pros::Imu* imu, QLength xOffset, QLength yOffset); void update(); @@ -45,7 +45,7 @@ namespace Pronounce { * * @param xOffset */ - void setXOffset(double xOffset) { + void setXOffset(QLength xOffset) { this->xOffset = xOffset; } @@ -54,7 +54,7 @@ namespace Pronounce { * * @return double */ - double getXOffset() { + QLength getXOffset() { return xOffset; } @@ -63,7 +63,7 @@ namespace Pronounce { * * @param yOffset */ - void setYOffset(double yOffset) { + void setYOffset(QLength yOffset) { this->yOffset = yOffset; } @@ -72,7 +72,7 @@ namespace Pronounce { * * @return double */ - double getYOffset() { + QLength getYOffset() { return yOffset; } diff --git a/include/position/avgOdom.hpp b/include/position/avgOdom.hpp index 69513f8e..faa13ea6 100644 --- a/include/position/avgOdom.hpp +++ b/include/position/avgOdom.hpp @@ -1,6 +1,7 @@ #pragma once #include "odomWheel.hpp" +#include "units/units.hpp" #include namespace Pronounce { @@ -22,8 +23,8 @@ namespace Pronounce { /** * Get the distance at the current moment */ - double getPosition() { - double total = 0; + QLength getPosition() { + QLength total = 0.0; for (int i = 0; i < odomWheels.size(); i++) { total += odomWheels.at(i).getPosition(); } @@ -38,8 +39,8 @@ namespace Pronounce { } } - double getChange() { - double total = 0; + QLength getChange() { + QLength total = 0.0; for (int i = 0; i < odomWheels.size(); i++) { total += odomWheels.at(i).getChange(); } diff --git a/include/position/odomWheel.hpp b/include/position/odomWheel.hpp index 2e97a41d..defb7056 100644 --- a/include/position/odomWheel.hpp +++ b/include/position/odomWheel.hpp @@ -11,8 +11,8 @@ namespace Pronounce { */ class OdomWheel { private: - QLength position = 0; - QLength lastPosition = 0; + QLength position = 0.0; + QLength lastPosition = 0.0; QLength radius; @@ -22,8 +22,8 @@ namespace Pronounce { OdomWheel(double radius); virtual void reset() { - position = 0; - lastPosition = 0; + position = 0.0; + lastPosition = 0.0; } QLength getRadius() { diff --git a/include/position/threeWireOdomWheel.hpp b/include/position/threeWireOdomWheel.hpp index fa3ba117..23dbfef7 100644 --- a/include/position/threeWireOdomWheel.hpp +++ b/include/position/threeWireOdomWheel.hpp @@ -12,7 +12,7 @@ namespace Pronounce { AdiOdomWheel(pros::ADIEncoder* encoder); void update() { - this->setPosition((encoder->get_value()/360.0) * this->getRadius() * M_PI * 2.0 * this->getTuningFactor()); + this->setPosition((encoder->get_value()/360.0) * this->getRadius().Convert(metre) * 1_pi * 2.0 * this->getTuningFactor()); } void reset() { diff --git a/include/position/trackingWheel.hpp b/include/position/trackingWheel.hpp index 532ad927..74a820a6 100644 --- a/include/position/trackingWheel.hpp +++ b/include/position/trackingWheel.hpp @@ -19,7 +19,7 @@ namespace Pronounce } void update() { - this->setPosition(((rotationSensor->get_position() / 100.0)/360.0) * this->getRadius() * M_PI * 2.0 * this->getTuningFactor()); + this->setPosition(((rotationSensor->get_position() / 100.0)/360.0) * this->getRadius().getValue() * 1_pi * 2.0 * this->getTuningFactor()); } ~TrackingWheel(); diff --git a/src/odometry/continuousOdometry/mecanumOdometry.cpp b/src/odometry/continuousOdometry/mecanumOdometry.cpp index 65f90069..4c585e9d 100644 --- a/src/odometry/continuousOdometry/mecanumOdometry.cpp +++ b/src/odometry/continuousOdometry/mecanumOdometry.cpp @@ -4,12 +4,12 @@ namespace Pronounce { MecanumOdometry::MecanumOdometry(/* args */) { } - MecanumOdometry::MecanumOdometry(double xOffset, double yOffset) { + MecanumOdometry::MecanumOdometry(QLength xOffset, QLength yOffset) { this->xOffset = xOffset; this->yOffset = yOffset; } - MecanumOdometry::MecanumOdometry(OdomWheel* wheel1, OdomWheel* wheel2, OdomWheel* wheel3, OdomWheel* wheel4, pros::Imu* imu, double xOffset, double yOffset) : MecanumOdometry(xOffset, yOffset) { + MecanumOdometry::MecanumOdometry(OdomWheel* wheel1, OdomWheel* wheel2, OdomWheel* wheel3, OdomWheel* wheel4, pros::Imu* imu, QLength xOffset, QLength yOffset) : MecanumOdometry(xOffset, yOffset) { this->wheel1 = wheel1; this->wheel2 = wheel2; this->wheel3 = wheel3; @@ -31,10 +31,10 @@ namespace Pronounce { Angle angleChange = 0.0; Angle lastAngle = lastPose->getAngle(); - double deltaWheel1 = wheel1->getChange(); - double deltaWheel2 = wheel2->getChange(); - double deltaWheel3 = wheel3->getChange(); - double deltaWheel4 = wheel4->getChange(); + QLength deltaWheel1 = wheel1->getChange(); + QLength deltaWheel2 = wheel2->getChange(); + QLength deltaWheel3 = wheel3->getChange(); + QLength deltaWheel4 = wheel4->getChange(); if (useImu && imu != nullptr) { if (imu->is_calibrating()) { @@ -52,7 +52,7 @@ namespace Pronounce { // Use the wheel encoders to determine orientation // Calculate the orientation since last reset - Angle currentAngle = (-wheel1->getPosition() + wheel2->getPosition() - wheel3->getPosition() + wheel4->getPosition()) / (4 * xOffset, yOffset); + Angle currentAngle = (-wheel1->getPosition() + wheel2->getPosition() - wheel3->getPosition() + wheel4->getPosition()).getValue() / (4 * xOffset, yOffset).getValue(); angleChange = currentAngle - lastAngle; diff --git a/src/odometry/continuousOdometry/threeWheelOdom.cpp b/src/odometry/continuousOdometry/threeWheelOdom.cpp index fba4b117..37931eb9 100644 --- a/src/odometry/continuousOdometry/threeWheelOdom.cpp +++ b/src/odometry/continuousOdometry/threeWheelOdom.cpp @@ -27,32 +27,32 @@ namespace Pronounce { backWheel->update(); // Get the current movement of odometry wheels - double deltaLeft = leftWheel->getChange(); - double deltaRight = rightWheel->getChange(); - double deltaBack = backWheel->getChange(); + QLength deltaLeft = leftWheel->getChange(); + QLength deltaRight = rightWheel->getChange(); + QLength deltaBack = backWheel->getChange(); // Get the last robot position Pose2D* lastPose = this->getPose(); // Calculate the change in orientation Angle lastAngle = lastPose->getAngle(); - Angle currentAngle = 0; + Angle currentAngle = 0.0; if (useImu && imu != nullptr) { currentAngle = toRadians(imu->get_rotation()); } else { - currentAngle = this->getResetPose()->getAngle().getValue() + (leftWheel->getPosition() - rightWheel->getPosition()) / (leftOffset + rightOffset); + currentAngle = this->getResetPose()->getAngle().getValue() + (leftWheel->getPosition() - rightWheel->getPosition()).getValue() / (leftOffset + rightOffset).getValue(); } - Angle deltaAngle = (deltaLeft - deltaRight) / (leftOffset + rightOffset); + Angle deltaAngle = (deltaLeft - deltaRight).getValue() / (leftOffset + rightOffset).getValue(); Angle averageOrientation = lastAngle + (deltaAngle / 2); Point localOffset; if (deltaAngle.Convert(radian) != 0.0) { double rotationAdjustment = 2 * sin(deltaAngle / 2); - localOffset = Point(((deltaBack/deltaAngle) + backOffset) * rotationAdjustment, ((deltaRight/deltaAngle) + rightOffset) * rotationAdjustment); + localOffset = Point(((deltaBack/deltaAngle).getValue() + backOffset.getValue()) * rotationAdjustment, ((deltaRight/deltaAngle).getValue() + rightOffset.getValue()) * rotationAdjustment); } else { // Calculate the local offset then translate it to the global offset localOffset = Point(deltaBack, deltaRight); @@ -66,7 +66,7 @@ namespace Pronounce { // Add localOffset to the global offset lastPose->add(localOffset); - lastPose->setAngle(fmod(angleDifference(currentAngle, 0) + M_PI * 2, M_PI * 2)); + lastPose->setAngle(fmod(angleDifference(currentAngle.Convert(radian), 0) + M_PI * 2, M_PI * 2)); if (Vector(&localOffset).getMagnitude() > maxMovement && maxMovement.Convert(metre) != 0.0) { return; diff --git a/src/position/motorOdom.cpp b/src/position/motorOdom.cpp index 857f9876..b4189454 100644 --- a/src/position/motorOdom.cpp +++ b/src/position/motorOdom.cpp @@ -10,6 +10,6 @@ namespace Pronounce { } void MotorOdom::update() { - this->setPosition(motor->get_position() * this->getRadius() * M_PI * 2.0 * this->getTuningFactor()); + this->setPosition(motor->get_position() * this->getRadius().Convert(metre) * 1_pi * 2.0 * this->getTuningFactor()); } } // namespace Pronounce diff --git a/src/utils/position.cpp b/src/utils/position.cpp index c11996ea..512fce24 100644 --- a/src/utils/position.cpp +++ b/src/utils/position.cpp @@ -2,7 +2,7 @@ namespace Pronounce { Pose2D::Pose2D() : Point() { - this->angle = 0; + this->angle = 0.0; } Pose2D::Pose2D(double angle) : Point() { @@ -10,7 +10,7 @@ namespace Pronounce { } Pose2D::Pose2D(double x, double y) : Point(x, y) { - this->angle = 0; + this->angle = 0.0; } Pose2D::Pose2D(double x, double y, double angle) : Point(x, y) { diff --git a/src/utils/vector.cpp b/src/utils/vector.cpp index 951e29da..db93c542 100644 --- a/src/utils/vector.cpp +++ b/src/utils/vector.cpp @@ -2,8 +2,8 @@ namespace Pronounce { Vector::Vector() { - this->magnitude = 0; - this->angle = 0; + this->magnitude = 0.0; + this->angle = 0.0; } Vector::Vector(QLength magnitude, Angle angle) { @@ -55,7 +55,7 @@ namespace Pronounce { Vector Vector::scale(double scalar) { Vector vector = Vector(*this); - vector.setMagnitude(vector.getMagnitude() * scalar); + vector.setMagnitude(vector.getMagnitude().getValue() * scalar); return vector; }