Skip to content

Commit

Permalink
moved to module directory
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPeled committed Jun 13, 2024
0 parents commit a1c5a9a
Show file tree
Hide file tree
Showing 16 changed files with 1,382 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apply from: '../build.common.gradle'
apply from: '../build.dependencies.gradle'

android {
namespace = 'com.danpeled.swerveftclib'

packagingOptions {
jniLibs.useLegacyPackaging true
}
}

dependencies {
implementation project(':FtcRobotController')
implementation 'org.ftclib.ftclib:core:2.0.1' // core
annotationProcessor files('lib/OpModeAnnotationProcessor.jar')
}
Empty file added consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.danpeled.swerveftclib;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.danpeled.swerveftclib.test", appContext.getPackageName());
}
}
4 changes: 4 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
123 changes: 123 additions & 0 deletions src/main/java/com/danpeled/swerveftclib/Swerve/SwerveCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.danpeled.swerveftclib.Swerve;

import com.danpeled.swerveftclib.util.BaseDrive;
import com.danpeled.swerveftclib.util.CommandUtil.CommandFor;
import com.danpeled.swerveftclib.util.Location;

import java.util.function.Supplier;

public class SwerveCommands {

/**
* Command to set the power of the swerve drive in an oriented manner.
*/
public static class SetPowerOriented extends CommandFor<SwerveDrive> {
private final Supplier<Double> m_supplierX, m_supplierY, m_supplierTurn;
private final boolean fieldOriented;

/**
* Constructs a new SetPowerOriented command.
*
* @param swerveDrive The swerve drive subsystem.
* @param supplierX The supplier for the X-axis power.
* @param supplierY The supplier for the Y-axis power.
* @param supplierTurn The supplier for the turning power.
* @param fieldOriented Whether the control is field-oriented.
*/
public SetPowerOriented(SwerveDrive swerveDrive, Supplier<Double> supplierX, Supplier<Double> supplierY, Supplier<Double> supplierTurn, boolean fieldOriented) {
super(swerveDrive);
this.fieldOriented = fieldOriented;
this.m_supplierTurn = supplierTurn;
this.m_supplierX = supplierX;
this.m_supplierY = supplierY;
}

/**
* Executes the command to set the power of the swerve drive based on supplier input.
*/
@Override
public void execute() {
double x = m_supplierX.get();
double y = m_supplierY.get();
double turn = m_supplierTurn.get();

if (Math.abs(x) < 0.1) x = 0;
if (Math.abs(y) < 0.1) y = 0;
if (Math.abs(turn) < 0.1) turn = 0;

subsystem.setPowerOriented(x, y, turn, fieldOriented);
}
}

/**
* Command to move the swerve drive to a specific location.
*/
public static class GoTo extends CommandFor<SwerveDrive> {
private final Location m_location;
private final BaseDrive.GotoSettings m_config;
private final Runnable m_midwayAction;

/**
* Constructs a new GoTo command.
*
* @param swerveDrive The swerve drive subsystem.
* @param location The target location to move to.
* @param config The configuration settings for the movement.
* @param midwayAction An optional action to perform midway through the movement.
*/
public GoTo(SwerveDrive swerveDrive, Location location, BaseDrive.GotoSettings config, Runnable midwayAction) {
super(swerveDrive);
this.m_location = location;
this.m_config = config;
this.m_midwayAction = midwayAction;
}

/**
* Constructs a new GoTo command without a midway action.
*
* @param swerveDrive The swerve drive subsystem.
* @param location The target location to move to.
* @param config The configuration settings for the movement.
*/
public GoTo(SwerveDrive swerveDrive, Location location, BaseDrive.GotoSettings config) {
this(swerveDrive, location, config, null);
}

/**
* Executes the command to move the swerve drive to the specified location.
*/
@Override
public void execute() {
subsystem.goToLocation(m_location, m_config, m_midwayAction);
}
}

/**
* Command to turn the swerve drive to a specific angle.
*/
public static class TurnTo extends CommandFor<SwerveDrive> {
private final double m_angle;
private final double m_power;

/**
* Constructs a new TurnTo command.
*
* @param swerveDrive The swerve drive subsystem.
* @param angle The target angle to turn to.
* @param power The power to apply while turning.
*/
public TurnTo(SwerveDrive swerveDrive, double angle, double power) {
super(swerveDrive);
this.m_angle = angle;
this.m_power = power;
}

/**
* Executes the command to turn the swerve drive to the specified angle.
*/
@Override
public void execute() {
subsystem.turnTo(m_angle, m_power);
}
}
}
Loading

0 comments on commit a1c5a9a

Please sign in to comment.