Skip to content

Commit aa438ad

Browse files
committed
Arcade Drive Joystick Demo
New project based on WPILIB
1 parent f24d689 commit aa438ad

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

JoystickDemo/.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<classpath>
2+
<classpathentry kind="src" path="src"/>
3+
<classpathentry kind="var" path="wpilib" sourcepath="wpilib.sources"/>
4+
<classpathentry kind="var" path="networktables" sourcepath="networktables.sources"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

JoystickDemo/.project

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JoystickDemo</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
<nature>edu.wpi.first.wpilib.plugins.core.nature.FRCProjectNature</nature>
17+
</natures>
18+
</projectDescription>

JoystickDemo/build.properties

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Project specific information
2+
package=org.usfirst.frc.team5518.robot
3+
robot.class=${package}.Robot
4+
simulation.world.file=/usr/share/frcsim/worlds/GearsBotDemo.world

JoystickDemo/build.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project name="FRC Deployment" default="deploy">
4+
5+
<!--
6+
The following properties can be defined to override system level
7+
settings. These should not be touched unless you know what you're
8+
doing. The primary use is to override the wpilib version when
9+
working with older robots that can't compile with the latest
10+
libraries.
11+
-->
12+
13+
<!-- By default the system version of WPI is used -->
14+
<!-- <property name="version" value=""/> -->
15+
16+
<!-- By default the system team number is used -->
17+
<!-- <property name="team-number" value=""/> -->
18+
19+
<!-- By default the target is set to 10.TE.AM.2 -->
20+
<!-- <property name="target" value=""/> -->
21+
22+
<!-- Any other property in build.properties can also be overridden. -->
23+
24+
<property file="${user.home}/wpilib/wpilib.properties"/>
25+
<property file="build.properties"/>
26+
<property file="${user.home}/wpilib/java/${version}/ant/build.properties"/>
27+
28+
<import file="${wpilib.ant.dir}/build.xml"/>
29+
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
package org.usfirst.frc.team5518.robot;
3+
4+
5+
import edu.wpi.first.wpilibj.SampleRobot;
6+
import edu.wpi.first.wpilibj.RobotDrive;
7+
import edu.wpi.first.wpilibj.Joystick;
8+
import edu.wpi.first.wpilibj.Timer;
9+
10+
/**
11+
* This is a demo program showing the use of the RobotDrive class.
12+
* The SampleRobot class is the base of a robot application that will automatically call your
13+
* Autonomous and OperatorControl methods at the right time as controlled by the switches on
14+
* the driver station or the field controls.
15+
*
16+
* The VM is configured to automatically run this class, and to call the
17+
* functions corresponding to each mode, as described in the SampleRobot
18+
* documentation. If you change the name of this class or the package after
19+
* creating this project, you must also update the manifest file in the resource
20+
* directory.
21+
*
22+
* WARNING: While it may look like a good choice to use for your code if you're inexperienced,
23+
* don't. Unless you know what you are doing, complex code will be much more difficult under
24+
* this system. Use IterativeRobot or Command-Based instead if you're new.
25+
*/
26+
public class Robot extends SampleRobot {
27+
28+
private static final int FRONT_LEFT_MOTOR = 2;
29+
private static final int REAR_LEFT_MOTOR = 1;
30+
private static final int FRONT_RIGHT_MOTOR = 3;
31+
private static final int REAR_RIGHT_MOTOR = 0;
32+
33+
RobotDrive myRobot;
34+
Joystick stick;
35+
36+
public Robot() { // initialize variables in constructor
37+
myRobot = new RobotDrive(FRONT_LEFT_MOTOR, REAR_LEFT_MOTOR,
38+
FRONT_RIGHT_MOTOR, REAR_RIGHT_MOTOR);
39+
myRobot.setExpiration(0.1);
40+
stick = new Joystick(0);
41+
}
42+
43+
/**
44+
* Drive left & right motors for 2 seconds then stop
45+
*/
46+
public void autonomous() { // function for autonomous mode
47+
myRobot.setSafetyEnabled(false);
48+
myRobot.drive(-0.5, 0.0); // drive forwards half speed
49+
Timer.delay(2.0); // for 2 seconds
50+
myRobot.drive(0.0, 0.0); // stop robot
51+
}
52+
53+
/**
54+
* Runs the motors with arcade steering.
55+
*/
56+
public void operatorControl() { // function for teleop mode
57+
myRobot.setSafetyEnabled(true);
58+
while (isOperatorControl() && isEnabled()) {
59+
myRobot.arcadeDrive(stick); // drive with arcade style (use right stick)
60+
Timer.delay(0.005); // wait for a motor update time
61+
}
62+
}
63+
64+
/**
65+
* Runs during test mode
66+
*/
67+
public void test() {
68+
69+
}
70+
}

JoystickDemo/sysProps.xml

5.96 KB
Binary file not shown.

0 commit comments

Comments
 (0)