Ejemplo n.º 1
0
 def command_button_analyze(self):
     logger = logging.getLogger('gui_multiples.command_button_analyze')
     logger.setLevel(logging.INFO)
     file_counter = 0
     for filename in self.filepath_open:
         file_counter += 1
         logger.info("Analyzing data of the file #%d of %d: %s." % (file_counter, len(self.filepath_open), filename))
         data_analyzer.analyze_data(filename, self.filepath_save)
    def run(self):

        # Initialize networktables
        team = ""
        while team == "":
            team = input("Enter team number or 'sim': ")

        if team == "sim":
            NetworkTables.initialize(server="localhost")
        else:
            NetworkTables.startClientTeam(int(team))

        # Use listeners to receive the data
        NetworkTables.addConnectionListener(self.connectionListener,
                                            immediateNotify=True)
        NetworkTables.addEntryListener(self.valueChanged)

        # Wait for a connection notification, then continue on the path
        print("Waiting for NT connection..")
        while True:
            if self.queue.get() == "connected":
                break

        print("Connected!")
        print()

        autonomous = [
            # name, initial speed, ramp
            ("slow-forward", 0, 0.001),
            ("slow-backward", 0, -0.001),
            ("fast-forward", abs(ROBOT_FAST_SPEED), 0),
            ("fast-backward", -abs(ROBOT_FAST_SPEED), 0),
        ]

        stored_data = {}

        #
        # Wait for the user to cycle through the 4 autonomus modes
        #

        for i, (name, initial_speed, ramp) in enumerate(autonomous):

            # Initialize the robot commanded speed to 0
            self.autospeed = 0
            self.discard_data = True

            print()
            print("Autonomous %d/%d: %s" % (i + 1, len(autonomous), name))
            print()
            print("Please enable the robot in autonomous mode.")
            print()
            print(
                "WARNING: It will not automatically stop moving, so disable the robot"
            )
            print("before it hits something!")
            print("")

            # Wait for robot to signal that it entered autonomous mode
            with self.lock:
                self.lock.wait_for(lambda: self.mode == "auto")

            data = self.wait_for_stationary()
            if data is not None:
                if data in ("connected", "disconnected"):
                    print(
                        "ERROR: NT disconnected, results won't be reliable. Giving up."
                    )
                    return
                else:
                    print(
                        "Robot exited autonomous mode before data could be sent?"
                    )
                    break

            # Ramp the voltage at the specified rate
            data = self.ramp_voltage_in_auto(initial_speed, ramp)
            if data in ("connected", "disconnected"):
                print(
                    "ERROR: NT disconnected, results won't be reliable. Giving up."
                )
                return

            # output sanity check
            if len(data) < 3:
                print(
                    "WARNING: There wasn't a lot of data received during that last run"
                )
            else:
                left_distance = data[-1][L_ENCODER_P_COL] - data[0][
                    L_ENCODER_P_COL]
                right_distance = data[-1][R_ENCODER_P_COL] - data[0][
                    R_ENCODER_P_COL]

                print()
                print("The robot reported traveling the following distance:")
                print()
                print("Left:  %.3f ft" % left_distance)
                print("Right: %.3f ft" % right_distance)
                print()
                print(
                    "If that doesn't seem quite right... you should change the encoder calibration"
                )
                print("in the robot program or fix your encoders!")

            stored_data[name] = data

        # In case the user decides to re-enable autonomous again..
        self.autospeed = 0

        #
        # We have data! Do something with it now
        #
        # Write it to disk first, in case the processing fails for some reason
        # -> Using JSON for simplicity, maybe add csv at a later date

        now = time.strftime("%Y%m%d-%H%M-%S")
        fname = "%s-data.json" % now

        print()
        print("Data collection complete! saving to %s..." % fname)
        with open(fname, "w") as fp:
            json.dump(stored_data, fp, indent=4, separators=(",", ": "))

        analyze_data(stored_data)
Ejemplo n.º 3
0
 def command_button_analyze(self):
     data_analyzer.analyze_data(self.filepath_open, self.filepath_save)
Ejemplo n.º 4
0
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeRegressor
from data_analyzer import analyze_data
x = []
y = []

for i in range(100):
    x.append(i)
    y.append(i)

# X = np.array(x)
# Y = np.array(y)

# X = X.reshape(-1, 1)
X = analyze_data()
Y = X.iloc[:, 12]

cc = list(combinations(X.iloc[0:11], 11))
print(len(cc))

indexes = []
indexes.append(cc[0][0])
indexes.append(cc[0][0])

x_smol = X[indexes]

# print(x_smol)
cross_val = KFold(10, True, 1)

print(cross_val)