Asking again because latest I can find online is from 2016. Our autonomous OpModes (linear) implement a list of commands defined in RobotHardware class. Each of these methods implement a loop with check of opModeIsActive() to perform the function (move, turn, raise arm, etc.), most using PID controllers. What are folks doing inside these loops to allow the robot state to change incrementally until the next iteration? Calling idle()? Calling sleep(100)? Doing nothing? Do calls to opmodeIsActive() still incorporate a call to idle()? We are using Java in Android Studio.
It’s difficult to completely understand and answer your question. Can you provide a link (or github repo) for the code in question?
Here is an exemplary method:
/**
* Drive forward (reverse) while maintaining current heading and limiting sideways drift.
* This method should only be called from a LinerOpMode and implements its own loop to cover the robot's motion to the specified position.
* @param distance Distance (MM) to move: + is forward, - is reverse
* @param speed Speed factor to apply (should use defined constants)
*/
public void forward(double distance, double speed) {
// Proportional controllers for x, y, and yaw
PController xController = new PController(distance, X_POSITION_TOLERANCE, X_CONTROLLER_DEADBAND, X_CONTROLLER_KP);
//PController yController = new PController(0.0, Y_POSITION_TOLERANCE, Y_CONTROLLER_DEADBAND, Y_CONTROLLER_KP);
//PController yawController = new PController(0.0, HEADING_TOLERANCE, YAW_CONTROLLER_DEADBAND, YAW_CONTROLLER_KP);
// Flag to determine if called from a Liner OpMode
boolean isLinearOpMode = myOpMode instanceof LinearOpMode;
// reset the odometry counters to zero
resetOdometryCounters();
// Loop until the robot has reached the desired position
while (!xController.isWithinTolerance(xOdometryCounter) && (!isLinearOpMode || ((LinearOpMode) myOpMode).opModeIsActive())) {
// Calculate the control output for each of the three controllers
double xPower = clip(xController.calculate(xOdometryCounter), -1.0, 1.0);
//double yPower = clip(yController.calculate(yOdometryCounter), -1.0, 1.0);
double yPower = 0;
//double yawPower = clip(yawController.calculate(headingOdometryCounter), -1.0, 1.0);
double yawPower = 0;
// Move the robot based on the calculated powers
move(xPower, yPower, yawPower, speed);
// If we are in a linear opmode, sleep for a short time to allow the robot to move
// and/or for the encoder wheels to update their position.
// NOTE: Need to look into what's needed/efficient here: sleep(), idle(), or nothing
if (isLinearOpMode) {
//((LinearOpMode) myOpMode).sleep(50);
((LinearOpMode) myOpMode).idle();
}
// Update the odometry counters
updateOdometry();
}
// stop movement of the robot
stop();
}
In this version, the PID controllers were replaced with proportional-only controllers, the P controllers for the non-targeted axises of movement were commented out, and the sleep(50) was replaced with an idle() call, all in attempts to figure out how to improve accuracy going into last Saturday’s competition. Now I am trying to work through each issue individually to restore an optimized approach and gain speed while not sacrificing accuracy in the odometry.