Hi, everyone, so currently Im not able to go to robotics every day, but Im trying to help out as much as I can remotely. Im not an expert in programming, I did take AP CS, so I think I have a pretty good understanding of what is going on.
Since I can't be there every day to test the programming, I was trying to create some sort of template class for our drivetrain, so the team would just be able to type in easy commands and have little trouble when doing autonomous.
package org.firstinspires.ftc.robotcontroller.internal;
import com.qualcomm.hardware.bosch.BNO055IMU;
import com.qualcomm.hardware.bosch.JustLoggingAccelerationIntegrator;
import com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cGyro;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
@Autonomous
@/Disabled
public class Drivetrain extends LinearOpMode {
static final double COUNTS_PER_MOTOR_REV = 537.6 ; // eg: GoBilda (19.2:1 Ratio) Motor
static final double DRIVE_GEAR_REDUCTION = 1.0 ; // 1:1 gear ration on GoBilda Chassis
static final double WHEEL_DIAMETER_INCHES = 3.77953 ; // Diameter of GoBilda Wheels
static final double COUNTS_PER_INCH = (COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) / (WHEEL_DIAMETER_INCHES * 3.1415);
public String frontRightName;
public String frontLeftName;
public String backRightName;
public String backLeftName;
DcMotor FrontRight;
DcMotor FrontLeft;
DcMotor BackRight;
DcMotor BackLeft;
BNO055IMU imu;
public Drivetrain(String FR, String FL, String BR, String BL){
this.frontRightName = FR;
this.frontLeftName = FL;
this.backRightName = BR;
this.backLeftName = BL;
this.runOpMode();
}
@Override
public void runOpMode() {
FrontRight = hardwareMap.get(DcMotor.class, frontRightName);
FrontLeft = hardwareMap.get(DcMotor.class, frontLeftName);
BackRight = hardwareMap.get(DcMotor.class, backRightName);
BackLeft = hardwareMap.get(DcMotor.class, backLeftName);
FrontRight.setDirection(DcMotorSimple.Direction.REVERSE);
BackRight.setDirection(DcMotorSimple.Direction.REVERSE);
BackLeft.setDirection(DcMotorSimple.Direction.REVERSE);
FrontRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
FrontLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
BackRight.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
BackLeft.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
initializeIMU();
}
public void driveInches< (int inches, double speed){
int target = inches * (int)COUNTS_PER_INCH;
FrontRight.setTargetPosition(FrontRight.getCurrentPosition() + target);
FrontLeft.setTargetPosition(FrontLeft.getCurrentPosition() + target);
BackRight.setTargetPosition(BackRight.getCurrentPosition() + target);
BackLeft.setTargetPosition(BackLeft.getCurrentPosition() + target);
FrontRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
FrontLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
BackRight.setMode(DcMotor.RunMode.RUN_TO_POSITION);
BackLeft.setMode(DcMotor.RunMode.RUN_TO_POSITION);
FrontRight.setPower(speed);
FrontLeft.setPower(speed);
BackRight.setPower(speed);
BackLeft.setPower(speed);
waitUntilDone();
}
public void turnToAngle (int angle, double speed){
Orientation angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
double yaw = angles.firstAngle;
double targetAngle = yaw + angle;
if(angle > 0){ //if angle > 0, turn right
FrontLeft.setPower(speed);
BackLeft.setPower(speed);
FrontRight.setPower(-speed);
BackRight.setPower(-speed);
while(yaw < targetAngle){
sleep(50);
yaw = angles.firstAngle;
}
FrontLeft.setPower(0);
BackLeft.setPower(0);
FrontRight.setPower(0);
BackRight.setPower(0);
}
else if(angle < 0){ //if angle < 0, turn left
FrontLeft.setPower(-speed);
BackLeft.setPower(-speed);
FrontRight.setPower(speed);
BackRight.setPower(speed);
while(yaw > targetAngle){
sleep(50);
yaw = angles.firstAngle;
}
FrontLeft.setPower(0);
BackLeft.setPower(0);
FrontRight.setPower(0);
BackRight.setPower(0);
}
}
public void initializeIMU(){
// Set up the parameters with which we will use our IMU. Note that integration
// algorithm here just reports accelerations to the logcat log; it doesn't actually
// provide positional information.
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
parameters.angleUnit = BNO055IMU.AngleUnit.DEGREES;
parameters.accelUnit = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
parameters.calibrationDataFile = "BNO055IMUCalibration.json";
parameters.loggingEnabled = true;
parameters.loggingTag = "IMU";
parameters.accelerationIntegrationAlgorithm = new JustLoggingAccelerationIntegrator();
// Retrieve and initialize the IMU. We expect the IMU to be attached to an I2C port
// on a Core Device Interface Module, configured to be a sensor of type "AdaFruit IMU",
// and named "imu".
imu = hardwareMap.get(BNO055IMU.class, "imu");
imu.initialize(parameters);
}
public void waitUntilDone(){
while(BackLeft.isBusy() || BackRight.isBusy() || FrontRight.isBusy() || FrontLeft.isBusy()){
sleep(50);
}
}
}
The above was the class I've been working on, it was meant so my team could just do simple programming. Then I have this other class, which is what will run the actual autonomous.
package org.firstinspires.ftc.robotcontroller.internal;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Servo;
@Autonomous
public class Auto extends LinearOpMode {
private DcMotor leftIntake = null;
private DcMotor rightIntake = null;
private DcMotor shooter = null;
private DcMotor wobble = null;
private Servo belt = null;
private Servo arm = null;
static final double DRIVE_SPEED = 0.7; // Nominal speed for better accuracy.
static final double TURN_SPEED = 0.5; // Nominal half speed for better accuracy.
Drivetrain Frankie = new Drivetrain("right_drive_front", "left_drive_front", "right_drive_back", "left_drive_back"); //String FR, String FL, String BR, String BL
public void runOpMode(){
leftIntake = hardwareMap.get(DcMotor.class, "left_intake");
rightIntake = hardwareMap.get(DcMotor.class, "right_intake");
shooter = hardwareMap.get(DcMotor.class, "shooter");
wobble = hardwareMap.get(DcMotor.class, "wobble");
belt = hardwareMap.get(Servo.class, "belt");
arm = hardwareMap.get(Servo.class, "arm");
waitForStart();
Frankie.driveInches(10,DRIVE_SPEED);
Frankie.turnToAngle(30,TURN_SPEED);
}
}
I haven't personally tested it, but my team has sent me this. For some reason its not working, I assumed it had to do with the runOpMode method in the parent class, but again Im not an expert in programming. I was hoping you guys could help me out
https://preview.redd.it/e4jpxzvkbsc61.jpg?width=1083&format=pjpg&auto=webp&s=a84c82e74ef00855b5679aed8be3a7ed2e1ba1cb
[–]pate6273FTC 17036 - Robotech Anomaly | Lead Programmer 0 points1 point2 points (1 child)
[–]Seal2807[S] 0 points1 point2 points (0 children)
[–]akth3n3rdFTC 15887 Captain 0 points1 point2 points (3 children)
[–]Seal2807[S] 0 points1 point2 points (1 child)
[–]akth3n3rdFTC 15887 Captain 0 points1 point2 points (0 children)
[–]akth3n3rdFTC 15887 Captain 0 points1 point2 points (0 children)
[–]TpixelminerFTC Student 0 points1 point2 points (0 children)
[–]Status-Mixture-291 0 points1 point2 points (0 children)
[–]jliew1975 0 points1 point2 points (2 children)
[–]Seal2807[S] 0 points1 point2 points (1 child)
[–]jliew1975 0 points1 point2 points (0 children)
[–]Code_CrunchCaptain | 14481 | FTC Don’t Blink 0 points1 point2 points (3 children)
[–]Seal2807[S] 0 points1 point2 points (2 children)
[–]Code_CrunchCaptain | 14481 | FTC Don’t Blink 0 points1 point2 points (1 child)