Skip to content

Commit

Permalink
Merge pull request #39 from WHS-FRC-3467/mitocandria-driver
Browse files Browse the repository at this point in the history
mitocandria implementation
  • Loading branch information
CJendantix authored Feb 8, 2025
2 parents 5a37a4d + 030bfb7 commit 46f2106
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/main/java/frc/robot/util/drivers/MitoCANdriaSensor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.util.drivers;

import au.grapplerobotics.MitoCANdria;

/** Add your docs here. */
public class MitoCANdriaSensor {

public MitoCANdriaSensor(int ID)
{
try (MitoCANdria mito = new MitoCANdria(ID)) {
// Get and print USB1 current
mito.getChannelCurrent(MitoCANdria.MITOCANDRIA_CHANNEL_USB1)
.ifPresentOrElse(
current -> System.out.println("USB1 current: " + current + " A"),
() -> System.out.println("Couldn't get USB1 current"));

// Get and print 5VA voltage
mito.getChannelVoltage(MitoCANdria.MITOCANDRIA_CHANNEL_5VA)
.ifPresentOrElse(
voltage -> System.out.println("5VA voltage: " + voltage + " V"),
() -> System.out.println("Couldn't get 5VA voltage"));

// Enable USB2 channel
mito.setChannelEnabled(MitoCANdria.MITOCANDRIA_CHANNEL_USB2, true);
System.out.println("USB2 channel enabled");

// Set ADJ channel voltage
mito.setChannelVoltage(MitoCANdria.MITOCANDRIA_CHANNEL_ADJ, 3.3);
System.out.println("ADJ channel voltage set to 3.3V");

// Get and print ADJ channel setpoint
mito.getChannelVoltageSetpoint(MitoCANdria.MITOCANDRIA_CHANNEL_ADJ)
.ifPresentOrElse(
setpoint -> System.out.println("ADJ channel setpoint: " + setpoint + " V"),
() -> System.out.println("Couldn't get ADJ channel setpoint"));

// Check if 5VB channel is enabled
mito.getChannelEnabled(MitoCANdria.MITOCANDRIA_CHANNEL_5VB)
.ifPresentOrElse(
enabled -> System.out.println("5VB channel enabled: " + (enabled == 1)),
() -> System.out.println("Couldn't check if 5VB channel is enabled"));

} catch (Exception e) {
System.out.println("An error occurred: " + e.getMessage());
}


}
}
20 changes: 20 additions & 0 deletions vendordeps/ThriftyLib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "ThriftyLib.json",
"name": "ThriftyLib",
"version": "2025.0.2",
"frcYear": "2025",
"uuid": "60b2694b-9e6e-4026-81ee-6f167946f4b0",
"mavenUrls": [
"https://docs.home.thethriftybot.com"
],
"jsonUrl": "https://docs.home.thethriftybot.com/ThriftyLib.json",
"javaDependencies": [
{
"groupId": "com.thethriftybot.frc",
"artifactId": "ThriftyLib-java",
"version": "2025.0.2"
}
],
"jniDependencies": [],
"cppDependencies": []
}

0 comments on commit 46f2106

Please sign in to comment.