Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #59 from rh-robotics/sadie-implementing-sensors
Browse files Browse the repository at this point in the history
Implementing Sensors
  • Loading branch information
sadie-datoo authored Dec 9, 2023
2 parents daf04cc + 95e831a commit c3de68e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ public class DistanceSensorTest extends OpMode {
private Hardware robot;
@Override
public void init() {
telemetry.addData("Distance Sensor", "Initializing");
robot = new Hardware(hardwareMap, telemetry);
robot.introduce(new HardwareElement<>(DistanceSensor.class, hardwareMap, "distanceSensor"));

telemetry.addData("Distance Sensor", "Initializing");
telemetry.addData("Distance Sensor", "Initialized");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package org.firstinspires.ftc.teamcode.auton;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.TouchSensor;

import org.firstinspires.ftc.teamcode.subsystems.hardware.Hardware;
import org.firstinspires.ftc.teamcode.subsystems.hardware.HardwareElement;

@Autonomous(name="Touch Sensor Test")

public class TouchSensorTest extends OpMode {
TouchSensor touch;
private Hardware robot;
boolean pressed;

@Override
public void init() {}
public void init() {
telemetry.addData("Touch Sensor", "Initializing");
robot = new Hardware(hardwareMap, telemetry);
robot.introduce(new HardwareElement<>(TouchSensor.class, hardwareMap, "touchSensor"));
telemetry.addData("Touch Sensor", "Initialized");
}

@Override
public void loop() {
touch = hardwareMap.touchSensor.get("touchSensor");
telemetry.addData("Touch Sensor", touch.isPressed());
pressed = robot.<TouchSensor>get("touchSensor").isPressed();
telemetry.addData("Touch Sensor Pressed", pressed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,33 @@
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.ColorSensor;

import org.firstinspires.ftc.teamcode.subsystems.hardware.Hardware;
import org.firstinspires.ftc.teamcode.subsystems.hardware.HardwareElement;

@Autonomous(name = "Color Sensor Test")

public class ColorSensorTest extends OpMode {
ColorSensor colorSensor;
int colorReading;
private Hardware robot;
int red;
int green;
int blue;

@Override
public void init() {
colorSensor = hardwareMap.colorSensor.get("color");
telemetry.addData("Color Sensor", "Initializing");
robot = new Hardware(hardwareMap, telemetry);
robot.introduce(new HardwareElement<>(ColorSensor.class, hardwareMap, "colorSensor"));
telemetry.addData("Color Sensor", "Initialized");
}

@Override
public void loop() {
//finds amount of red, green, blue, and light (alpha)
colorReading = colorSensor.argb();
telemetry.addData("Hue", colorReading);
telemetry.update();
// Finds amount of red, green, blue, and light (alpha).
red = robot.<ColorSensor>get("colorSensor").red();
green = robot.<ColorSensor>get("colorSensor").green();
blue = robot.<ColorSensor>get("colorSensor").blue();
telemetry.addData("Red", red);
telemetry.addData("Green", green);
telemetry.addData("Blue", blue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ private void initTouchSensor(HardwareElement<?> hardwareElement,

private void initColorSensor(HardwareElement<?> hardwareElement,
HashMap<String, String> initsHashMap) {
if (!initsHashMap.isEmpty()){
throw new RuntimeException("Color Sensor unnecessary initializers included");
}

ColorSensor deviceColorSensor = (ColorSensor) hardwareElement.device;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.firstinspires.ftc.teamcode.subsystems.hardware;

import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.ColorSensor;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.DistanceSensor;
Expand Down Expand Up @@ -69,6 +70,8 @@ private void setDefaultInitializers(Class<T> deviceType) {

} else if (deviceType.equals(DistanceSensor.class)) {

} else if (deviceType.equals(ColorSensor.class)) {

} else {
throw new RuntimeException(deviceType.getName() + " has not been " +
"implemented with default initializers.");
Expand Down

0 comments on commit c3de68e

Please sign in to comment.