From f7d7997aac71fd125dea5753ccfb899905469924 Mon Sep 17 00:00:00 2001 From: Hankang Zhou <136044263+nobody-particular@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:58:47 -0700 Subject: [PATCH 1/4] Added driver --- .../ftc/UltrasonicDistanceSensor.java | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/swerverobotics/ftc/UltrasonicDistanceSensor.java b/src/main/java/org/swerverobotics/ftc/UltrasonicDistanceSensor.java index 9a79e79..7f8305d 100644 --- a/src/main/java/org/swerverobotics/ftc/UltrasonicDistanceSensor.java +++ b/src/main/java/org/swerverobotics/ftc/UltrasonicDistanceSensor.java @@ -1,5 +1,45 @@ package org.swerverobotics.ftc; -public class UltrasonicDistanceSensor { +import com.qualcomm.robotcore.hardware.I2cAddr; +import com.qualcomm.robotcore.hardware.I2cDeviceSynchDevice; +import com.qualcomm.robotcore.hardware.I2cDeviceSynchSimple; +import com.qualcomm.robotcore.hardware.configuration.annotations.DeviceProperties; +import com.qualcomm.robotcore.hardware.configuration.annotations.I2cDeviceType; -} \ No newline at end of file +import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit; + +@I2cDeviceType() +@DeviceProperties(name = "SparkFun Ultrasonic Distance Sensor", description = "QWIIC Ultrasonic Distance Sensor TCT40", xmlTag = "QWIIC_ULTRASONIC_DISTANCE_SENSOR") +public class UltrasonicDistanceSensor extends I2cDeviceSynchDevice { + final int TRIGGER_AND_READ_REGISTER = 0x01; + + public double getDistance(DistanceUnit distanceUnit) { + byte[] rawData = deviceClient.read(TRIGGER_AND_READ_REGISTER, 2); + int distance = ((rawData[0] & 0xff) << 8) | (rawData[1] & 0xff); + return distanceUnit.fromUnit(DistanceUnit.MM, distance); + } + + @Override + protected boolean doInitialize() { + return true; + } + + @Override + public Manufacturer getManufacturer() { + return Manufacturer.SparkFun; + } + + @Override + public String getDeviceName() { + return "SparkFun Ultrasonic Distance Sensor"; + } + + private final static I2cAddr ADDRESS_I2C_DEFAULT = I2cAddr.create7bit(0x2F); + + public UltrasonicDistanceSensor(I2cDeviceSynchSimple deviceClient, boolean deviceClientIsOwned) { + super(deviceClient, deviceClientIsOwned); + + this.deviceClient.setI2cAddress(ADDRESS_I2C_DEFAULT); + super.registerArmingStateCallback(false); + } +} From 182b225018bb5a145eeaef95ac5376af22f8185d Mon Sep 17 00:00:00 2001 From: Hankang Zhou <136044263+nobody-particular@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:35:35 -0700 Subject: [PATCH 2/4] Added description and instructions in README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e3f2f0e..a4e0b6d 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ # Header - -A description of the repository goes here. +This repository contains a driver for integrating the [SparkFun Ultrasonic Distance Sensor - TCT40 (Qwiic)](https://www.sparkfun.com/products/24805), an I2C device, into the FTC SDK. You may want to use this sensor because, as of 2024, the walls of the competition area are clear, and so a conventional laser distance sensor would not be able to detect the wall. # Installation: ## Step 1: -Put instructions here: +First, go to your `build.gradle` file and go to `repositories`. Add `maven { url "https://jitpack.io" }` as a repository. (If it's already there, don't do anything.) ```Java repositories { - + // Your other stuff here... + maven { url "https://jitpack.io" } } ``` ## Step 2: -Then more instructions here: +Then, go to `dependencies` in the same `build.gradle` file. Add `com.github.SwerveRobotics:UltrasonicDistanceSensor:0.0.1` as a dependency. ```Java dependencies { - + implementation 'com.github.SwerveRobotics:UltrasonicDistanceSensor:0.0.1' } ``` ## Step 3: -Last instructions here. +Now, you may type `import org.swerverobotics.ftc.UltrasonicDistanceSensor` in one of your Java class files to import the driver! From cb7ced2815a0839f7185f202974349b20e763639 Mon Sep 17 00:00:00 2001 From: Hankang Zhou <136044263+nobody-particular@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:36:36 -0700 Subject: [PATCH 3/4] Added comment --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a4e0b6d..104dbb5 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ repositories { Then, go to `dependencies` in the same `build.gradle` file. Add `com.github.SwerveRobotics:UltrasonicDistanceSensor:0.0.1` as a dependency. ```Java dependencies { + // Your other stuff here... implementation 'com.github.SwerveRobotics:UltrasonicDistanceSensor:0.0.1' } ``` From 1baeb7765095293942fa380715d81e2a7c8ad9f4 Mon Sep 17 00:00:00 2001 From: Hankang Zhou <136044263+nobody-particular@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:37:26 -0700 Subject: [PATCH 4/4] Added header --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 104dbb5..2322135 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Header +# Description: This repository contains a driver for integrating the [SparkFun Ultrasonic Distance Sensor - TCT40 (Qwiic)](https://www.sparkfun.com/products/24805), an I2C device, into the FTC SDK. You may want to use this sensor because, as of 2024, the walls of the competition area are clear, and so a conventional laser distance sensor would not be able to detect the wall. # Installation: