-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logging2.java
120 lines (95 loc) · 3.55 KB
/
Logging2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package frc.robot;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
@SuppressWarnings("deprecation")
public class Robot extends SampleRobot
{
DifferentialDrive robotDrive;
Talon motorLeft, motorRight;
Joystick stick;
/**
* Constructor. Called once when this class is created.
*/
public Robot()
{
System.out.println("Robot.constructor()");
// Set up our custom logger.
try
{
Logging.CustomLogger.setup();
}
catch (Throwable e) { Logging.logException(e); }
Logging.consoleLog();
}
/**
* Called once after class load complete.
* Use to perform any needed initializations.
* Very similar to the constructor.
*/
public void robotInit()
{
Logging.consoleLog();
// Create two PWM Talon motor controller objects for left & right motors on PWM ports 0 & 1.
// Assumes robot has two motors controlled by Talon controllers connected via PWM.
// Add them to a drive controller class that can do tank and arcade driving based on
// joystick input.
motorLeft = new Talon(0);
motorRight = new Talon(1);
robotDrive = new DifferentialDrive(motorLeft, motorRight);
robotDrive.setExpiration(0.1); // need to see motor input at least every
// 10th of a second or stop motors.
// One side has motors reversed so the wheels turn in the same direction.
robotDrive.setRightSideInverted(false);
stick = new Joystick(0); // joystick on usb port 0.
}
/**
* Executes a simple autonomous program.
* Called by the driver station or field control system at the
* start of the autonomous period.
*/
public void autonomous()
{
Logging.consoleLog();
robotDrive.setSafetyEnabled(false); // motor safety off due to the fact
// we want the motor to run 2 sec
// with no other input.
robotDrive.tankDrive(0.5, 0.5); // drive forwards half speed
Timer.delay(2.0); // for 2 seconds.
robotDrive.tankDrive(0.0, 0.0); // stop motors.
}
/**
* Runs the motors with arcade steering, input from joystick.
* Called by the driver station or field control system at the
* start of the operator control (teleop) period. Runs in a loop
* until robot is disabled.
*/
public void operatorControl()
{
Logging.consoleLog();
robotDrive.setSafetyEnabled(true); // motor safety back on.
Looging.consoleLog("log some information I am interested in");
while (isOperatorControl() && isEnabled())
{
robotDrive.arcadeDrive(-stick.getX(), stick.getY()); // drive with arcade style.
Timer.delay(0.020); // wait for a joystick update.
}
}
/**
* Called whenever the robot is disabled by the DS or field control.
* Use to perform any needed resets or changes when switching between modes.
*/
public void disabled()
{
Logging.consoleLog();
}
/**
* Runs during test mode
*/
public void test()
{
Logging.consoleLog("Robot.test()");
}
}