mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Added support for CAN Talon SRX in C++ and Java.
Currently, the JNI bindings are generated by Swig and, unfortunately, the interface available through Java is lower-level than that for C++ (ie, direct access to the ctre code through the JNI bindings, rather than an interface on top of that), but it does work. See eclipse plugins for some short samples. There are a couple of short unit tests as placeholders. Still needs some cleaning up. Change-Id: Iae2f74693ca6b80bf7d5aca0625c66aa6e0b7f85 Added quick samples for C++/Java CAN Talon stuff. Change-Id: I3acb27d6fd5568d88931e0d678c09973d436735d
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package $package;
|
||||
|
||||
|
||||
import edu.wpi.first.wpilibj.SpeedController;
|
||||
import edu.wpi.first.wpilibj.hal.CanTalonSRX;
|
||||
import edu.wpi.first.wpilibj.SampleRobot;
|
||||
import edu.wpi.first.wpilibj.Timer;
|
||||
|
||||
/**
|
||||
* This is a short sample program demonstrating how to use the basic throttle
|
||||
* mode of the new CAN Talon. As of when this was made, the basic throttle mode
|
||||
* is all that is supported.
|
||||
*/
|
||||
public class Robot extends SampleRobot {
|
||||
|
||||
CanTalonSRX motor;
|
||||
|
||||
private final double k_updatePeriod = 0.005; // update every 0.005 seconds/5 milliseconds (200Hz)
|
||||
|
||||
public Robot() {
|
||||
motor = new CanTalonSRX(1); // Initialize the CanTalonSRX on device 1.
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the motor from a joystick.
|
||||
*/
|
||||
public void operatorControl() {
|
||||
motor.SetModeSelect(0);
|
||||
while (isOperatorControl() && isEnabled()) {
|
||||
// Set the motor's output.
|
||||
// This takes a number from -1 (100% speed in reverse) to +1 (100% speed
|
||||
// going forward)
|
||||
motor.Set(0.5);
|
||||
|
||||
Timer.delay(k_updatePeriod); // wait 5ms to the next update
|
||||
}
|
||||
motor.Set(0.0);
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,23 @@
|
||||
</files>
|
||||
</example>
|
||||
|
||||
<example>
|
||||
<name>CAN Talon SRX</name>
|
||||
<description>Demonstrate running a Talon SRX with the basic throttle mode.</description>
|
||||
<tags>
|
||||
<tag>Actuators</tag>
|
||||
<tag>Complete List</tag>
|
||||
<tag>Robot and Motor</tag>
|
||||
</tags>
|
||||
<packages>
|
||||
<package>src/$package-dir</package>
|
||||
</packages>
|
||||
<files>
|
||||
<file source="examples/CANTalon/src/org/usfirst/frc/team190/robot/Robot.java"
|
||||
destination="src/$package-dir/Robot.java"></file>
|
||||
</files>
|
||||
</example>
|
||||
|
||||
|
||||
<tagDescription>
|
||||
<name>CommandBased Robot</name>
|
||||
|
||||
Reference in New Issue
Block a user