Skip to content

Commit

Permalink
Merge pull request #2 from technototes/main
Browse files Browse the repository at this point in the history
keep up to date
  • Loading branch information
1toldyou authored Aug 13, 2022
2 parents ad78dde + 7a44a1b commit 4db7c9b
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.firstinspires.ftc.teachcode;



import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotorEx;

@TeleOp(name = "DemoOpMode")
public class DemoOpMode extends OpMode {

@Override
public void init() {

}

@Override
public void loop() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.Gamepad;
import com.qualcomm.robotcore.hardware.DcMotorSimple;

import org.firstinspires.ftc.teachcode.TankDrive;
import org.firstinspires.ftc.teachcode.TankDriveDemo;

@com.qualcomm.robotcore.eventloop.opmode.TeleOp(name = "TankCubed")

public class StickCubedTank extends OpMode {

private static final double DEAD_ZONE = 0.1;
private TankDrive tankDrive;
private TankDriveDemo tankDrive;
private DcMotorEx motorL;
private DcMotorEx motorR;

@Override
public void init() {
motorL = hardwareMap.get(DcMotorEx.class, "motorL");
motorR = hardwareMap.get(DcMotorEx.class, "motorR");
tankDrive = new TankDrive(motorL, motorR);
motorR.setDirection(DcMotorSimple.Direction.REVERSE);
tankDrive = new TankDriveDemo(motorL, motorR);
}

@Override
Expand All @@ -32,7 +33,7 @@ public void loop() {
tankDrive.motorLPower(0);
}
if (Math.abs(ry) > DEAD_ZONE) {
tankDrive.motorRPower(-ry * ry * ry);
tankDrive.motorRPower(ry * ry * ry);
} else {
tankDrive.motorRPower(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
import com.qualcomm.robotcore.hardware.Gamepad;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.hardware.TouchSensor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;

import org.firstinspires.ftc.teachcode.TankDriveDemo;
import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
import org.firstinspires.ftc.teachcode.TankDrive;

@com.qualcomm.robotcore.eventloop.opmode.TeleOp(name = "StickTankDrive")

public class StickTankDrive extends OpMode {
private static final double DEAD_ZONE = 0.1;
private TankDrive tankDrive;
private TankDriveDemo tankDrive;
private DcMotorEx motorL;
private DcMotorEx motorR;
private Servo servo;
Expand All @@ -29,7 +31,8 @@ public class StickTankDrive extends OpMode {
public void init() {
motorL = hardwareMap.get(DcMotorEx.class, "motorL");
motorR = hardwareMap.get(DcMotorEx.class, "motorR");
tankDrive = new TankDrive(motorL, motorR);
motorR.setDirection(DcMotorSimple.Direction.REVERSE);
tankDrive = new TankDriveDemo(motorL, motorR);
servo = hardwareMap.get(Servo.class, "gobilda");
toucha = hardwareMap.get(RevTouchSensor.class, "touch6");
touchb = hardwareMap.get(RevTouchSensor.class, "touch7");
Expand All @@ -48,7 +51,8 @@ public void loop() {
}
tankDrive.motorLPower(left);
if (Math.abs(gamepad1.right_stick_y) > DEAD_ZONE) {
right = -gamepad1.right_stick_y;
tankDrive.motorRPower(gamepad1.right_stick_y);
right = gamepad1.right_stick_y;
} else {
right = 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.firstinspires.ftc.teachcode.OpModes;

import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.Gamepad;

import org.firstinspires.ftc.teachcode.TankDriveDemo;

@com.qualcomm.robotcore.eventloop.opmode.TeleOp(name = "StickTankDriveForVideo")

public class StickTankDriveForVideo extends OpMode {

private static final double DEAD_ZONE = 0.1;
private TankDriveDemo tankDrive;
private DcMotorEx motorL;
private DcMotorEx motorR;

@Override
public void init() {
motorL = hardwareMap.get(DcMotorEx.class, "motorL");
motorR = hardwareMap.get(DcMotorEx.class, "motorR");
motorR.setDirection(DcMotorSimple.Direction.REVERSE);
tankDrive = new TankDriveDemo(motorL, motorR);
}

@Override
public void loop() {
if (Math.abs(gamepad1.left_stick_y) > DEAD_ZONE) {
tankDrive.motorLPower(gamepad1.left_stick_y);
} else {
tankDrive.motorLPower(0);
}
if (Math.abs(gamepad1.right_stick_y) > DEAD_ZONE) {
tankDrive.motorRPower(gamepad1.right_stick_y);
} else {
tankDrive.motorRPower(0);
}
}

@Override
public void start() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

import com.qualcomm.robotcore.hardware.DcMotorEx;

import java.util.*;

public class TankDrive {
private void sleep(int ms) {
try {
Thread.sleep(ms);
} catch (Exception e) {
}
}

public DcMotorEx motorL;
public DcMotorEx motorR;

Expand All @@ -20,34 +11,9 @@ public TankDrive(DcMotorEx motorL, DcMotorEx motorR) {
this.motorR = motorR;
}

// For non-stick control system
public void moveForwardButton(double power, int seconds) {
motorL.setPower(power);
motorR.setPower(power);
sleep(seconds * 1000);
pleaseStop();
}

// For non-stick control system
public void pleaseStop() {
motorL.setPower(0);
motorR.setPower(0);
}

// For non-stick control system
public void moveBackwardButton(double power, int seconds) {
motorL.setPower(-power);
motorR.setPower(-power);
sleep(seconds * 1000);
pleaseStop();
}

// For stick control system
public void motorLPower(double power) {
motorL.setPower(power);
}

// For stick control system
public void motorRPower(double power) {
motorR.setPower(power);
}
Expand All @@ -59,3 +25,4 @@ public DcMotorEx getMotorR() {
return motorR;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,32 @@

import com.qualcomm.robotcore.hardware.DcMotorEx;

import java.util.*;

public class TankDriveDemo {

public DcMotorEx motorL;
public DcMotorEx motorR;

public TankDriveDemo(DcMotorEx motorL, DcMotorEx motorR) {
this.motorL = motorL;
this.motorR = motorR;
}

// For stick control system
public void motorLPower(double power) {
motorL.setPower(power);
}

// For stick control system
public void motorRPower(double power) {
motorR.setPower(power);
}

public DcMotorEx getMotorL() {
return motorL;
}
public DcMotorEx getMotorR() {
return motorR;
}
}

0 comments on commit 4db7c9b

Please sign in to comment.