Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad code #22

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/pipelines/eocvsim_workspace.json
Binary file added TeamCode/.DS_Store
Binary file not shown.
Binary file added TeamCode/src/.DS_Store
Binary file not shown.
Binary file added TeamCode/src/main/.DS_Store
Binary file not shown.
Binary file added TeamCode/src/main/java/.DS_Store
Binary file not shown.
Binary file added TeamCode/src/main/java/org/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file modified TeamCode/src/main/java/org/firstinspires/ftc/.DS_Store
Binary file not shown.
Binary file not shown.
16 changes: 5 additions & 11 deletions TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ public class Camera
OpenCvWebcam camera;
colorDetection pipeline;

public Camera.State state;
public enum State
{
ONE,
TWO,
THREE
}
public Camera(HardwareMap hardwareMap, Telemetry telemetry)
{
int cameraMonitorViewId = hardwareMap.appContext.getResources().getIdentifier("cameraMonitorViewId", "id", hardwareMap.appContext.getPackageName());
Expand All @@ -44,12 +37,13 @@ public void onError(int errorCode)
}
});
}
public void update()

public OpenCvWebcam streamSource()
{
state=pipeline.getOutput();
return camera;
}
public Camera.State getState()
public int getState()
{
return state;
return pipeline.getOutput();
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package org.firstinspires.ftc.teamcode;

import com.acmerobotics.dashboard.FtcDashboard;
import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;

@TeleOp
public class CameraTest extends LinearOpMode

{
FtcDashboard dashboard;
TelemetryPacket packet;
Camera camera;

@Override
public void runOpMode() throws InterruptedException
{
packet=new TelemetryPacket();
dashboard=FtcDashboard.getInstance();

camera=new Camera(hardwareMap, telemetry);
dashboard.startCameraStream(camera.streamSource(),30);

waitForStart();
while(opModeIsActive())
{
camera.update();
telemetry.addData("Status:", camera.getState());
packet.put("Zone:", camera.getState());
dashboard.sendTelemetryPacket(packet);

telemetry.addData("Zone:", camera.getState());
telemetry.update();
}
}
Expand Down
51 changes: 0 additions & 51 deletions TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Claw.java

This file was deleted.

This file was deleted.

54 changes: 54 additions & 0 deletions TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Intake.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.firstinspires.ftc.teamcode;

import com.arcrobotics.ftclib.hardware.ServoEx;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;

public class Intake
{

CRServo intake1, intake2;
public Intake.State state;
public enum State
{
IN, OUT, OFF
}

public Intake(HardwareMap hardwareMap)
{
intake1=hardwareMap.get(CRServo.class, "intake1");
intake2=hardwareMap.get(CRServo.class, "intake2");

intake1.setDirection(DcMotorSimple.Direction.REVERSE);

setState(State.OFF);
}

public void update()
{
switch(state)
{
case IN:
intake1.setPower(1);
intake2.setPower(1);
case OUT:
intake1.setPower(-1);
intake2.setPower(-1);
case OFF:
intake1.setPower(0);
intake2.setPower(0);
}
}

public Intake.State getState() {
return state;
}

public void setState(Intake.State state)
{
this.state = state;
update();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
@TeleOp

public class IntakeTest extends LinearOpMode
{
Intake intake;

@Override
public void runOpMode() throws InterruptedException
{
intake=new Intake(hardwareMap);

waitForStart();

while(opModeIsActive())
{
if(gamepad1.a)
{
intake.setState(Intake.State.IN);
}
else if(gamepad1.b)
{
intake.setState(Intake.State.OUT);
}
else if(gamepad1.x)
{
intake.setState(Intake.State.OFF);
}
}
}
}
109 changes: 109 additions & 0 deletions TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Slides.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.DigitalChannel;
import com.qualcomm.robotcore.hardware.HardwareMap;

public class Slides {

DigitalChannel limitSwitch;
public DcMotorEx slidesLeft;
public DcMotorEx slidesRight;
//slides is 17.5 inches tall
static final double HIGH = 16; //in inches, 33.5 - 17.5 (high junction height - slides height)
static final double MID = 6; //in inches, 23.5 - 17.5 (mid junction height - slides height)
static final double LOW = 0; //in inches, low junction is 13.5 inches
static final double THRESHOLD=20;

public targetPos target;
public enum targetPos {
HIGH, MID, LOW
}

public State state;
public enum State
{
MOVING, STOPPED, RESETTING
}

public Slides(HardwareMap hardwareMap) {
slidesLeft = hardwareMap.get(DcMotorEx.class, "s1");
slidesRight = hardwareMap.get(DcMotorEx.class, "s2");
limitSwitch = hardwareMap.get(DigitalChannel.class, "limitSwitch");

//reverse a motor
limitSwitch.setMode(DigitalChannel.Mode.INPUT);
setTarget(targetPos.LOW);
}

public void update()
{
switch(state)
{
case MOVING:
slidesLeft.setPower(motorPower());
slidesRight.setPower(motorPower());
if(Math.abs(((slidesLeft.getCurrentPosition()+slidesRight.getCurrentPosition())/2)- targetTicks())<THRESHOLD)
{
state=State.STOPPED;
}
break;
case RESETTING:
slidesLeft.setPower(motorPower());
slidesRight.setPower(motorPower());
if(limitSwitch.getState()==true)
{
state=State.STOPPED;
}
break;
case STOPPED:
//maybe continue running motors w/ PID loop? Depends on if it can't stay in place
break;
}
}



private double targetTicks()
{
switch(target)
{
case HIGH:
return HIGH;
case MID:
return MID;
case LOW:
return LOW;
}
return LOW;
}
private double motorPower()
{
//use pid to determine w/ current and target position motor velocity
return 0.5;
}



public void setTarget(targetPos target)
{
this.target = target;
this.state=State.MOVING;
}
public void resetPos()
{
this.target=targetPos.LOW;
this.state=State.RESETTING;
}



public targetPos getTarget()
{
return target;
}
public Slides.State getState()
{
return state;
}
}
Loading