mirror of
https://github.com/TimeCrafters/FreightFrenzy.git
synced 2025-12-13 05:02:34 +00:00
Compare commits
3 Commits
8f2f471667
...
ee4e05f28d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee4e05f28d | ||
|
|
7332fe8a72 | ||
|
|
6136b0a3b5 |
1
TC_Config/FreightFrenzy.json
Normal file
1
TC_Config/FreightFrenzy.json
Normal file
@@ -0,0 +1 @@
|
||||
{"config":{"created_at":"2021-12-02 19:33:56 -0600","updated_at":"2021-12-02 20:11:14 -0600","spec_version":2,"revision":38},"data":{"groups":[{"name":"autonomous","actions":[{"name":"01_0","comment":"turret rotation (;","enabled":true,"variables":[{"name":"power","value":"Dx1"},{"name":"time","value":"Lx3"}]},{"name":"02_0","comment":"Turret Arm Extension","enabled":true,"variables":[{"name":"power","value":"Dx0.75"},{"name":"targetPosition","value":"Ix3000"},{"name":"tolerance","value":"Ix150"}]},{"name":"03_0","comment":"Depositor Door","enabled":true,"variables":[{"name":"TargetPosition","value":"Dx0.5"},{"name":"time","value":"Lx1"}]},{"name":"04_0","comment":"Depositor Door","enabled":true,"variables":[{"name":"TargetPosition","value":"Dx0"},{"name":"time","value":"Lx0"}]},{"name":"05_0","comment":"Turret Arm Extension","enabled":true,"variables":[{"name":"power","value":"Dx1"},{"name":"targetPosition","value":"Ix0"},{"name":"tolerance","value":"Ix150"}]},{"name":"06_0","comment":"turret rotation (;","enabled":true,"variables":[{"name":"power","value":"Dx-1"},{"name":"time","value":"Lx3"}]},{"name":"07_0","comment":"Drive State","enabled":true,"variables":[{"name":"distanceLeft","value":"Ix1500"},{"name":"distanceRight","value":"Ix1500"},{"name":"powerLeft","value":"Dx1"},{"name":"powerRight","value":"Dx1"}]},{"name":"08_0","comment":"Drive State","enabled":true,"variables":[{"name":"distanceLeft","value":"Ix1500"},{"name":"distanceRight","value":"Ix500"},{"name":"powerLeft","value":"Dx1"},{"name":"powerRight","value":"Dx0.75"}]}]}],"presets":{"groups":[],"actions":[{"name":"DepositorDoor","comment":"Depositor Door","enabled":true,"variables":[{"name":"TargetPosition","value":"Dx0.5"},{"name":"time","value":"Lx1"}]},{"name":"DriveState","comment":"Drive State","enabled":true,"variables":[{"name":"distanceLeft","value":"Ix1500"},{"name":"distanceRight","value":"Ix500"},{"name":"powerLeft","value":"Dx1"},{"name":"powerRight","value":"Dx0.75"}]},{"name":"TurretArmExtension","comment":"Turret Arm Extension","enabled":true,"variables":[{"name":"power","value":"Dx0.75"},{"name":"targetPosition","value":"Ix3000"},{"name":"tolerance","value":"Ix150"}]},{"name":"TurretOrbit","comment":"turret rotation (;","enabled":true,"variables":[{"name":"power","value":"Dx1"},{"name":"time","value":"Lx3"}]}]}}}
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.timecrafters.FreightFrenzy.Competition.Autonomous.Engines;
|
||||
|
||||
import org.cyberarm.engine.V2.CyberarmEngine;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Autonomous.States.DepositorDoor;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Autonomous.States.DriveState;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Autonomous.States.TurretArmExtension;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Autonomous.States.TurretOrbit;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Common.Robot;
|
||||
|
||||
public class RedWarehouseEngine extends CyberarmEngine {
|
||||
@@ -9,6 +12,14 @@ public class RedWarehouseEngine extends CyberarmEngine {
|
||||
public void setup() {
|
||||
Robot robot = new Robot(this);
|
||||
|
||||
addState(new DriveState(robot, 2000, 2000,1,1));
|
||||
addState(new TurretOrbit(robot, robot.turretServoWhite, "autonomous", "01_0"));
|
||||
addState(new TurretArmExtension(robot, robot.whiteArmBobbin, "autonomous", "02_0"));
|
||||
addState(new DepositorDoor(robot, robot.whiteDispenser, "autonomous", "03_0"));
|
||||
addState(new DepositorDoor(robot, robot.whiteDispenser, "autonomous", "04_0"));
|
||||
addState(new TurretArmExtension(robot, robot.whiteArmBobbin, "autonomous", "05_0"));
|
||||
addState(new TurretOrbit(robot, robot.turretServoWhite, "autonomous", "01_0"));
|
||||
addState(new DriveState(robot, 1500, 500, 1, .75));
|
||||
addState(new DriveState(robot, 1500, 1500, 1, 1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.timecrafters.FreightFrenzy.Competition.Autonomous.States;
|
||||
|
||||
import com.qualcomm.robotcore.hardware.CRServo;
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
|
||||
import org.cyberarm.engine.V2.CyberarmState;
|
||||
|
||||
public class CollectorToggle extends CyberarmState {
|
||||
final static public int MODE_REVERSE = -1;
|
||||
final static public int MODE_COLLECT = 1;
|
||||
final static public int MODE_STOPPED = 0;
|
||||
|
||||
CRServo servo;
|
||||
int mode;
|
||||
|
||||
public CollectorToggle(CRServo servo, int mode) {
|
||||
this.servo = servo;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
if (mode == MODE_REVERSE){
|
||||
servo.setPower(-1);
|
||||
}
|
||||
|
||||
else if (mode == MODE_COLLECT){
|
||||
servo.setPower(1);
|
||||
}
|
||||
|
||||
else {
|
||||
servo.setPower(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.timecrafters.FreightFrenzy.Competition.Autonomous.States;
|
||||
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
|
||||
import org.cyberarm.engine.V2.CyberarmState;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Common.Robot;
|
||||
|
||||
public class DepositorDoor extends CyberarmState {
|
||||
|
||||
Servo servo;
|
||||
double targetPosition;
|
||||
long time;
|
||||
|
||||
public DepositorDoor(Robot robot, Servo servo, String groupName, String actionName) {
|
||||
this.servo = servo;
|
||||
this.targetPosition = robot.configuration.variable(groupName, actionName, "targetPosition").value();
|
||||
this.time = robot.configuration.variable(groupName, actionName, "time").value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
if (runTime() < time) {
|
||||
servo.setPosition(targetPosition);
|
||||
}
|
||||
else {
|
||||
setHasFinished(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,18 +9,29 @@ public class TurretArmExtension extends CyberarmState {
|
||||
|
||||
private Robot robot;
|
||||
private DcMotor motor;
|
||||
private int position;
|
||||
private int targetPosition, tolerance;
|
||||
private double power;
|
||||
|
||||
public TurretArmExtension(Robot robot, DcMotor motor, int position, double power) {
|
||||
public TurretArmExtension(Robot robot, DcMotor motor, String groupName, String actionName) {
|
||||
this.robot = robot;
|
||||
this.motor = motor;
|
||||
this.position = position;
|
||||
this.power = power;
|
||||
this.targetPosition = robot.configuration.variable(groupName, actionName, "targetPosition").value();
|
||||
this.power = robot.configuration.variable(groupName, actionName, "power").value();
|
||||
this.tolerance = robot.configuration.variable(groupName, actionName, "tolerance").value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
if (motor.getCurrentPosition() < targetPosition + tolerance){
|
||||
motor.setPower(power);
|
||||
}
|
||||
|
||||
else if (motor.getCurrentPosition() > targetPosition - tolerance){
|
||||
motor.setPower(-power);
|
||||
}
|
||||
else {
|
||||
setHasFinished(true);
|
||||
motor.setPower(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.timecrafters.FreightFrenzy.Competition.Autonomous.States;
|
||||
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
|
||||
import org.cyberarm.engine.V2.CyberarmState;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Common.Robot;
|
||||
|
||||
public class TurretArmRiser extends CyberarmState {
|
||||
|
||||
private Robot robot;
|
||||
private DcMotor motor;
|
||||
private int targetPosition, tolerance;
|
||||
private double power;
|
||||
|
||||
public TurretArmRiser(Robot robot, DcMotor motor, int targetPosition, double power, int tolerance) {
|
||||
this.robot = robot;
|
||||
this.motor = motor;
|
||||
this.targetPosition = targetPosition;
|
||||
this.power = power;
|
||||
this.tolerance = tolerance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
if (motor.getCurrentPosition() < targetPosition + tolerance){
|
||||
motor.setPower(power);
|
||||
}
|
||||
|
||||
else if (motor.getCurrentPosition() > targetPosition - tolerance){
|
||||
motor.setPower(-power);
|
||||
}
|
||||
else {
|
||||
setHasFinished(true);
|
||||
motor.setPower(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import com.qualcomm.robotcore.hardware.CRServo;
|
||||
|
||||
import org.cyberarm.engine.V2.CyberarmState;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Common.Robot;
|
||||
import org.timecrafters.TimeCraftersConfigurationTool.library.TimeCraftersConfiguration;
|
||||
import org.timecrafters.TimeCraftersConfigurationTool.library.backend.config.Action;
|
||||
|
||||
public class TurretOrbit extends CyberarmState {
|
||||
private Robot robot;
|
||||
@@ -11,11 +13,11 @@ public class TurretOrbit extends CyberarmState {
|
||||
private long time;
|
||||
private double power;
|
||||
|
||||
public TurretOrbit(Robot robot, CRServo servo, long time, double power) {
|
||||
public TurretOrbit(Robot robot, CRServo servo, String groupName, String actionName) {
|
||||
this.robot = robot;
|
||||
this.servo = servo;
|
||||
this.time = time;
|
||||
this. power = power;
|
||||
this.time = robot.configuration.variable(groupName, actionName, "time").value();
|
||||
this. power = robot.configuration.variable(groupName, actionName, "power").value();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.timecrafters.FreightFrenzy.Competition.Autonomous.States;
|
||||
|
||||
import org.cyberarm.engine.V2.CyberarmState;
|
||||
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
|
||||
import org.timecrafters.FreightFrenzy.Competition.Common.Robot;
|
||||
|
||||
public class VuforiaState extends CyberarmState {
|
||||
|
||||
Robot robot;
|
||||
|
||||
public VuforiaState(Robot robot) {
|
||||
this.robot = robot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
robot.activateVuforia();
|
||||
robot.activateTensorflow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
for (Recognition recognition : robot.tensorflowDetections()) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void telemetry() {
|
||||
for (Recognition recognition : robot.tensorflowDetections()) {
|
||||
engine.telemetry.addData("Label", recognition.getLabel());
|
||||
engine.telemetry.addData("Left", recognition.getLeft());
|
||||
engine.telemetry.addData("Top", recognition.getTop());
|
||||
engine.telemetry.addData("Confidence", recognition.getConfidence());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user