-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added branch sensors * created a generic get distance method for sensors, called it in get left and right sensor distance, should be ready to merge to main * added branch sensors to Sensors file * made a method only called in branchsensors private --------- Co-authored-by: braelynandthefrogs <[email protected]> Co-authored-by: braelynandthefrogs <[email protected]>
- Loading branch information
1 parent
ce6fb59
commit 1e4e53a
Showing
3 changed files
with
61 additions
and
1 deletion.
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
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package frc.robot.sensors; | ||
|
||
import static edu.wpi.first.units.Units.Millimeter; | ||
|
||
import au.grapplerobotics.ConfigurationFailedException; | ||
import au.grapplerobotics.LaserCan; | ||
import edu.wpi.first.units.measure.Distance; | ||
import frc.robot.Hardware; | ||
|
||
public class BranchSensors { | ||
|
||
private final LaserCan leftSensor; | ||
private final LaserCan rightSensor; | ||
|
||
public BranchSensors() { | ||
leftSensor = new LaserCan(Hardware.BRANCH_SENSOR_LEFT); | ||
rightSensor = new LaserCan(Hardware.BRANCH_SENSOR_RIGHT); | ||
ConfigureSensor(leftSensor); | ||
ConfigureSensor(rightSensor); | ||
} | ||
|
||
private void ConfigureSensor(LaserCan Sensor) { | ||
try { | ||
Sensor.setRangingMode(LaserCan.RangingMode.SHORT); | ||
Sensor.setRegionOfInterest(new LaserCan.RegionOfInterest(8, 8, 16, 16)); | ||
Sensor.setTimingBudget(LaserCan.TimingBudget.TIMING_BUDGET_33MS); | ||
} catch (ConfigurationFailedException e) { | ||
System.out.println("Configuration Failed! " + e); | ||
} | ||
} | ||
|
||
private Distance getSensorDistance(LaserCan sensor) { | ||
LaserCan.Measurement measurement = sensor.getMeasurement(); | ||
if (measurement != null && measurement.status == LaserCan.LASERCAN_STATUS_VALID_MEASUREMENT) { | ||
return Millimeter.of(measurement.distance_mm); | ||
} else { | ||
return Millimeter.of(10000); | ||
} | ||
} | ||
|
||
public Distance getLeftSensorDistance() { | ||
return getSensorDistance(leftSensor); | ||
} | ||
|
||
public Distance getRightSensorDistance() { | ||
return getSensorDistance(rightSensor); | ||
} | ||
} |