Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2dba680
Implemented state and stateMachine classes
GarrettBurroughs Dec 17, 2017
00ae340
Implemented alloy autonomous
GarrettBurroughs Dec 17, 2017
4de9925
Added newState method in autostatmachine
GarrettBurroughs Dec 17, 2017
6dd957c
Update FTCDebug.java
GarrettBurroughs Jan 26, 2018
54874bb
Created static init() method for Debug.java
GarrettBurroughs Jan 26, 2018
2a40fd5
Initialize FTCDebug
GarrettBurroughs Jan 26, 2018
ee4f1cd
Implemented base alloy autonomous
GarrettBurroughs Jan 27, 2018
ec8b5c2
Merge branch 'Autonomous' of https://github.com/GarrettBurroughs/Allo…
GarrettBurroughs Jan 27, 2018
a133fd2
removed files that should have been ignored
GarrettBurroughs Jan 27, 2018
ec387ee
Merge branch 'master' into Autonomous
GarrettBurroughs Feb 3, 2018
601a4a8
revert changes that made debug static
GarrettBurroughs Feb 3, 2018
49b9a13
Merge branch 'master' into Autonomous
GarrettBurroughs Feb 3, 2018
b2d05eb
Merge branch 'master' into Autonomous
GarrettBurroughs Feb 12, 2018
4154819
Readme Update
GarrettBurroughs Feb 12, 2018
727df52
merge
GarrettBurroughs Sep 8, 2018
e4b7785
Implemented turning and driving auto modes
GarrettBurroughs Sep 12, 2018
1c0271a
added autonomous features and samples
GarrettBurroughs Oct 7, 2018
77e0df6
Merge branch 'master' into Autonomous
GarrettBurroughs Jan 24, 2019
558b26c
Fixed Merge conflicts and Removed InvalidParameterException
GarrettBurroughs Jan 24, 2019
37412c6
Updated Format and debugging for states
GarrettBurroughs Jan 24, 2019
b62483b
Updated Description and debug info for state machines
GarrettBurroughs Jan 24, 2019
f7efc98
Updated Simple Autonomous
GarrettBurroughs Jan 24, 2019
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
.idea/
main/java/main.iml

# Sensitive or high-churn files:
.idea/**/dataSources/
Expand Down Expand Up @@ -32,6 +34,7 @@ cmake-build-debug/

# IntelliJ
out/
.idea/

# Project
src/test/
Expand Down
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

8 changes: 1 addition & 7 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: java
jdk:
- oraclejdk8
before_install:
- chmod +x gradlew
language: java
jdk:
- oraclejdk8
before_install:
- chmod +x gradlew

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
![AlloyLogo](http://gdurl.com/AFl8)

Status: **Beta**


Alloy is a robot framework designed specifically for the First Tech Challenge (FTC).

Alloy is based off the FRC robot framework [Sprocket](https://github.com/MontclairRobotics/Sprocket), but redesigned to abstract away the more complex ideas but still allow for advanced robot functionality.

Note: Alloy is still under heavy development, and not ready or suggested for use in creating a robot

Developed by FTC147 and FRC555
Expand Down
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ spotless {

licenseHeaderFile 'SpotlessLicense'
paddedCell()


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,109 @@ of this software and associated documentation files (the "Software"), to deal
package org.montclairrobotics.alloy.auto;

import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.util.ElapsedTime;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.Set;
import org.montclairrobotics.alloy.core.Alloy;
import org.montclairrobotics.alloy.core.RobotCore;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;

/**
* Created by MHS Robotics on 12/5/2017.
*
* AlloyAutonomous is the core framework for coding auto modes
* When an auto mode extends AlloyAutonomous, it needs to override
* the setup() method, and has the option of overriding the userLoop()
* method. In the setup method, <code>auto<code/> needs to be set to a
* state machine, that will be run during the auto mode
*
* The optional userLoop() method can be used to update or perform
* actions every loop, it is called before the state in the state machine
*
* @author Garrett Burroughs
* @version 0.1
* @since 0.1
*/
public abstract class AlloyAutonomous extends OpMode {

/** Keeps track of when the auto mode is running (True after started and before finished) */
boolean running;

/** The actual auto mode that should be instantiated in setup */
public StateMachine auto;

/** A timer to keep track of time in the autoMode */
public ElapsedTime timer;

/**
* This is where the user should define all their code and where "Auto", should be instantiated
*/
public abstract void setup();

/**
* Runs when the play button is pressed Start will set up everything that the auto mode needs to
* run
*/
@Override
public void start() {
auto.start(); // run the start method of the state machine
running = true; // the state machine has started running
timer.reset(); // reset the timer
}

/**
* Init is called when the INIT button is pressed on the drivers station. The init method takes
* care of setting up global robot variables and running the user setup method
*/
@Override
public void init() {
// this code will be run on robot initialization
Reflections reflections = new Reflections(new SubTypesScanner());
Set<Class<? extends Alloy>> robots = reflections.getSubTypesOf(Alloy.class);
for (Class<? extends Alloy> robot : robots) {
try {
if (!Modifier.isAbstract(robot.getMethod("robotSetup").getModifiers())
|| robot.getMethod("robotSetup") == null) {
robot.getMethod("robotSetup").invoke(robot.newInstance());
}
} catch (NoSuchMethodException
| IllegalAccessException
| InstantiationException
| InvocationTargetException e) {
e.printStackTrace();
}
}

new RobotCore(telemetry, hardwareMap, gamepad1, gamepad2);
setup();
}

/**
* The user loop can be overridden in the auto mode and is called every loop before the state is
* run. This can be useful for updating information used in states.
*/
public void userLoop() {}

/** the Loop method takes care of running the state machine */
@Override
public void loop() {
// This code will be run once a loop while the auto mode is running
userLoop();
if (running) {
auto.run(); // Run the state machine, which will in turn run the states
}
if (auto.isDone()) { // check if the state machine has finished (Last state achieved)
running = false; // stop the state machine
auto.stop(); // Finally stop the state machine
}
}

/**
* A wrapper around the add state method to allow the user to add states to the auto mode
*
* @param state the state to be added
*/
public void newState(State state) {
auto.addState(state);
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/montclairrobotics/alloy/auto/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ when they have finished running
3. Alloy Autonomus - This is the basic framework for alloy auto's. An alloy autonomous takes care of running the state machine<br>
that the auto is using so all the user has to do is create the state machine and define functionality.
You can read more about how to use an Alloy Autonomous [Here](https://github.com/GarrettBurroughs/Alloy/wiki/Creating-An-Auto-Mode)

4. Simple Autonomous - A simple autonomous mode further abstracts away auto mode creation allowing
for command like auto mode programming. You can read more about how to use a Simple autonomous [Here](https://github.com/GarrettBurroughs/Alloy/wiki/Creating-An-Auto-Mode)
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
MIT License

Copyright (c) 2018 Garrett Burroughs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package org.montclairrobotics.alloy.auto;

import org.montclairrobotics.alloy.auto.States.ConditionalState;
import org.montclairrobotics.alloy.auto.States.Drive;
import org.montclairrobotics.alloy.auto.States.Turn;
import org.montclairrobotics.alloy.utils.Input;
import org.montclairrobotics.alloy.vector.Angle;

/**
* Created by MHS Robotics on 1/26/2018.
*
* <p>SimpleAutonomous abstracts away the concept of adding states to a state machine, so that
* states can be added as if they were commands to be executed by the auto mode. This class only has
* the pre-written states included, so another class extending this one would need to be created to
* add any custom states
*
* @author Garrett Burroughs
* @since
*/
public class SimpleAutonomous extends AlloyAutonomous {
@Override
public void setup() {}

public void drive(double speed, double distance) {
addState(new Drive(speed, distance));
}

public void turn(double speed, Angle angle) {
addState(new Turn(speed, angle));
}

public void contition(Input<Boolean> condition, State state){
addState(new ConditionalState(condition, state));
}

public void addState(State state){
auto.addState(state);
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/montclairrobotics/alloy/auto/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ of this software and associated documentation files (the "Software"), to deal
public abstract class State {

private Integer nextState = null;
protected String debug = "Running State: ";
protected String description = "None";

/** The start method is the first thing called when the state is run */
public abstract void start();
Expand All @@ -55,10 +57,33 @@ public abstract class State {
*/
public abstract boolean isDone();

/**
* In order to have a non linear state machine, the state machine must know what state to go to
* when it is done with the previous state. The state also sometimes needs to know the current
* state for example if it just wanted to increment the state by one.
*
* @param currentState the state the state machine is currently running
* @return the state the state machine should go to
*/
public int getNextState(int currentState) {
if (nextState != null) {
return nextState;
}
return currentState + 1;
}

/**
* When a state machine is running, it will debug out information about the state it is running.
* It will debug the result of debugInfo
*
* @param currentState the current state so that it can be used in the debug
* @return debug information about the state
*/
public String debugInfo(int currentState) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to give different levels of debugs depending on the debug mode

return debug + currentState;
}

public String verboseDebug() {
return description;
}
}
Loading