summaryrefslogtreecommitdiff
path: root/FakeRobot/src/livewindowfakerobot/LiveWindowFakeRobot.java
blob: 32666bf1f9f69628e0a451f4ed27c35883e5c0c0 (plain)
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

package livewindowfakerobot;

import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.tables.ITable;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author Sam
 */
public class LiveWindowFakeRobot {
    
    private static final NetworkTable liveWindow = NetworkTable.getTable("LiveWindow");
    
    private static final ITable STATUS          = createTable(liveWindow, "~STATUS~", "LW Status"), 
            
                                wrist           = createTable(liveWindow, "Wrist", "LW Subsystem"),
                                wPotentiometer  = createTable(wrist, "Potentiometer", "Analog Input"),
                                wVictor         = createTable(wrist, "Victor", "Speed Controller"), 

                                elevator        = createTable(liveWindow, "Elevator", "PIDSubsystem"), 
                                ePotentiometer  = createTable(elevator, "Potentiometer", "Analog Input"), 
                                eVictor         = createTable(elevator, "Victor", "Speed Controller"),
            
                                testSys         = createTable(liveWindow, "TestSystem", "LW Subsystem"), 
                                tComp           = createTable(testSys, "Compressor", "Compressor"), 
                                tGearTooth      = createTable(testSys, "Gear Tooth Sensor", "Gear Tooth"), 
                                tVictor         = createTable(testSys, "Victor", "Speed Controller"), 
                                tPotentiometer  = createTable(testSys, "Potentiometer", "Analog Input"), 
                                tRelay          = createTable(testSys, "Spike", "Relay"), 
                                tDigitalOutput  = createTable(testSys, "Digital Output", "Digital Output"), 
                                tGyro           = createTable(testSys, "Gyro", "LWGyro"), 
                                tSolenoid       = createTable(testSys, "Solenoid", "Solenoid"), 
                                tServo          = createTable(testSys, "Serov the Servo", "Servo"), 
                                tAccel          = createTable(testSys, "Accelerometer", "Accelerometer"), 
                                tEncoder1       = createTable(testSys, "Encoder 1", "Encoder"), 
                                tUltra          = createTable(testSys, "Ultrasonic", "Ultrasonic"), 
                                tCompass        = createTable(testSys, "Compass", "Compass"), 
                                tSwitch         = createTable(testSys, "Limit Switch", "Digital Input"),
            
                                canSystem       = createTable(liveWindow, "CAN Subsystem", "LW Subsystem"),
                                canJag          = createTable(canSystem, "CAN Jaguar", "CANSpeedController"),
                                canTalon        = createTable(canSystem, "CAN Talon", "CANSpeedController");
    
    public static void main(String[] args) {
        
        System.out.println();
        
        STATUS.putBoolean("LW Enabled", true);
        STATUS.putString("Robot", "Testing");
        wPotentiometer.putNumber("Value", 2.6);
        ePotentiometer.putNumber("Value", -11.6872);
        tSwitch.putString("Value", "Off");
        
        elevator.putNumber("p", 0.5);
        elevator.putNumber("i", 0.5);
        elevator.putNumber("d", 0.5);
        elevator.putNumber("f", 0.5);
        elevator.putNumber("setpoint", 0.5);
        elevator.putBoolean("enabled", false);
        
        canJag.putString("Type", "CANJaguar");
        canTalon.putString("Type", "CANTalon");
        
        
        (new Timer()).schedule(
            new TimerTask(){
                @Override
                public void run() {
                    wPotentiometer.putNumber("Value", (Math.random()-.5) * 24);
                    ePotentiometer.putNumber("Value", (Math.random()-.5) * 24);
                    tPotentiometer.putNumber("Value", (Math.random()-.5) * 24);
                    tGyro.putNumber("Value", Math.random() * 360);
                    tAccel.putNumber("Value", (Math.random()-.5)*8);
                    tSwitch.putString("Value", Math.random() < 0.5 ? "On" : "Off");
                    tEncoder1.putNumber("Speed", Math.random() * 20);
                    tEncoder1.putNumber("Distance", Math.random() * 10);
                    tEncoder1.putNumber("Distance per Tick", Math.random());
                    tCompass.putNumber("Value", Math.random());
                    tUltra.putNumber("Value", (Math.random()-.5) * 200);
                    tGearTooth.putNumber("Value", (int)(Math.random() * 100));
                }}, 
            0, 500);
        
    }
    
    private static ITable createTable(ITable parent, String name, String type) {
        ITable table = parent.getSubTable(name);
        System.out.println(table);
        table.putString("~TYPE~", type);
        table.putString("Name", name);
        return table;
    }
}