Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static void register(ConfigCommandStore commandStore) {
commandStore.registerClass(TurretTarget.class);
commandStore.registerClass(TurretPrep.class);

commandStore.registerClass(OIRumble.class);

commandStore.registerClass(WaitCommand.class);
commandStore.registerClass(ChooserCommand.class);
}
Expand Down
70 changes: 70 additions & 0 deletions core/src/main/java/org/teamtators/rotator/commands/OIRumble.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.teamtators.rotator.commands;

import org.teamtators.rotator.CommandBase;
import org.teamtators.rotator.CoreRobot;
import org.teamtators.rotator.config.Configurable;
import org.teamtators.rotator.control.Timer;
import org.teamtators.rotator.operatorInterface.AbstractOperatorInterface;
import org.teamtators.rotator.operatorInterface.LogitechF310;
import org.teamtators.rotator.operatorInterface.RumbleType;

public class OIRumble extends CommandBase implements Configurable<OIRumble.Config> {

private Config config;
private int times;
private Timer timer;
private boolean rumbling;
private LogitechF310 joystick;
private AbstractOperatorInterface operatorInterface;

public OIRumble(CoreRobot robot) {
super("OIRumble");
timer = robot.timer();
this.operatorInterface = robot.operatorInterface();
}

@Override
public void configure(Config config) {
this.config = config;
if (config.joystick.equals("driver")) {
joystick = operatorInterface.driverJoystick();
} else if (config.joystick.equals("gunner")) {
joystick = operatorInterface.gunnerJoystick();
}
}

@Override
protected void initialize() {
logger.info("Rumbling {} times", config.maxTimes);
times = 0;
joystick.setRumble(config.type, (float) config.value);
rumbling = true;
timer.start();
}

@Override
protected boolean step() {
if (rumbling && timer.hasPeriodElapsed(config.onTime)) {
joystick.setRumble(config.type, 0);
rumbling = false;
times++;
} else if (!rumbling && timer.hasPeriodElapsed(config.offTime)) {
joystick.setRumble(config.type, (float) config.value);
rumbling = true;
}
return times >= config.maxTimes;
}

protected void finish() {
joystick.setRumble(config.type, 0);
}

static class Config {
public int maxTimes;
public double onTime;
public double offTime;
public String joystick = "driver";
public RumbleType type;
public double value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ default TriggerSource getTriggerSource(Button button) {
return new LogitechTrigger(this, button);
}

void setRumble(RumbleType rumbleType, float value);

/**
* Enum containing the location of all the buttons on a Logitech F310 gamepad
*/
Expand Down Expand Up @@ -115,4 +117,5 @@ public boolean getActive() {
return joystick.getButtonValue(button);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.teamtators.rotator.operatorInterface;

public enum RumbleType {
LEFT,
RIGHT
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.teamtators.rotator.operatorInterface.noop;

import org.teamtators.rotator.operatorInterface.LogitechF310;
import org.teamtators.rotator.operatorInterface.RumbleType;

public class NoopLogitechF310 implements LogitechF310 {
@Override
Expand All @@ -12,4 +13,9 @@ public double getAxisValue(Axis axisKind) {
public boolean getButtonValue(Button button) {
return false;
}

@Override
public void setRumble(RumbleType rumbleType, float value) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.teamtators.rotator.operatorInterface.LogitechF310;
import org.teamtators.rotator.operatorInterface.RumbleType;
import org.teamtators.rotator.scheduler.TriggerSource;

import javax.inject.Inject;
Expand All @@ -29,6 +30,11 @@ public WASDJoystick() {
reset();
}

@Override
public void setRumble(RumbleType rumbleType, float value) {

}

public void reset() {
up = false;
left = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ public WPILibLogitechF310(int port) {
super(port);
}

@Override
public void setRumble(org.teamtators.rotator.operatorInterface.RumbleType type, float value) {
switch (type) {
case LEFT:
setRumble(RumbleType.kLeftRumble, value);
break;
case RIGHT:
setRumble(RumbleType.kRightRumble, value);
Copy link
Contributor

Choose a reason for hiding this comment

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

break?

break;
}
}

@Override
public double getAxisValue(Axis axisKind) {
return getRawAxis(axisKind.getAxisNumber());
Expand Down