Skip to content
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
4 changes: 2 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android'
ext {
PUBLISH_GROUP_ID = 'com.arcrobotics'
PUBLISH_ARTIFACT_ID = 'ftclib'
PUBLISH_VERSION = '2.1.0'
PUBLISH_VERSION = '2.1.1'
}

android {
Expand All @@ -16,7 +16,7 @@ android {
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName 'v2.1.0'
versionName 'v2.1.1'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand Down
2 changes: 1 addition & 1 deletion core/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "2.1.0"
versionName "2.1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Set<Subsystem> getRequirements() {
}

public String getName() {
return this.getClass().getSimpleName();
return m_name;
}

public void setName(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* ----------------------------------------------------------------------------
* Copyright (c) 2018-2019 FIRST. All Rights Reserved.
* Open Source Software - may be modified and shared by FRC teams. The code
* must be accompanied by the FIRST BSD license file in the root directory of
* the project.
* ----------------------------------------------------------------------------
*/

package com.arcrobotics.ftclib.command;

import static com.arcrobotics.ftclib.command.CommandGroupBase.registerGroupedCommands;
import static com.arcrobotics.ftclib.command.CommandGroupBase.requireUngrouped;

/**
* A command that runs another command repeatedly, restarting it when it ends, until this command is
* interrupted. While this class does not extend {@link CommandGroupBase}, it is still considered a
* CommandGroup, as it allows one to compose another command within it; the command instances that
* are passed to it cannot be added to any other groups, or scheduled individually.
*
* <p>As a rule, CommandGroups require the union of the requirements of their component commands.
*
* @author Ryan
*/
public class RepeatCommand extends CommandBase{

protected final Command m_command;

/**
* Creates a new RepeatCommand. Will run another command repeatedly, restarting it whenever it
* ends, until this command is interrupted.
*
* @param command the command to run repeatedly
*/
public RepeatCommand(Command command) {
requireUngrouped(command);
registerGroupedCommands(command);
m_command = command;
m_requirements.addAll(command.getRequirements());
}


@Override
public void initialize() {
m_command.initialize();
}


@Override
public void execute() {
m_command.execute();
if (m_command.isFinished()) {
// restart command
m_command.end(false);
m_command.initialize();
}
}

@Override
public boolean isFinished() {
return false;
}

@Override
public void end(boolean interrupted) {
m_command.end(interrupted);
}

@Override
public boolean runsWhenDisabled() {
return m_command.runsWhenDisabled();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* ----------------------------------------------------------------------------
* Copyright (c) 2018-2019 FIRST. All Rights Reserved.
* Open Source Software - may be modified and shared by FRC teams. The code
* must be accompanied by the FIRST BSD license file in the root directory of
* the project.
* ----------------------------------------------------------------------------
*/

package com.arcrobotics.ftclib.command;

import com.arcrobotics.ftclib.trajectory.TrapezoidProfile;
import com.arcrobotics.ftclib.util.Timing;
import com.qualcomm.robotcore.util.ElapsedTime;


import java.util.function.Consumer;

/**
* A command that runs a {@link TrapezoidProfile}. Useful for smoothly controlling mechanism motion.
*
* @author Ryan
*/

public class TrapezoidProfileCommand extends CommandBase {

private final TrapezoidProfile m_profile;
private final Consumer<TrapezoidProfile.State> m_output;


private final ElapsedTime m_timer = new ElapsedTime();


/**
* Creates a new TrapezoidProfileCommand that will execute the given {@link TrapezoidProfile}.
* Output will be piped to the provided consumer function.
*
* @param profile The motion profile to execute.
* @param output The consumer for the profile output.
* @param requirements The subsystems required by this command.
*/
public TrapezoidProfileCommand(
TrapezoidProfile profile, Consumer<TrapezoidProfile.State> output, Subsystem... requirements){
m_profile = profile;
m_output = output;
addRequirements(requirements);
}


@Override
public void initialize(){
m_timer.reset();
}

@Override
public void execute() {
m_output.accept(m_profile.calculate(m_timer.seconds()));
}

@Override
public boolean isFinished() {
return m_timer.seconds() >= m_profile.totalTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class TriggerReader implements KeyReader {
* Current state of the button
**/
private boolean currState;

/**
* Current threshold
**/
private double threshold;

/**
* Initializes controller variables
Expand All @@ -23,15 +28,20 @@ public class TriggerReader implements KeyReader {
* @param trigger The controller button
**/
public TriggerReader(GamepadEx gamepad, GamepadKeys.Trigger trigger) {
this(gamepad, trigger, 0.5);
}

public TriggerReader(GamepadEx gamepad, GamepadKeys.Trigger trigger, double threshold) {
this.gamepad = gamepad;
this.trigger = trigger;

if (this.gamepad.getTrigger(trigger) > 0.5) {
this.threshold = threshold;

if (this.gamepad.getTrigger(trigger) > this.threshold) {
currState = true;
} else {
currState = false;
}

lastState = currState;
}

Expand All @@ -40,7 +50,7 @@ public TriggerReader(GamepadEx gamepad, GamepadKeys.Trigger trigger) {
**/
public void readValue() {
lastState = currState;
if (this.gamepad.getTrigger(trigger) > 0.5) {
if (this.gamepad.getTrigger(trigger) > this.threshold) {
currState = true;
} else {
currState = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ public DistanceTarget(DistanceUnit unit, double target, double threshold, String
*/
public boolean atTarget(double currentDistance) {
currentDistance = unit.fromUnit(unit, currentDistance);
double clippedRange = Range.clip(currentDistance, currentDistance - threshold, currentDistance + threshold);
if (clippedRange >= currentDistance + threshold)
return false;
else return !(clippedRange <= currentDistance + threshold);
return (currentDistance >= target - threshold) && (currentDistance <= target + threshold);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,21 @@ public boolean atTargetPosition() {
}

/**
* Resets the encoder.
* Resets the external encoder wrapper value.
*/
public void resetEncoder() {
encoder.reset();
}

/**
* Resets the internal position of the motor.
*/
public void stopAndResetEncoder() {
encoder.resetVal = 0;
motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
motor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
}

/**
* @return the velocity coefficients
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ public void setZeroPowerBehavior(ZeroPowerBehavior behavior) {

@Override
public void resetEncoder() {
for (Motor motor : group) {
motor.resetEncoder();
}
group[0].resetEncoder();
}

@Override
public void stopAndResetEncoder() {
group[0].stopAndResetEncoder();
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion core/vision/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ apply plugin: 'maven'

dependencies {
api 'org.openftc:easyopencv:1.5.3'
implementation 'org.openftc:apriltag:1.1.1'
implementation "androidx.core:core-ktx:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}

def groupId = 'com.arcrobotics.ftclib'
def artifactId = 'vision'
def version = '2.0.1'
def version = '2.1.0'

def localReleaseDest = "${buildDir}/release/${version}"
def releaseStorageDir = "${projectDir}/ReleaseStorage"
Expand Down
Loading