Useful Links







Welcome To Josh's Code Corner

Here I will give you any cool tips I know about programming

Here is the code for our robot, Centurion.
GitHub link
One of my favorite features of this year's robot is Automatic Tread Recalculation. This system checks the value of the current going to the motors and course-tunes the speeds sent to keep the bot going streight, and fine-tunes it more if it needs. Here is the code I have in the Drive Subsystem.

public void calculateReduction() {
//Make sure The Robot is not turning
if ( RobotMap.turning = false) {
//Get the speed of the motors
double leftSpeed = this.getLeft();
double rightSpeed = this.getRight();

//Add speed if they are both less than 99%
if (( leftSpeed < .99) && ( rightSpeed < .99)) {
RobotMap.leftDecrease= RobotMap.leftDecrease+.01;
RobotMap.rightDecrease= RobotMap.rightDecrease+.01;
}

//Corse tuning to 1% speed if left is faster
if (( leftSpeed - rightSpeed) > .01) {

//Decrease left if right is already max
if ( RobotMap.rightDecrease <= .09) {
RobotMap.leftDecrease = RobotMap.leftDecrease-.01;
}
//Increase Right if it is not
else {
RobotMap.rightDecrease = RobotMap.rightDecrease+.01;
}
}

//Corse tuning to 1% speed if right is faster
if (( rightSpeed - leftSpeed) > .01) {

//Decrease right if left is already max
if ( RobotMap.leftDecrease <= .09) {
RobotMap.rightDecrease = RobotMap.rightDecrease-.01;
}
//Increase left if it is not.
else {
RobotMap.leftDecrease = RobotMap.leftDecrease+.01;
}
}

//Fine tuning to .1% if left is faster
if (( leftSpeed - rightSpeed) > .001) {

//Same as above, just with a smaller speed
if ( RobotMap.rightDecrease == 1) {
RobotMap.leftDecrease = RobotMap.leftDecrease-.001;
}
else {
RobotMap.rightDecrease = RobotMap.rightDecrease+.001;
}
}

//Fine tuning to .1% if right is faster
if (( rightSpeed - leftSpeed) > .001) {

//Same as above, just with a smaller speed
if ( RobotMap.leftDecrease == 1) {
RobotMap.rightDecrease = RobotMap.rightDecrease-.001;
}
else {
RobotMap.leftDecrease = RobotMap.leftDecrease+.001;
}
}
}
}