The code for the driving worked, but i ran into a problem when coding my actuator. I got the error: User code threw an uncaught exception: MissingFormatArgumentException - Format specifier '%7d". It may be because I used %7d for both drive motor telemetry and the actuator telemetry? This is my code for the actuator (I copy pasted my code for drive motors and edited it for 1 motor, the actuator). while (opModeIsActive() && (runtime.seconds() < timeoutS) && (actuator.isBusy())) { telemetry.addData("Path3","Running to %7d :%7d", newActuatorTarget); telemetry.addData("Path4","Running to %7d :%7d", actuator.getCurrentPosition()); telemetry.update(); } My whole code is below package org.firstinspires.ftc.teamcode; import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; import java.util.Set; import com.qualcomm.robotcore.util.ElapsedTime; import com.qualcomm.robotcore.eventloop.opmode.Autonomous; import com.qualcomm.robotcore.hardware.CRServo; import com.qualcomm.robotcore.hardware.Servo; import com.qualcomm.robotcore.hardware.DcMotor; import com.qualcomm.robotcore.hardware.DcMotorSimple; @Autonomous(name = "Autonomous Spice Meme", group = "") public class AutonomousMeme extends LinearOpMode { private ElapsedTime runtime = new ElapsedTime(); private DcMotor left_drive; private DcMotor right_drive; private DcMotor actuator; private CRServo intake; private Servo latch; private DcMotor pulley; static final double COUNTS_PER_MOTOR_REV = 1440; //counts per rotation for encoder static final double DRIVE_GEAR_REDUCTION = 1.0; static final double WHEEL_DIAMETER_INCHES = 4.0; static final double PI = 3.14159265359; static final double COUNTS_PER_INCH = (COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) / (WHEEL_DIAMETER_INCHES * PI); static final double DRIVE_SPEED = 1.0; static final double TURN_SPEED = 0.5; @Override public void runOpMode() { left_drive = hardwareMap.get(DcMotor.class, "left_drive"); right_drive = hardwareMap.get(DcMotor.class, "right_drive"); actuator = hardwareMap.get(DcMotor.class, "actuator"); intake = hardwareMap.get(CRServo.class, "intake"); latch = hardwareMap.get(Servo.class, "latch"); pulley = hardwareMap.get(DcMotor.class, "pulley"); telemetry.addData("Status", "Resetting Encoders" ); telemetry.update();
left_drive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); right_drive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); left_drive.setMode(DcMotor.RunMode.RUN_USING_ENCODER); right_drive.setMode(DcMotor.RunMode.RUN_USING_ENCODER); right_drive.setDirection(DcMotor.Direction.REVERSE); //wait for game to start (driver presses PLAY) waitForStart();
// Step through each leg of the path, // Note: Reverse movement is obtained by setting a negative distance (not speed) actuatorMovement(DRIVE_SPEED, 6.5, 4.0); //encoderDrive(DRIVE_SPEED, 48, 48, 5.0); /*encoderDrive(DRIVE_SPEED, 48, 48, 5.0); // Forward 48 inches with a 5 second timeout encoderDrive(TURN_SPEED, (PI/2), -(PI/2), 4.0); // Turn Right 12 inches with a 4 second timeout encoderDrive(DRIVE_SPEED, -24, -24, 4.0); // Reverse 24 inches with a 4 second timeout */ //latch.setPosition(0.45); //sleep(1000);
//Stop all motion left_drive.setPower(0); right_drive.setPower(0); //Turn off RUN_TO_POSITION left_drive.setMode(DcMotor.RunMode.RUN_USING_ENCODER); right_drive.setMode(DcMotor.RunMode.RUN_USING_ENCODER); // sleep(250); //optional pause after each move } }
public void actuatorMovement(double speed, double inches, double timeoutS){ int newActuatorTarget; if(opModeIsActive()) { newActuatorTarget = actuator.getCurrentPosition() + (int)(inches * COUNTS_PER_INCH); actuator.setTargetPosition(newActuatorTarget); actuator.setMode(DcMotor.RunMode.RUN_TO_POSITION); runtime.reset(); actuator.setPower(Math.abs(speed)); while (opModeIsActive() && (runtime.seconds() < timeoutS) && (actuator.isBusy())) { telemetry.addData("Path3","Running to %7d :%7d", newActuatorTarget); telemetry.addData("Path4","Running to %7d :%7d", actuator.getCurrentPosition()); telemetry.update(); }
//Stop all motion actuator.setPower(0); //Turn off RUN_TO_POSITION actuator.setMode(DcMotor.RunMode.RUN_USING_ENCODER); // sleep(250); //optional pause after each move } } }
Great videos! you guys did very well! do you have a copy of the code that integrate vuforia? We ahve this part pretty good, but are having a difficult time adding the vuforia code in the right sequence. We can read the pictograph but cant figure out how to sequence it properly after the jewel is knocked out.... Any help would be appreciated.
+Sebastien Cournoyer thank you! We don't have the code on our website or anywhere else yet. We will work on getting that on our website and post when it is up! Hope that helps!
+wing nuts if you have four independent motors you would just add in programming for the other two motors. And they would do the same for left side and right side. Hope that helps. There is lots of sample code on the web for different drive trains.
You da goat hope we can compete with/against you this year man
The code for the driving worked, but i ran into a problem when coding my actuator. I got the error: User code threw an uncaught exception: MissingFormatArgumentException - Format specifier '%7d". It may be because I used %7d for both drive motor telemetry and the actuator telemetry? This is my code for the actuator (I copy pasted my code for drive motors and edited it for 1 motor, the actuator).
while (opModeIsActive() &&
(runtime.seconds() < timeoutS) &&
(actuator.isBusy()))
{
telemetry.addData("Path3","Running to %7d :%7d", newActuatorTarget);
telemetry.addData("Path4","Running to %7d :%7d",
actuator.getCurrentPosition());
telemetry.update();
}
My whole code is below
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import java.util.Set;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
@Autonomous(name = "Autonomous Spice Meme", group = "")
public class AutonomousMeme extends LinearOpMode {
private ElapsedTime runtime = new ElapsedTime();
private DcMotor left_drive;
private DcMotor right_drive;
private DcMotor actuator;
private CRServo intake;
private Servo latch;
private DcMotor pulley;
static final double COUNTS_PER_MOTOR_REV = 1440; //counts per rotation for encoder
static final double DRIVE_GEAR_REDUCTION = 1.0;
static final double WHEEL_DIAMETER_INCHES = 4.0;
static final double PI = 3.14159265359;
static final double COUNTS_PER_INCH = (COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) / (WHEEL_DIAMETER_INCHES * PI);
static final double DRIVE_SPEED = 1.0;
static final double TURN_SPEED = 0.5;
@Override
public void runOpMode()
{
left_drive = hardwareMap.get(DcMotor.class, "left_drive");
right_drive = hardwareMap.get(DcMotor.class, "right_drive");
actuator = hardwareMap.get(DcMotor.class, "actuator");
intake = hardwareMap.get(CRServo.class, "intake");
latch = hardwareMap.get(Servo.class, "latch");
pulley = hardwareMap.get(DcMotor.class, "pulley");
telemetry.addData("Status", "Resetting Encoders" );
telemetry.update();
left_drive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
right_drive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
left_drive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
right_drive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
right_drive.setDirection(DcMotor.Direction.REVERSE);
//wait for game to start (driver presses PLAY)
waitForStart();
// Step through each leg of the path,
// Note: Reverse movement is obtained by setting a negative distance (not speed)
actuatorMovement(DRIVE_SPEED, 6.5, 4.0);
//encoderDrive(DRIVE_SPEED, 48, 48, 5.0);
/*encoderDrive(DRIVE_SPEED, 48, 48, 5.0); // Forward 48 inches with a 5 second timeout
encoderDrive(TURN_SPEED, (PI/2), -(PI/2), 4.0); // Turn Right 12 inches with a 4 second timeout
encoderDrive(DRIVE_SPEED, -24, -24, 4.0); // Reverse 24 inches with a 4 second timeout */
//latch.setPosition(0.45);
//sleep(1000);
telemetry.addData("Path", "Complete" );
telemetry.update();
}
public void encoderDrive(double speed, double leftInches, double rightInches, double timeoutS){
int newLeftTarget;
int newRightTarget;
if(opModeIsActive())
{
newLeftTarget = left_drive.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
newRightTarget = right_drive.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
left_drive.setTargetPosition(newLeftTarget);
right_drive.setTargetPosition(newRightTarget);
left_drive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
right_drive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
runtime.reset();
left_drive.setPower(Math.abs(speed));
right_drive.setPower(Math.abs(speed));
while (opModeIsActive() &&
(runtime.seconds() < timeoutS) &&
(left_drive.isBusy() && right_drive.isBusy()))
{
telemetry.addData("Path1","Running to %7d :%7d", newLeftTarget, newRightTarget);
telemetry.addData("Path2","Running to %7d :%7d",
left_drive.getCurrentPosition(),
right_drive.getCurrentPosition());
telemetry.update();
}
//Stop all motion
left_drive.setPower(0);
right_drive.setPower(0);
//Turn off RUN_TO_POSITION
left_drive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
right_drive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// sleep(250); //optional pause after each move
}
}
public void actuatorMovement(double speed, double inches, double timeoutS){
int newActuatorTarget;
if(opModeIsActive())
{
newActuatorTarget = actuator.getCurrentPosition() + (int)(inches * COUNTS_PER_INCH);
actuator.setTargetPosition(newActuatorTarget);
actuator.setMode(DcMotor.RunMode.RUN_TO_POSITION);
runtime.reset();
actuator.setPower(Math.abs(speed));
while (opModeIsActive() &&
(runtime.seconds() < timeoutS) &&
(actuator.isBusy()))
{
telemetry.addData("Path3","Running to %7d :%7d", newActuatorTarget);
telemetry.addData("Path4","Running to %7d :%7d",
actuator.getCurrentPosition());
telemetry.update();
}
//Stop all motion
actuator.setPower(0);
//Turn off RUN_TO_POSITION
actuator.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// sleep(250); //optional pause after each move
}
}
}
Great videos! you guys did very well! do you have a copy of the code that integrate vuforia? We ahve this part pretty good, but are having a difficult time adding the vuforia code in the right sequence. We can read the pictograph but cant figure out how to sequence it properly after the jewel is knocked out....
Any help would be appreciated.
+Sebastien Cournoyer thank you! We don't have the code on our website or anywhere else yet. We will work on getting that on our website and post when it is up! Hope that helps!
all set thank you
How would i program this for an omni drive system?
+wing nuts if you have four independent motors you would just add in programming for the other two motors. And they would do the same for left side and right side. Hope that helps. There is lots of sample code on the web for different drive trains.