-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40e697a
commit ae323d5
Showing
7 changed files
with
693 additions
and
5 deletions.
There are no files selected for viewing
6 changes: 1 addition & 5 deletions
6
TeamCode/src/org/firstinspires/ftc/teamcode/myopmodes/opmodes/ConvinceJess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
TeamCode/src/org/firstinspires/ftc/teamcode/myopmodes/outreach/reddit/ArmTest2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
TeamCode/src/org/firstinspires/ftc/teamcode/myopmodes/outreach/vrs/BasicDrivetrain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.