Skip to content

Commit

Permalink
add swerve and turret code
Browse files Browse the repository at this point in the history
  • Loading branch information
gcschmit committed Dec 19, 2021
1 parent 0633fd4 commit 1ee5c01
Show file tree
Hide file tree
Showing 58 changed files with 3,175 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# 2021-release
public release of our 2020-2021 season software

* Galactic-Search: code for the FIRST@Home Galactic Search challenge
* Infinite-Recharge: code for Lumi, our Infinite Recharge 2.0 robot
* swerve-drive: code for our swerve drive prototype
* turret: code for our turret shooter prototype

13 changes: 13 additions & 0 deletions swerve-drive/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
35 changes: 35 additions & 0 deletions swerve-drive/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch SwerveSimRunner",
"request": "launch",
"mainClass": "frc.robot.SwerveSimRunner",
"projectName": "InfiniteRecharge2021",
"cwd": "${workspaceFolder}/build/tmp/jniExtractDir",
"vmArgs": [
"-Djava.library.path=${workspaceFolder}/build/tmp/jniExtractDir"
],
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/build/tmp/jniExtractDir",
"DYLD_LIBRARY_PATH": "${workspaceFolder}/build/tmp/jniExtractDir"
}
},
{
"type": "wpilib",
"name": "WPILib Desktop Debug",
"request": "launch",
"desktop": true
},
{
"type": "wpilib",
"name": "WPILib roboRIO Debug",
"request": "launch",
"desktop": false
}
]
}
27 changes: 27 additions & 0 deletions swerve-drive/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.server.launchMode": "Standard",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"bin/": true,
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true,
"**/*~": true
}, "java.test.config": [
{
"name": "WPIlibUnitTests",
"workingDirectory": "${workspaceFolder}/build/tmp/jniExtractDir",
"vmargs": [ "-Djava.library.path=${workspaceFolder}/build/tmp/jniExtractDir" ],
"env": { "LD_LIBRARY_PATH": "${workspaceFolder}/build/tmp/jniExtractDir" ,
"DYLD_LIBRARY_PATH": "${workspaceFolder}/build/tmp/jniExtractDir" }

},
],
"java.test.defaultConfig": "WPIlibUnitTests"
}
6 changes: 6 additions & 0 deletions swerve-drive/.wpilib/wpilib_preferences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"enableCppIntellisense": false,
"currentLanguage": "java",
"projectYear": "2021",
"teamNumber": 3061
}
109 changes: 109 additions & 0 deletions swerve-drive/READMEunitTestSetup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~Tutorial on how to set up a regular java robot project for unit testing~~~~~~~~~~~~~~~~~~~~~~~~~~~

Step 1
Paste this code in build.gradle so build.gradle knows to install the mockito dependency from MavenCentral:
repositories {
mavenCentral()
}

Step 2
Paste this code inside the {}s of build.gradle dependencies to tell the gradle to compile the mockito dependency with version 2.23 (it is important to use this version since this version supports Java 11):
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.0'

Step 3
Create a folder named "test\java\frc\robot" inside the src folder
If your robot project is a command project, add the "commands" & "subsystems" folders inside the test\java\frc\robot folder

Step 4
Add this to the .classpath file so VSCode recognizes the path your Unit Tests (.classpath file may not show up in VSCode, .classpath file should show up next to your build.gradle file in VSCode):
<classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>

Step 5
delete the ".classpath" line from the .gitignore so Github Desktop knows to commit your .classpath file's change to your branch/repository

Step 6
Paste this as a new setting in the settings.json file inside the .vscode folder. This tells FRC VSCode where to find the JNI libaries needed for many WPI Modules (remember to put a comma between any previous settings and this one!):
"java.test.config": [
{
"name": "WPIlibUnitTests",
"workingDirectory": "${workspaceFolder}/build/tmp/jniExtractDir",
"vmargs": [ "-Djava.library.path=${workspaceFolder}/build/tmp/jniExtractDir" ],
"env": { "LD_LIBRARY_PATH": "${workspaceFolder}/build/tmp/jniExtractDir" ,
"DYLD_LIBRARY_PATH": "${workspaceFolder}/build/tmp/jniExtractDir" }

},
],
"java.test.defaultConfig": "WPIlibUnitTests"

Step 7
Ctrl+Shift+P to open command palette
Choose this command:
run Java: clean Java Language server workspace

Step 8
install the Java Test Runner extension in your FRC VSCode

Step 9
Close out of FRC VSCode and reopen it. After that, you're done!

All unit tests go in src\test\java\frc\robot, and follow the same file structure & package statements as regular robot code
Wpilib & CTRE imports also seem to work in unit tests if settings.json was set up correctly


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Basic structure of an FRC Unit Test~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
package frc.robot; //package frc.robot.subsystems if in subsystems folder, package frc.robot.commands if in commands folder

import org.junit.*;
import static org.junit.Assert.*;
import org.mockito.*;
import static org.mockito.Mockito.*;

public class TemplateUnitTest {
@Before
public void setup() {
// code that runs before every test
}
@Mock
// put your mock instance variables here
Object objectMock;
@Test
public void myUnitTest() {
//write code for your unit test here
}
@Test
public void myUnitTest2() {
//write code for your 2nd unit test here
}
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~How to run an FRC Unit Test~~~~~~~~~~~~~~~~~~~~~~~~~~~
Make sure that you have the Java Test Runner extension installed
Click on the "run test" button that appears above a unit test method and below the @Test annotation
Example:

@Test
Run Test | Debug Test
public void myUnitTest() {
//write code for your unit test here
}

^^^^^^^^Unit test should look like this^^^^^^^^^^^^^
If unit test passed, a checkmark should pop up next to the "Run Test | Debug Test" buttons. Click on the checkmark to view details about the test in a new window
Example:
@Test
Run Test | Debug Test ✓
public void myUnitTest() {
//write code for your unit test here
}
If unit test failed, an X should appear in the same spot. Click on the X to view details about the test in a new window

~~~~~~~~~~~~~~~~~Known Bugs~~~~~~~~~~~~~~~~~
Cannot find jniExtractDir because it does not exist:
Make sure .scode\settings.json has correct settings (see above to setup settings.json correctly)
Right click on build.gradle, click on "build robot code".
24 changes: 24 additions & 0 deletions swerve-drive/WPILib-License.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2009-2021 FIRST and other WPILib contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of FIRST, WPILib, nor the names of other WPILib
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY FIRST AND OTHER WPILIB CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY NONINFRINGEMENT AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FIRST OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions swerve-drive/bin/main/frc/robot/swerve_math.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
swerve_math1.jpg: displays translation vector for each wheel (same vector as the tilt of joystick)
swerve_math2.jpg: displays rotation vector for each wheel (wheels travel in a circle, vectors are perpendicular to the diagonal of the robot's rectangular chassis. Twist of joystick controls the magnitude of each rotation vector)
swerve_math3.jpg: adds both the translation vector and rotation vector for each wheel
Binary file added swerve-drive/bin/main/frc/robot/swerve_math1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added swerve-drive/bin/main/frc/robot/swerve_math2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added swerve-drive/bin/main/frc/robot/swerve_math3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions swerve-drive/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2021.2.1"
}

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

def ROBOT_MAIN_CLASS = "frc.robot.Main"

// Define my targets (RoboRIO) and artifacts (deployable files)
// This is added by GradleRIO's backing project EmbeddedTools.
deploy {
targets {
roboRIO("roborio") {
// Team number is loaded either from the .wpilib/wpilib_preferences.json
// or from command line. If not found an exception will be thrown.
// You can use getTeamOrDefault(team) instead of getTeamNumber if you
// want to store a team number in this file.
team = frc.getTeamNumber()
}
}
artifacts {
frcJavaArtifact('frcJava') {
targets << "roborio"
// Debug can be overridden by command line, for use with VSCode
debug = frc.getDebugOrDefault(false)
}
// Built in artifact to deploy arbitrary files to the roboRIO.
fileTreeArtifact('frcStaticFileDeploy') {
// The directory below is the local directory to deploy
files = fileTree(dir: 'src/main/deploy')
// Deploy to RoboRIO target, into /home/lvuser/deploy
targets << "roborio"
directory = '/home/lvuser/deploy'
}
}
}

// Set this to true to enable desktop support.
def includeDesktopSupport = true

repositories {
mavenCentral()
}

// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.
// Also defines JUnit 4.
dependencies {
implementation wpi.deps.wpilib()
nativeZip wpi.deps.wpilibJni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.wpilibJni(wpi.platforms.desktop)


implementation wpi.deps.vendor.java()
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)

testImplementation 'junit:junit:4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.0'

// Enable simulation gui support. Must check the box in vscode to enable support
// upon debugging
simulation wpi.deps.sim.gui(wpi.platforms.desktop, false)
simulation wpi.deps.sim.driverstation(wpi.platforms.desktop, false)

// Websocket extensions require additional configuration.
// simulation wpi.deps.sim.ws_server(wpi.platforms.desktop, false)
// simulation wpi.deps.sim.ws_client(wpi.platforms.desktop, false)
}

// Simulation configuration (e.g. environment variables).
sim {
// Sets the websocket client remote host.
// envVar "HALSIMWS_HOST", "10.0.0.2"
}

// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')
// in order to make them all available at runtime. Also adding the manifest so WPILib
// knows where to look for our Robot Class.
jar {
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS)
}
Binary file added swerve-drive/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions swerve-drive/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=permwrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=permwrapper/dists
Loading

0 comments on commit 1ee5c01

Please sign in to comment.