-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nobody-particular/main
Added driver
- Loading branch information
Showing
2 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,23 +1,24 @@ | ||
# Header | ||
|
||
A description of the repository goes here. | ||
# 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: | ||
## 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 { | ||
|
||
// Your other stuff here... | ||
This comment has been minimized.
Sorry, something went wrong. |
||
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! |
44 changes: 42 additions & 2 deletions
44
src/main/java/org/swerverobotics/ftc/UltrasonicDistanceSensor.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 |
---|---|---|
@@ -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; | ||
|
||
} | ||
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<I2cDeviceSynchSimple> { | ||
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); | ||
} | ||
} |
It's actually com.github.SwerveRobotics:SparkFunUltrasonicDriver, not UltrasonicDistanceSensor.