Skip to content

Commit

Permalink
did stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLottman committed Apr 27, 2023
1 parent 40e697a commit ae323d5
Show file tree
Hide file tree
Showing 7 changed files with 693 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package org.firstinspires.ftc.teamcode.myopmodes.opmodes;

import static org.firstinspires.ftc.teamcode.myopmodes.subsystems.ease_commands.inTT_dt;

import static java.lang.Math.PI;
import static java.lang.Math.round;
import static java.lang.Math.*;

import androidx.annotation.NonNull;

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.DcMotorEx;
import com.qualcomm.robotcore.hardware.DistanceSensor;
import com.qualcomm.robotcore.hardware.IMU;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.firstinspires.ftc.teamcode.myopmodes.outreach.reddit;

import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
// i used DcMotorEx class rather than DcMotor because setting a tolerance allows our code to be less jumpy
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.DigitalChannel;
import com.qualcomm.robotcore.hardware.IMU;
import com.qualcomm.robotcore.hardware.Servo;

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;
// idk the Gyroscope class you were using but it just doesnt exist in ftc, at least not where i looked
// maybe you meant GyroSensor???

/*
in this file i assume you want to have a dynamic ability to change height of the arm, as thats how the code originally appeared
assuming you only wanted a few (2 or more) predetermined positions this would be a whole lot easier, no tuning increment or tolerances,
and way easier to read code for you to understand
*/

@TeleOp
public class ArmTest2 extends LinearOpMode {
// i like to put anything i need to tune up here so some variables here may seem repetitive but its just neater
private DcMotorEx arm,leftmotor,rightmotor;
private Servo claw;
private IMU imu;
private DigitalChannel touch;
Orientation angles;
private double heading;
// max at 45
// min at 0 degrees
// below we can set out angles for max and min
int minAngle = 0;
int maxAngle = 45;
int tolerance = 5; // change how close we are to the target position before we ajust out target position
// based off of COUNTS_PER_MOTOR_REV var being low i kept the tolerance low,
// increase this if the code gets jumpy when holding dpad
int increment = 5; // how much we change each time the code is looped, this is different between motors,
// based off of COUNTS_PER_MOTOR_REV var being low i kept the increment low,
// increase it for more drastic changes decrease it for smaller changes when holding dpad

// just so you know in case you didnt realize you have to fill your own info in here, if you dont know ill rewrite it my way so its easier for you to understand, i already have it premade i just have to find it
// assuming you dont know your motors count per rotation its 28 * motor internal gear ratio assuming you use a hall effect motor
static final double COUNTS_PER_MOTOR_REV = 288;
static final double GEAR_REDUCTION = 2.7778;
static final double COUNTS_PER_GEAR_REV = COUNTS_PER_MOTOR_REV * GEAR_REDUCTION;
static final double COUNTS_PER_DEGREE = COUNTS_PER_GEAR_REV/360;

@Override
public void runOpMode() {
arm = hardwareMap.get(DcMotorEx.class, "arm");
imu = hardwareMap.get(IMU.class, "imu");
leftmotor = hardwareMap.get(DcMotorEx.class, "leftmotor");
rightmotor = hardwareMap.get(DcMotorEx.class, "rightmotor");
touch = hardwareMap.get(DigitalChannel.class, "touch");

// set our current position to 0
arm.setMode(DcMotorEx.RunMode.STOP_AND_RESET_ENCODER);
// tell it we are going to use encoders
arm.setMode(DcMotorEx.RunMode.RUN_USING_ENCODER);
// this just means if we set power to 0 the motor will short itself and attempt to stay in place with 0 power
arm.setZeroPowerBehavior(DcMotorEx.ZeroPowerBehavior.BRAKE);
// this value deter
arm.setTargetPositionTolerance(tolerance);
// tell the motor where to go
arm.setTargetPosition(0);
// tell the motor to go
arm.setMode(DcMotorEx.RunMode.RUN_TO_POSITION);

// here i convert the angle you gave above into a number that is representative of that angle on your motor
minAngle = (int)(COUNTS_PER_DEGREE*minAngle);
maxAngle = (int)(COUNTS_PER_DEGREE*maxAngle);

waitForStart();

//run until the end of the match (driver presses STOP)
while (opModeIsActive()) {
// how to get heading assuming hub is upside up, if not change firstAngle to second or third
angles = imu.getRobotOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
heading = angles.firstAngle;

arm.setPower(1); // you can set this to whatever needed, as long as its enough power to lift whatever you need youre good

// if our current position is close enough to our target position and a button is pressed we change our target
if (gamepad1.dpad_up && !arm.isBusy()) {
arm.setTargetPosition(arm.getCurrentPosition()+increment);
}
if (gamepad1.dpad_down && !arm.isBusy()) {
arm.setTargetPosition(arm.getCurrentPosition()-increment);
}

// if we are shooting for a target position outside our determined limits, set it back to the limit
if (arm.getTargetPosition() > maxAngle) {
arm.setTargetPosition(maxAngle);
} else if (arm.getTargetPosition() < minAngle) {
arm.setTargetPosition(minAngle);
}

// because this code loops in a while(opModeIsActive()) loop,
// i only need to tell it to go to its position at the end of the code
arm.setMode(DcMotorEx.RunMode.RUN_TO_POSITION);

// idk what you were using the touch button for
telemetry.addData("Arm Test", arm.getCurrentPosition());
telemetry.update();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.firstinspires.ftc.teamcode.myopmodes.outreach.vrs;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
/*
this code is an example of the DcMotorSimple class, it contains all the functions used in the class but getPower which just tells you the last setPower
if you run this in the sim or in real life youll realize the loop isnt perfect, thats because physics exists and we are using no sensors to correct for errors over time
*/
@Autonomous(name = "basic drivetrain using DcMotorSimple (no encoders)", group = "opmodes")
public class BasicDrivetrain extends LinearOpMode {
DcMotorSimple frontRight,frontLeft,backRight,backLeft;
@Override
public void runOpMode() {
// put initialization blocks here
frontRight = hardwareMap.get(DcMotorSimple.class, "frontRight");
frontLeft = hardwareMap.get(DcMotorSimple.class, "frontLeft");
backRight = hardwareMap.get(DcMotorSimple.class, "backRight");
backLeft = hardwareMap.get(DcMotorSimple.class, "backLeft");

frontRight.setDirection(DcMotorSimple.Direction.REVERSE);
backRight.setDirection(DcMotorSimple.Direction.REVERSE);

waitForStart();
// because we used a while loop it'll loop the circle
while (opModeIsActive()) {
// put run code here

// drive forward
frontRight.setPower(1);
frontLeft.setPower(1);
backRight.setPower(1);
backLeft.setPower(1);
sleep(2500);

// strafe left
frontRight.setPower(1);
frontLeft.setPower(-1);
backRight.setPower(-1);
backLeft.setPower(1);
sleep(1100);

// drive backward
frontRight.setPower(-1);
frontLeft.setPower(-1);
backRight.setPower(-1);
backLeft.setPower(-1);
sleep(2500);

// strafe right
frontRight.setPower(-1);
frontLeft.setPower(1);
backRight.setPower(1);
backLeft.setPower(-1);
sleep(1100);
}
}
}
Loading

0 comments on commit ae323d5

Please sign in to comment.