Skip to content

Commit ee948d4

Browse files
committed
Enable follower mode for Talons
1 parent eb944a8 commit ee948d4

File tree

5 files changed

+92
-2
lines changed

5 files changed

+92
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
id 'net.ltgt.apt-idea' version '0.15'
77
}
88

9-
version = '18.1.6'
9+
version = '18.1.7'
1010

1111
repositories {
1212
jcenter()

src/main/java/org/strykeforce/thirdcoast/telemetry/tct/talon/config/ConfigMenuModule.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ public static Menu configMenu(
4545
@Named("TALON_CONFIG")
4646
public abstract Command selectOperatingModeCommand(SelectOperatingModeCommand command);
4747

48+
@Binds
49+
@IntoSet
50+
@Named("TALON_CONFIG")
51+
public abstract Command followCommand(FollowCommand command);
52+
4853
@Binds
4954
@IntoSet
5055
@Named("TALON_CONFIG")
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.strykeforce.thirdcoast.telemetry.tct.talon.config;
2+
3+
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import javax.inject.Inject;
7+
import org.jline.reader.EndOfFileException;
8+
import org.jline.reader.LineReader;
9+
import org.jline.reader.UserInterruptException;
10+
import org.strykeforce.thirdcoast.telemetry.tct.Messages;
11+
import org.strykeforce.thirdcoast.telemetry.tct.talon.TalonSet;
12+
13+
public class FollowCommand extends AbstractTalonConfigCommand {
14+
15+
public static final String NAME = "Set Talon Follower";
16+
17+
@Inject
18+
public FollowCommand(LineReader reader, TalonSet talonSet) {
19+
super(NAME, reader, talonSet);
20+
}
21+
22+
@Override
23+
public void perform() {
24+
int[] values = getFollowerMasterPair();
25+
if (values == null) {
26+
return;
27+
}
28+
try {
29+
TalonSRX follower = talonSet.get(values[0]).orElseThrow(IllegalArgumentException::new);
30+
TalonSRX master = talonSet.get(values[1]).orElseThrow(IllegalArgumentException::new);
31+
follower.follow(master);
32+
} catch (IllegalArgumentException e) {
33+
terminal
34+
.writer()
35+
.println(Messages.bold("\nOne or both Talons missing: " + Arrays.toString(values)));
36+
}
37+
}
38+
39+
private int[] getFollowerMasterPair() {
40+
terminal.writer().println(Messages.bold("\nenter <follower>,<master> TalonSRX ids"));
41+
int[] values = null;
42+
while (values == null) {
43+
String line;
44+
try {
45+
line = reader.readLine(prompt()).trim();
46+
} catch (EndOfFileException | UserInterruptException e) {
47+
break;
48+
}
49+
50+
if (line.isEmpty()) {
51+
logger.info("{}: no value entered", name());
52+
break;
53+
}
54+
55+
List<String> entries = Arrays.asList(line.split(","));
56+
int[] ints = new int[2];
57+
try {
58+
if (entries.size() > 0) {
59+
ints[0] = Integer.valueOf(entries.get(0));
60+
} else {
61+
help();
62+
continue;
63+
}
64+
if (entries.size() > 1) {
65+
ints[1] = Integer.valueOf(entries.get(1));
66+
} else {
67+
help();
68+
continue;
69+
}
70+
} catch (NumberFormatException nfe) {
71+
help();
72+
continue;
73+
}
74+
values = ints;
75+
}
76+
return values;
77+
}
78+
79+
private void help() {
80+
terminal
81+
.writer()
82+
.println(Messages.boldRed("please enter two TalonSRX ids separated by a commma"));
83+
}
84+
}

src/main/resources/org/strykeforce/thirdcoast/telemetry/tct/menu.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ TALON = [
1919

2020
TALON_CONFIG = [
2121
"org.strykeforce.thirdcoast.telemetry.tct.talon.config.SelectOperatingModeCommand",
22+
"org.strykeforce.thirdcoast.telemetry.tct.talon.config.FollowCommand",
2223
"org.strykeforce.thirdcoast.telemetry.tct.talon.config.ClosedLoopConfigCommand",
2324
"org.strykeforce.thirdcoast.telemetry.tct.talon.config.OutputConfigCommand",
2425
"org.strykeforce.thirdcoast.telemetry.tct.talon.config.EncoderConfigCommand",

tct.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id="tct" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="18.1.6" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id="tct" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="18.1.7" type="JAVA_MODULE" version="4">
33
<component name="NewModuleRootManager">
44
<output url="file://$MODULE_DIR$/out/production/classes" />
55
<output-test url="file://$MODULE_DIR$/out/test/classes" />

0 commit comments

Comments
 (0)