Hi all,
My team and I have been trying to create an Odometry-based program on VEXcode Pro V5 to track the absolute coordinate position of our robot, but we are running into multiple odd issues… After extensive debugging, all the variables (including deltaX and deltaY) up until xPos and yPos are functioning as intended in that they are appropriately changing values when we move the robot. However, xPos and yPos (which we intend to be storing the absolute coordinate position of the robot) seem to have multiple issues, as noted within the code below (#1: double/float variable types are not working; #2: unwanted reset occurring)…
If anyone has any ideas regarding how to resolve these issues, that would be much much appreciated!
#include "vex.h"
#include "autonfunctions.h"
// fields
double currentLeft;
double currentRight;
double previousLeft;
double previousRight;
double deltaL;
double deltaR;
double deltaX;
double deltaY;
double linearDistance;
double head;
double theta;
double lradius;
// constants
const double trackWidth = 4.625;
int getPos(double& xPos, double& yPos) {
while (true) {
// odometryWheelToInch is a constant global to all our program files... its value is (2.75 * M_PI) / 360
currentLeft = getLeftEncoderRotation() * odometryWheelToInch;
currentRight = -getRightEncoderRotation() * odometryWheelToInch;
deltaL = currentLeft - previousLeft;
deltaR = currentRight - previousRight;
theta = ((deltaR - deltaL) / trackWidth);
lradius = deltaL / theta;
linearDistance = 2 * (lradius + (trackWidth / 2)) * sin(theta / 2);
deltaX = linearDistance * cos(head + theta / 2);
deltaY = linearDistance * sin(head + theta / 2);
// Issue #1: When we change the type of these variables (tempX & tempY) to a double or float (as we intend to do),
// xPos and yPos no longer change (they always remain at 0).
// Issue #2: When tempX & tempY are integers as written below, xPos and yPos change when we move the robot; however, with this, (1) all
// precision is lost, and (2) xPos and yPos reset to zeroes when the robot stops moving. These values should never
// reset--they should always store the absolute coordinate position of the robot on the field.
int tempX = xPos;
int tempY = yPos;
head += theta;
xPos = tempX + deltaX; // We tried xPos += deltaX, but that didn't work for some reason;
// thus, we stored its original value in tempX (above) and used that... Same for Y below...
yPos = tempY + deltaY;
previousLeft = currentLeft;
previousRight = currentRight;
wait(10, msec);
}
return 0;
}
void skills() {
double xPos = 0;
double yPos = 0;
getPos(xPos, yPos); // We intend to run this line as a thread so that it can update
// xPos & yPos (localized to this skills() function) as the program
// is running. We plan to reference xPos & yPos frequently in other functions
// throughout our program (by passing them in as parameters)
// in order to determine the robot's path of motion.
}
Thank you so very much!