Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mitocandria implementation #39

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": []
}