Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Bugfixes and IRL Testing (#8)
Browse files Browse the repository at this point in the history
* Missing gradle wrappers

* FtcRobotController v6.1

* Bump RR and migrate constraints

* remove unused imports

* pull changes from RR

* move update to commands

* fix: incorrect behavior of instant commands

* remove drive requirement in drive velocity tuner

* fix: incorrect deadline with logic

* fix: missing gamepad construction

* fix: define TurnCommand

* restructure drive velo pid tuner

* feat: change tests to wait until start

* refactor: change it from periodic to inside the commands

* fix: remove requirement of drive subsystem

* fix: update turn command to run with radians

* fix: field centric test y sign

* fix: call drive.update in the localization test

* fix: call drive.update in FieldCentricTest

* fix: FollowerPIDTuner.. all of it

Co-authored-by: CalKestis <[email protected]>
Co-authored-by: Cal Kestis <[email protected]>
Co-authored-by: Ryan Brott <[email protected]>
  • Loading branch information
4 people authored Jan 7, 2021
1 parent b03ee1c commit a83fbb2
Show file tree
Hide file tree
Showing 33 changed files with 205 additions and 276 deletions.
2 changes: 1 addition & 1 deletion FtcRobotController/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
buildConfigField "String", "BUILD_TIME", '"' + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ROOT).format(new Date())) + '"'
}

compileSdkVersion 28
compileSdkVersion 29

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
Expand Down
14 changes: 7 additions & 7 deletions FtcRobotController/build.release.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
dependencies {
implementation 'org.firstinspires.ftc:Inspection:6.0.1'
implementation 'org.firstinspires.ftc:Blocks:6.0.1'
implementation 'org.firstinspires.ftc:RobotCore:6.0.1'
implementation 'org.firstinspires.ftc:RobotServer:6.0.1'
implementation 'org.firstinspires.ftc:OnBotJava:6.0.1'
implementation 'org.firstinspires.ftc:Hardware:6.0.1'
implementation 'org.firstinspires.ftc:FtcCommon:6.0.1'
implementation 'org.firstinspires.ftc:Inspection:6.1.1'
implementation 'org.firstinspires.ftc:Blocks:6.1.1'
implementation 'org.firstinspires.ftc:RobotCore:6.1.1'
implementation 'org.firstinspires.ftc:RobotServer:6.1.1'
implementation 'org.firstinspires.ftc:OnBotJava:6.1.1'
implementation 'org.firstinspires.ftc:Hardware:6.1.1'
implementation 'org.firstinspires.ftc:FtcCommon:6.1.1'
implementation 'androidx.appcompat:appcompat:1.2.0'

implementation 'com.acmerobotics.dashboard:dashboard:0.3.10'
Expand Down
7 changes: 4 additions & 3 deletions FtcRobotController/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.qualcomm.ftcrobotcontroller"
android:versionCode="38"
android:versionName="6.0">
android:versionCode="39"
android:versionName="6.1">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Expand All @@ -13,7 +13,8 @@
android:extractNativeLibs="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppThemeRedRC" >
android:theme="@style/AppThemeRedRC"
android:usesCleartextTraffic="true">

<!-- Indicates to the ControlHubUpdater what the latest version of the Control Hub is that this app supports -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ public void runOpMode() {
// If your target is at distance greater than 50 cm (20") you can adjust the magnification value
// to artificially zoom in to the center of image. For best results, the "aspectRatio" argument
// should be set to the value of the images used to create the TensorFlow Object Detection model
// (typically 1.78 or 16/9).

// Uncomment the following line if you want to adjust the magnification and/or the aspect ratio of the input images.
//tfod.setZoom(2.5, 1.78);
// (typically 16/9).
tfod.setZoom(2.5, 16.0/9.0);
}

/** Wait for the game to begin */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ public void runOpMode() {
// If your target is at distance greater than 50 cm (20") you can adjust the magnification value
// to artificially zoom in to the center of image. For best results, the "aspectRatio" argument
// should be set to the value of the images used to create the TensorFlow Object Detection model
// (typically 1.78 or 16/9).

// Uncomment the following line if you want to adjust the magnification and/or the aspect ratio of the input images.
//tfod.setZoom(2.5, 1.78);
// (typically 16/9).
tfod.setZoom(2.5, 16.0/9.0);
}

/** Wait for the game to begin */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ public void runOpMode() {
// If your target is at distance greater than 50 cm (20") you can adjust the magnification value
// to artificially zoom in to the center of image. For best results, the "aspectRatio" argument
// should be set to the value of the images used to create the TensorFlow Object Detection model
// (typically 1.78 or 16/9).

// Uncomment the following line if you want to adjust the magnification and/or the aspect ratio of the input images.
//tfod.setZoom(2.5, 1.78);
// (typically 16/9).
tfod.setZoom(2.5, 16.0/9.0);
}

/** Wait for the game to begin */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import org.firstinspires.ftc.robotcore.internal.network.WifiMuteEvent;
import org.firstinspires.ftc.robotcore.internal.network.WifiMuteStateMachine;
import org.firstinspires.ftc.robotcore.internal.opmode.ClassManager;
import org.firstinspires.ftc.robotcore.internal.system.AppAliveNotifier;
import org.firstinspires.ftc.robotcore.internal.system.AppUtil;
import org.firstinspires.ftc.robotcore.internal.system.Assert;
import org.firstinspires.ftc.robotcore.internal.system.PreferencesHelper;
Expand Down Expand Up @@ -610,6 +611,9 @@ else if (id == R.id.action_exit_app) {
}
}

// Allow the user to use the Control Hub operating system's UI, instead of relaunching the app
AppAliveNotifier.getInstance().disableAppWatchdogUntilNextAppStart();

//Finally, nuke the VM from orbit
AppUtil.getInstance().exitApplication();

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Road Runner FTCLib Quickstart

**CURRENTLY IN PRODUCTION**
# Road Runner FTCLib Quickstart (CURRENTLY IN PRODUCTION)

An example FTC project using [Road Runner](https://github.com/acmerobotics/road-runner) with a dependency for [FTCLib](https://www.github.com/FTCLib/FTCLib) to set up a command-based project.

Expand Down
8 changes: 4 additions & 4 deletions TeamCode/build.release.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
dependencies {
implementation project(':FtcRobotController')
implementation 'org.firstinspires.ftc:RobotCore:6.0.1'
implementation 'org.firstinspires.ftc:Hardware:6.0.1'
implementation 'org.firstinspires.ftc:FtcCommon:6.0.1'
implementation 'org.firstinspires.ftc:RobotCore:6.1.1'
implementation 'org.firstinspires.ftc:Hardware:6.1.1'
implementation 'org.firstinspires.ftc:FtcCommon:6.1.1'
implementation (name: 'tfod-release', ext:'aar')
implementation (name: 'tensorflow-lite-0.0.0-nightly', ext:'aar')

implementation 'org.apache.commons:commons-math3:3.6.1'

implementation 'com.acmerobotics.roadrunner:core:0.5.2'
implementation 'com.acmerobotics.roadrunner:core:0.5.3'
implementation 'com.acmerobotics.dashboard:dashboard:0.3.10'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.firstinspires.ftc.teamcode.commands;

import com.acmerobotics.roadrunner.geometry.Pose2d;
import com.arcrobotics.ftclib.command.CommandBase;

import org.firstinspires.ftc.teamcode.subsystems.MecanumDriveSubsystem;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.firstinspires.ftc.teamcode.commands;

import com.acmerobotics.roadrunner.geometry.Pose2d;
import com.acmerobotics.roadrunner.trajectory.Trajectory;
import com.arcrobotics.ftclib.command.CommandBase;

Expand All @@ -23,6 +22,11 @@ public void initialize() {
drive.followTrajectory(trajectory);
}

@Override
public void execute() {
drive.update();
}

@Override
public void end(boolean interrupted) {
if (interrupted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public void initialize() {
drive.turn(angle);
}

@Override
public void execute() {
drive.update();
}

@Override
public void end(boolean interrupted) {
if (interrupted) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.firstinspires.ftc.teamcode.drive;

import com.acmerobotics.dashboard.config.Config;
import com.acmerobotics.roadrunner.trajectory.constraints.DriveConstraints;
import com.qualcomm.robotcore.hardware.PIDFCoefficients;

/*
Expand Down Expand Up @@ -33,7 +32,8 @@ public class DriveConstants {
* from DriveVelocityPIDTuner.
*/
public static final boolean RUN_USING_ENCODER = true;
public static PIDFCoefficients MOTOR_VELO_PID = new PIDFCoefficients(0, 0, 0, getMotorVelocityF(MAX_RPM / 60 * TICKS_PER_REV));
public static PIDFCoefficients MOTOR_VELO_PID = new PIDFCoefficients(0, 0, 0,
getMotorVelocityF(MAX_RPM / 60 * TICKS_PER_REV));

/*
* These are physical constants that can be determined from your robot (including the track
Expand Down Expand Up @@ -61,14 +61,13 @@ public class DriveConstants {
* These values are used to generate the trajectories for you robot. To ensure proper operation,
* the constraints should never exceed ~80% of the robot's actual capabilities. While Road
* Runner is designed to enable faster autonomous motion, it is a good idea for testing to start
* small and gradually increase them later after everything is working. The velocity and
* acceleration values are required, and the jerk values are optional (setting a jerk of 0.0
* forces acceleration-limited profiling). All distance units are inches.
* small and gradually increase them later after everything is working. All distance units are
* inches.
*/
public static DriveConstraints BASE_CONSTRAINTS = new DriveConstraints(
30.0, 30.0, 0.0,
Math.toRadians(180.0), Math.toRadians(180.0), 0.0
);
public static double MAX_VEL = 30;
public static double MAX_ACCEL = 30;
public static double MAX_ANG_VEL = Math.toRadians(180);
public static double MAX_ANG_ACCEL = Math.toRadians(180);


public static double encoderTicksToInches(double ticks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
import com.acmerobotics.roadrunner.profile.MotionState;
import com.acmerobotics.roadrunner.trajectory.Trajectory;
import com.acmerobotics.roadrunner.trajectory.TrajectoryBuilder;
import com.acmerobotics.roadrunner.trajectory.constraints.DriveConstraints;
import com.acmerobotics.roadrunner.trajectory.constraints.MecanumConstraints;
import com.acmerobotics.roadrunner.trajectory.constraints.AngularVelocityConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.MecanumVelocityConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.MinVelocityConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.ProfileAccelerationConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.TrajectoryAccelerationConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.TrajectoryVelocityConstraint;
import com.acmerobotics.roadrunner.util.NanoClock;
import com.qualcomm.hardware.bosch.BNO055IMU;
import com.qualcomm.hardware.lynx.LynxModule;
Expand All @@ -38,7 +42,10 @@
import java.util.LinkedList;
import java.util.List;

import static org.firstinspires.ftc.teamcode.drive.DriveConstants.BASE_CONSTRAINTS;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MAX_ACCEL;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MAX_ANG_ACCEL;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MAX_ANG_VEL;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MAX_VEL;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MOTOR_VELO_PID;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.RUN_USING_ENCODER;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.TRACK_WIDTH;
Expand Down Expand Up @@ -78,7 +85,8 @@ public enum Mode {
private MotionProfile turnProfile;
private double turnStart;

private DriveConstraints constraints;
private TrajectoryVelocityConstraint velConstraint;
private TrajectoryAccelerationConstraint accelConstraint;
private TrajectoryFollower follower;

private LinkedList<Pose2d> poseHistory;
Expand All @@ -104,7 +112,11 @@ public SampleMecanumDrive(HardwareMap hardwareMap) {
turnController = new PIDFController(HEADING_PID);
turnController.setInputBounds(0, 2 * Math.PI);

constraints = new MecanumConstraints(BASE_CONSTRAINTS, TRACK_WIDTH);
velConstraint = new MinVelocityConstraint(Arrays.asList(
new AngularVelocityConstraint(MAX_ANG_VEL),
new MecanumVelocityConstraint(MAX_VEL, TRACK_WIDTH)
));
accelConstraint = new ProfileAccelerationConstraint(MAX_ACCEL);
follower = new HolonomicPIDVAFollower(TRANSLATIONAL_PID, TRANSLATIONAL_PID, HEADING_PID,
new Pose2d(0.5, 0.5, Math.toRadians(5.0)), 0.5);

Expand Down Expand Up @@ -158,15 +170,15 @@ public SampleMecanumDrive(HardwareMap hardwareMap) {
}

public TrajectoryBuilder trajectoryBuilder(Pose2d startPose) {
return new TrajectoryBuilder(startPose, constraints);
return new TrajectoryBuilder(startPose, velConstraint, accelConstraint);
}

public TrajectoryBuilder trajectoryBuilder(Pose2d startPose, boolean reversed) {
return new TrajectoryBuilder(startPose, reversed, constraints);
return new TrajectoryBuilder(startPose, reversed, velConstraint, accelConstraint);
}

public TrajectoryBuilder trajectoryBuilder(Pose2d startPose, double startHeading) {
return new TrajectoryBuilder(startPose, startHeading, constraints);
return new TrajectoryBuilder(startPose, startHeading, velConstraint, accelConstraint);
}

public void turnAsync(double angle) {
Expand All @@ -177,9 +189,8 @@ public void turnAsync(double angle) {
turnProfile = MotionProfileGenerator.generateSimpleMotionProfile(
new MotionState(heading, 0, 0, 0),
new MotionState(heading + angle, 0, 0, 0),
constraints.maxAngVel,
constraints.maxAngAccel,
constraints.maxAngJerk
MAX_ANG_VEL,
MAX_ANG_ACCEL
);

turnStart = clock.seconds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
import com.acmerobotics.roadrunner.profile.MotionState;
import com.acmerobotics.roadrunner.trajectory.Trajectory;
import com.acmerobotics.roadrunner.trajectory.TrajectoryBuilder;
import com.acmerobotics.roadrunner.trajectory.constraints.DriveConstraints;
import com.acmerobotics.roadrunner.trajectory.constraints.TankConstraints;
import com.acmerobotics.roadrunner.trajectory.constraints.AngularVelocityConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.MinVelocityConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.ProfileAccelerationConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.TankVelocityConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.TrajectoryAccelerationConstraint;
import com.acmerobotics.roadrunner.trajectory.constraints.TrajectoryVelocityConstraint;
import com.acmerobotics.roadrunner.util.NanoClock;
import com.qualcomm.hardware.bosch.BNO055IMU;
import com.qualcomm.hardware.lynx.LynxModule;
Expand All @@ -37,7 +41,10 @@
import java.util.Arrays;
import java.util.List;

import static org.firstinspires.ftc.teamcode.drive.DriveConstants.BASE_CONSTRAINTS;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MAX_ACCEL;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MAX_ANG_ACCEL;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MAX_ANG_VEL;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MAX_VEL;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.MOTOR_VELO_PID;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.RUN_USING_ENCODER;
import static org.firstinspires.ftc.teamcode.drive.DriveConstants.TRACK_WIDTH;
Expand Down Expand Up @@ -73,7 +80,8 @@ public enum Mode {
private MotionProfile turnProfile;
private double turnStart;

private DriveConstraints constraints;
private TrajectoryVelocityConstraint velConstraint;
private TrajectoryAccelerationConstraint accelConstraint;
private TrajectoryFollower follower;

private List<Pose2d> poseHistory;
Expand All @@ -96,7 +104,11 @@ public SampleTankDrive(HardwareMap hardwareMap) {
turnController = new PIDFController(HEADING_PID);
turnController.setInputBounds(0, 2 * Math.PI);

constraints = new TankConstraints(BASE_CONSTRAINTS, TRACK_WIDTH);
velConstraint = new MinVelocityConstraint(Arrays.asList(
new AngularVelocityConstraint(MAX_ANG_VEL),
new TankVelocityConstraint(MAX_VEL, TRACK_WIDTH)
));
accelConstraint = new ProfileAccelerationConstraint(MAX_ACCEL);
follower = new TankPIDVAFollower(AXIAL_PID, CROSS_TRACK_PID,
new Pose2d(0.5, 0.5, Math.toRadians(5.0)), 0.5);

Expand Down Expand Up @@ -153,25 +165,24 @@ public SampleTankDrive(HardwareMap hardwareMap) {
}

public TrajectoryBuilder trajectoryBuilder(Pose2d startPose) {
return new TrajectoryBuilder(startPose, constraints);
return new TrajectoryBuilder(startPose, velConstraint, accelConstraint);
}

public TrajectoryBuilder trajectoryBuilder(Pose2d startPose, boolean reversed) {
return new TrajectoryBuilder(startPose, reversed, constraints);
return new TrajectoryBuilder(startPose, reversed, velConstraint, accelConstraint);
}

public TrajectoryBuilder trajectoryBuilder(Pose2d startPose, double startHeading) {
return new TrajectoryBuilder(startPose, startHeading, constraints);
return new TrajectoryBuilder(startPose, startHeading, velConstraint, accelConstraint);
}

public void turnAsync(double angle) {
double heading = getPoseEstimate().getHeading();
turnProfile = MotionProfileGenerator.generateSimpleMotionProfile(
new MotionState(heading, 0, 0, 0),
new MotionState(heading + angle, 0, 0, 0),
constraints.maxAngVel,
constraints.maxAngAccel,
constraints.maxAngJerk
MAX_ANG_VEL,
MAX_ANG_ACCEL
);
turnStart = clock.seconds();
mode = Mode.TURN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.acmerobotics.roadrunner.localization.ThreeTrackingWheelLocalizer;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.HardwareMap;

import org.firstinspires.ftc.teamcode.util.Encoder;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import com.acmerobotics.roadrunner.geometry.Pose2d;
import com.acmerobotics.roadrunner.trajectory.Trajectory;
import com.arcrobotics.ftclib.command.CommandOpMode;
import com.arcrobotics.ftclib.command.InstantCommand;
import com.arcrobotics.ftclib.command.PerpetualCommand;
import com.arcrobotics.ftclib.command.ScheduleCommand;
import com.arcrobotics.ftclib.command.SequentialCommandGroup;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;

Expand Down
Loading

0 comments on commit a83fbb2

Please sign in to comment.