mirror of
https://github.com/TimeCrafters/CenterStage
synced 2025-12-15 16:52:35 +00:00
Trying to find right syntax for a parallel background state
This commit is contained in:
@@ -4,6 +4,7 @@ import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||
|
||||
import org.timecrafters.CenterStage.Autonomous.States.SodiPizzaAutoArmState;
|
||||
import org.timecrafters.CenterStage.Autonomous.States.SodiPizzaAutoFirstDriveState;
|
||||
import org.timecrafters.CenterStage.Autonomous.States.SodiPizzaAutoSecDriveState;
|
||||
import org.timecrafters.CenterStage.Autonomous.States.SodiPizzaAutoTurnState;
|
||||
import org.timecrafters.CenterStage.Autonomous.States.SodiPizzaWheelTest;
|
||||
|
||||
@@ -13,8 +14,12 @@ import dev.cyberarm.engine.V2.CyberarmEngine;
|
||||
public class SodiPizzaAutoRedRightEngine extends CyberarmEngine {
|
||||
@Override
|
||||
public void setup() {
|
||||
|
||||
addState(new SodiPizzaAutoFirstDriveState());
|
||||
addState(new SodiPizzaAutoTurnState());
|
||||
|
||||
// addState(new SodiPizzaAutoSecDriveState());
|
||||
|
||||
// addState(new SodiPizzaAutoArmState());
|
||||
// addState(new SodiPizzaWheelTest());
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ public class SodiPizzaAutoFirstDriveState extends CyberarmState{
|
||||
private long lastMoveTime;
|
||||
private int targetPos = 2500;
|
||||
private double drivePower;
|
||||
private boolean lastHalf;
|
||||
|
||||
public SodiPizzaAutoFirstDriveState() {
|
||||
groupName = " ";
|
||||
@@ -26,7 +25,6 @@ public class SodiPizzaAutoFirstDriveState extends CyberarmState{
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
lastHalf = false;
|
||||
lastMoveTime = System.currentTimeMillis();
|
||||
robot.readyToTurn = 0;
|
||||
|
||||
@@ -43,8 +41,8 @@ public class SodiPizzaAutoFirstDriveState extends CyberarmState{
|
||||
@Override
|
||||
public void exec() {
|
||||
// Move forward from 0 to targetPos
|
||||
if (robot.leftFront.getCurrentPosition() <= 10 && robot.leftFront.getCurrentPosition() >= -10
|
||||
&& !lastHalf) {
|
||||
if (robot.leftFront.getCurrentPosition() <= 10 && robot.leftFront.getCurrentPosition() >= -10) {
|
||||
|
||||
robot.leftFront.setTargetPosition(targetPos);
|
||||
robot.leftBack.setTargetPosition(targetPos);
|
||||
robot.rightFront.setTargetPosition(targetPos);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.timecrafters.CenterStage.Autonomous.States;
|
||||
|
||||
import org.timecrafters.CenterStage.Common.SodiPizzaMinibotObject;
|
||||
|
||||
import dev.cyberarm.engine.V2.CyberarmState;
|
||||
|
||||
public class SodiPizzaAutoSecDriveState extends CyberarmState {
|
||||
|
||||
final private SodiPizzaMinibotObject robot;
|
||||
final private String groupName, actionName;
|
||||
|
||||
public SodiPizzaAutoSecDriveState() {
|
||||
groupName = " ";
|
||||
actionName = " ";
|
||||
robot = new SodiPizzaMinibotObject();
|
||||
robot.setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,13 @@ import org.timecrafters.CenterStage.Common.SodiPizzaMinibotObject;
|
||||
import dev.cyberarm.engine.V2.CyberarmState;
|
||||
|
||||
public class SodiPizzaAutoTurnState extends CyberarmState {
|
||||
final private SodiPizzaMinibotObject robot = new SodiPizzaMinibotObject();
|
||||
final private SodiPizzaMinibotObject robot = SodiPizzaMinibotObject();
|
||||
final private String groupName, actionName;
|
||||
private long lastMoveTime;
|
||||
private double turnSpeedRaw, turnSpeed;
|
||||
private int startPos;
|
||||
private double targetRot;
|
||||
private double currentRot = robot.imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.DEGREES);
|
||||
private double currentRot;
|
||||
private double neededRot = targetRot - currentRot;
|
||||
/** Rot = rotation **/
|
||||
|
||||
@@ -23,6 +23,13 @@ public class SodiPizzaAutoTurnState extends CyberarmState {
|
||||
robot.setup();
|
||||
}
|
||||
|
||||
public SodiPizzaAutoTurnState(int readyToTurnParm) {
|
||||
groupName = " ";
|
||||
actionName = " ";
|
||||
robot.setup();
|
||||
robot.readyToTurn = readyToTurnParm;
|
||||
}
|
||||
|
||||
private double getTurnSpeed() {
|
||||
if (Math.abs(neededRot) > 5) {
|
||||
turnSpeed = turnSpeedRaw * neededRot / 10;
|
||||
@@ -48,6 +55,8 @@ public class SodiPizzaAutoTurnState extends CyberarmState {
|
||||
@Override
|
||||
public void exec() {
|
||||
|
||||
currentRot = robot.imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.DEGREES);
|
||||
|
||||
if (robot.readyToTurn == 1 && robot.leftFront.getCurrentPosition() == startPos && Math.abs(neededRot) > 10) {
|
||||
|
||||
targetRot = currentRot + 90;
|
||||
@@ -59,12 +68,14 @@ public class SodiPizzaAutoTurnState extends CyberarmState {
|
||||
robot.rightFront.setPower(-turnSpeed);
|
||||
robot.rightBack.setPower(-turnSpeed);
|
||||
|
||||
} else if (robot.readyToTurn == 1 && Math.abs(neededRot) < 10) {
|
||||
} else if (robot.readyToTurn == 1 && Math.abs(neededRot) < 5) {
|
||||
turnSpeedRaw = 0;
|
||||
robot.leftFront.setPower(turnSpeed);
|
||||
robot.leftBack.setPower(turnSpeed);
|
||||
robot.rightFront.setPower(turnSpeed);
|
||||
robot.rightBack.setPower(turnSpeed);
|
||||
|
||||
robot.readyToTurn = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user