Skip to content

Commit b36ef50

Browse files
committed
Issue 95 - Added support for the Spark motor controller
1 parent c827eb9 commit b36ef50

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

strongback/src/org/strongback/hardware/Hardware.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import edu.wpi.first.wpilibj.Joystick;
5959
import edu.wpi.first.wpilibj.PowerDistributionPanel;
6060
import edu.wpi.first.wpilibj.SPI;
61+
import edu.wpi.first.wpilibj.Spark;
6162
import edu.wpi.first.wpilibj.Talon;
6263
import edu.wpi.first.wpilibj.Ultrasonic;
6364
import edu.wpi.first.wpilibj.Victor;
@@ -692,6 +693,29 @@ public static TalonSRX talonSRX(int deviceNumber, TalonSRX leader, boolean rever
692693
talon.reverseOutput(reverse);
693694
return talonSRX(talon, 0.0d, 0.0d);
694695
}
696+
697+
/**
698+
* Create a motor driven by a <a href="http://www.revrobotics.com/SPARK">RevRobotics Spark Motor Controller</a> on the
699+
* specified channel. The speed output is limited to [-1.0,1.0] inclusive.
700+
*
701+
* @param channel the channel the controller is connected to
702+
* @return a motor on the specified channel
703+
*/
704+
public static Motor spark(int channel) {
705+
return spark(channel, SPEED_LIMITER);
706+
}
707+
708+
/**
709+
* Create a motor driven by a <a href="http://www.revrobotics.com/SPARK">RevRobotics Spark Motor Controller</a> on the
710+
* specified channel, with a custom speed limiting function.
711+
*
712+
* @param channel the channel the controller is connected to
713+
* @param speedLimiter function that will be used to limit the speed (input voltage); may not be null
714+
* @return a motor on the specified channel
715+
*/
716+
public static Motor spark(int channel, DoubleToDoubleFunction speedLimiter) {
717+
return new HardwareSpark(new Spark(channel), SPEED_LIMITER);
718+
}
695719
}
696720

697721
/**

strongback/src/org/strongback/hardware/HardwareMotor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @see Hardware
3131
* @see edu.wpi.first.wpilibj.SpeedController
3232
*/
33-
final class HardwareMotor implements Motor {
33+
class HardwareMotor implements Motor {
3434

3535
private final SpeedController controller;
3636
private final DoubleToDoubleFunction speedValidator;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Strongback
3+
* Copyright 2017, Strongback and individual contributors by the @authors tag.
4+
* See the COPYRIGHT.txt in the distribution for a full listing of individual
5+
* contributors.
6+
*
7+
* Licensed under the MIT License; you may not use this file except in
8+
* compliance with the License. You may obtain a copy of the License at
9+
* http://opensource.org/licenses/MIT
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.strongback.hardware;
18+
19+
import org.strongback.annotation.Immutable;
20+
import org.strongback.function.DoubleToDoubleFunction;
21+
22+
import edu.wpi.first.wpilibj.SpeedController;
23+
24+
/**
25+
* RevRobotics Spark motor controller.
26+
*
27+
* @author Randall Hauch
28+
*/
29+
@Immutable
30+
class HardwareSpark extends HardwareMotor {
31+
32+
HardwareSpark(SpeedController controller, DoubleToDoubleFunction speedValidator ) {
33+
super(controller,speedValidator);
34+
}
35+
}

0 commit comments

Comments
 (0)