Пример #1
0
 def testPeriodic(self):
     """
 This method is not called during competition.
 You can put test code in here that is tested from driver station.
 """
     self.pdp = PowerDistributionPanel(0)
     self.pdp.clearStickyFaults()
     self.compressor.clearAllPCMStickyFaults()
Пример #2
0
    def __init__(self):
        super().__init__(name="Climber")

        self.trigger = Servo(4)
        self.trigger.set(0)

        self.climb_victor1 = VictorSP(2)
        self.climb_victor2 = VictorSP(3)

        self.climb_pdp_port1 = 2
        self.climb_pdp_port2 = 3

        self.pdp = PowerDistributionPanel()
Пример #3
0
class SendData():
    def init(self):
        self.dashboard = NetworkTables.getTable("SmartDashboard")
        self.pdp = PowerDistributionPanel(ports.miscPorts.get("pdp"))

    def sendDriveData(self, speed, rotation):
        self.dashboard.putNumber("RobotSpeed", speed)
        self.dashboard.putNumber("RobotRotation", rotation)

    def sendPDPData(self):
        self.dashboard.putNumber("PDPCurrent", self.pdp.getTotalCurrent())
        self.dashboard.putNumber("PDPTemperature", self.pdp.getTemperature())
        self.dashboard.putNumber("PDPVoltage", self.pdp.getVoltage())
Пример #4
0
class Robot(CommandBasedRobot):
    def robotInit(self):
        Command.getRobot = lambda x=0: self
        """Run when the robot turns on."""
        # Update constants from json file on robot
        if self.isReal():
            Constants.updateConstants()
        # Initialize drive objects
        drive.Drive().init()
        # The PDP
        self.pdp = PDP(Constants.PDP_ID)
        # Robot odemetry command
        self.updateodemetry = updateodemetry.UpdateOdemetry()
        # Set command group member variables
        self.autonomous = autogroup.AutonomousCommandGroup()
        self.disabled = disabledgroup.DisabledCommandGroup()
        self.disabled.setRunWhenDisabled(True)
        self.teleop = teleopgroup.TeleopCommandGroup()
        self.test = testgroup.TestCommandGroup()
        # Start the camera sever
        CameraServer.launch()

    def globalInit(self):
        """Run on every init."""
        self.updateodemetry.start()

    def disabledInit(self):
        """Run when robot enters disabled mode."""
        self.globalInit()
        self.disabled.start()

    def autonomousInit(self):
        """Run when the robot enters auto mode."""
        self.globalInit()
        self.autonomous.start()

    def teleopInit(self):
        """Run when the robot enters teleop mode."""
        self.globalInit()
        self.teleop.start()

    def testInit(self):
        """Run when the robot enters test mode."""
        self.globalInit()
        self.test.start()

    def outputToSmartDashboard(self):
        Dash.putNumber("Total Current", self.pdp.getTotalCurrent())
        for i in range(16):
            Dash.putNumber("Channel {} Current".format(i),
                           self.pdp.getCurrent(i))
Пример #5
0
class PowerElectronics(object):
    pdp: PowerDistributionPanel

    def __init__(self, channels):
        self.pdp = PowerDistributionPanel(module=0)
        # self.channels = channels

        self.temperature = self.pdp.getTemperature()
        self.voltage = self.pdp.getVoltage()

    def basic_update(self):
        self.temperature = self.pdp.getTemperature()
        self.voltage = self.pdp.getVoltage()

    def check_current(self, channel: int):
        self.basic_update()
        return self.pdp.getCurrent(channel=channel)
Пример #6
0
class Climber(Subsystem):
    def __init__(self):
        super().__init__(name="Climber")

        self.trigger = Servo(4)
        self.trigger.set(0)

        self.climb_victor1 = VictorSP(2)
        self.climb_victor2 = VictorSP(3)

        self.climb_pdp_port1 = 2
        self.climb_pdp_port2 = 3

        self.pdp = PowerDistributionPanel()

    def close_gate(self):
        self.trigger.set(0)

    def open_gate(self):
        self.trigger.set(0.5)

    def active_climber(self, climb_power):
        self.climb_victor1.set(climb_power)
        self.climb_victor2.set(climb_power)

    def inactive_climber(self):
        self.climb_victor1.set(0)
        self.climb_victor2.set(0)

    def check_continuous_faults(self):
        """
        Check if the system is faulted.

        For the climber, we are interested in whether the versa dual-input has failed.
        :return:
        """

        master_current = self.pdp.getCurrent(self.climb_pdp_port1)
        slave_current = self.pdp.getCurrent(self.climb_pdp_port2)
        ref = master_current
        if ref == 0:
            ref = slave_current
        if ref == 0:
            ref = 1
        eps = 1e-1
        return False  # (master_current > eps or slave_current > eps) and abs(master_current - slave_current) / ref < 1
Пример #7
0
 def __init__(self):
     self.pdp = PDP(Constants.PDP_ID)
     self.diagnostic_table = NetworkTables.getTable(
         "SmartDashboard").getSubTable("Diagnostic")
     self.pdp_table = self.diagnostic_table.getSubTable("PDP")
     self.roborio_table = self.diagnostic_table.getSubTable("roboRIO")
     self.data = {}
     self.pdp_logfile = None
     self.roborio_logfile = None
Пример #8
0
def init():
    global drive_left_encoder, drive_right_encoder, elevator_encoder, gyro, back_photosensor, side_photosensor, pdp
    drive_left_encoder = Encoder(6, 7)
    drive_left_encoder.setDistancePerPulse(_drive_encoder_scale())

    drive_right_encoder = Encoder(4, 5)
    drive_right_encoder.setDistancePerPulse(_drive_encoder_scale())

    elevator_encoder = Encoder(0, 1, True)
    elevator_encoder.setDistancePerPulse(_elevator_encoder_scale())

    gyro = Gyro(0)

    back_photosensor = DigitalInput(8)
    side_photosensor = DigitalInput(3)
    pdp = PowerDistributionPanel()
Пример #9
0
    def __init__(self):
        super().__init__("Intake")

        self.talon_left = Talon(0)
        self.talon_right = Talon(1)

        self.solenoid_lift = DoubleSolenoid(0, 1)
        self.solenoid_grab = DoubleSolenoid(2, 3)
        self.set_grab_state(GrabState.IN)
        self.set_arm_state(ArmState.UP)

        self.power = .75

        self.in_sensor = AnalogInput(0)
        dashboard2.add_graph("Ultrasonic", self.get_reported_distance)

        self.pdp = PowerDistributionPanel()
        self.l_channel = 0
        self.r_channel = 1
Пример #10
0
 def robotInit(self):
     Command.getRobot = lambda x=0: self
     """Run when the robot turns on."""
     # Update constants from json file on robot
     if self.isReal():
         Constants.updateConstants()
     # Initialize drive objects
     drive.Drive().init()
     # The PDP
     self.pdp = PDP(Constants.PDP_ID)
     # Robot odemetry command
     self.updateodemetry = updateodemetry.UpdateOdemetry()
     # Set command group member variables
     self.autonomous = autogroup.AutonomousCommandGroup()
     self.disabled = disabledgroup.DisabledCommandGroup()
     self.disabled.setRunWhenDisabled(True)
     self.teleop = teleopgroup.TeleopCommandGroup()
     self.test = testgroup.TestCommandGroup()
     # Start the camera sever
     CameraServer.launch()
Пример #11
0
class Diagnostic:
    def __init__(self):
        self.pdp = PDP(Constants.PDP_ID)
        self.diagnostic_table = NetworkTables.getTable(
            "SmartDashboard").getSubTable("Diagnostic")
        self.pdp_table = self.diagnostic_table.getSubTable("PDP")
        self.roborio_table = self.diagnostic_table.getSubTable("roboRIO")
        self.data = {}
        self.pdp_logfile = None
        self.roborio_logfile = None

    def log(self):
        timestamp = RC.getFPGATime()
        self.logPDP(timestamp)
        self.logroboRIO(timestamp)

    def logPDP(self, timestamp):
        self.pdp_logfile.writerow([timestamp] +
                                  list(self.data["PDP"].values()))

    def logroboRIO(self, timestamp):
        self.roborio_logfile.writerow([timestamp] +
                                      list(self.data["roboRIO"].values()))

    def outputToSmartDashboard(self):
        self.outputPDP()
        self.outputroboRIO()

    def outputPDP(self):
        for key, value in self.data["PDP"].items():
            self._putData(self.pdp_table, key, value)

    def outputroboRIO(self):
        for key, value in self.data["roboRIO"].items():
            self._putData(self.roborio_table, key, value)

    def _putData(self, table, key, value):
        if isinstance(value, (int, float)):
            self.roborio_table.putNumber(key, value)
        elif isinstance(value, str):
            self.roborio_table.putString(key, value)
        elif isinstance(value, bool):
            self.roborio_table.putBoolean(key, value)

    def update(self):
        self.updatePDP()
        self.updateroboRIO()
        if self.pdp_logfile == None:
            self.pdp_logfile = csv.writer(open("/home/lvuser/pdp.csv", 'w'))
            self.pdp_logfile.writerow(["FPGATime"] +
                                      list(self.data["PDP"].keys()))
        if self.roborio_logfile == None:
            self.roborio_logfile = csv.writer(
                open("/home/lvuser/roborio.csv", 'w'))
            self.roborio_logfile.writerow(["FPGATime"] +
                                          list(self.data["roboRIO"].keys()))

    def updatePDP(self):
        self.data["PDP"] = {}
        self.data["PDP"]["Total Current"] = self.pdp.getTotalCurrent()
        for i in range(16):
            self.data["PDP"][f"Channel {i} Current"] = self.pdp.getCurrent(i)
        self.data["PDP"]["Input Voltage"] = self.pdp.getVoltage()

    def updateroboRIO(self):
        self.data["roboRIO"] = {}
        self.data["roboRIO"]["Battery Voltage"] = RC.getBatteryVoltage()
        self.data["roboRIO"]["Current 3.3V Rail"] = RC.getCurrent3V3()
        self.data["roboRIO"]["Current 5V Rail"] = RC.getCurrent5V()
        self.data["roboRIO"]["Current 6V Rail"] = RC.getCurrent6V()
        self.data["roboRIO"]["Enabled 3.3V Rail"] = RC.getEnabled3V3()
        self.data["roboRIO"]["Enabled 5V Rail"] = RC.getEnabled5V()
        self.data["roboRIO"]["Enabled 6V Rail"] = RC.getEnabled6V()
        self.data["roboRIO"]["Fault Count 3.3V Rail"] = RC.getFaultCount3V3()
        self.data["roboRIO"]["Fault Count 5V Rail"] = RC.getFaultCount5V()
        self.data["roboRIO"]["Fault Count 6V Rail"] = RC.getFaultCount6V()
        self.data["roboRIO"]["Input Current"] = RC.getInputCurrent()
        self.data["roboRIO"]["Input Voltage"] = RC.getInputVoltage()
        self.data["roboRIO"]["Voltage 3.3V Rail"] = RC.getVoltage3V3()
        self.data["roboRIO"]["Voltage 5V Rail"] = RC.getVoltage5V()
        self.data["roboRIO"]["Voltage 6V Rail"] = RC.getVoltage6V()
        self.data["roboRIO"]["Is Browned Out"] = RC.isBrownedOut()
        self.data["roboRIO"]["Is System Active"] = RC.isSysActive()
Пример #12
0
    def __init__(self, channels):
        self.pdp = PowerDistributionPanel(module=0)
        # self.channels = channels

        self.temperature = self.pdp.getTemperature()
        self.voltage = self.pdp.getVoltage()
Пример #13
0
 def init(self):
     self.dashboard = NetworkTables.getTable("SmartDashboard")
     self.pdp = PowerDistributionPanel(ports.miscPorts.get("pdp"))
Пример #14
0
class Robot(TimedRobot):
    """
  Command-based robots inherit from the TimedRobot class.
  """
    def robotInit(self):
        """
    This function is run when the robot is first started up and should be 
    used for any initialization code.
    """
        self.compressor = Compressor()
        self.compressor.setClosedLoopControl(True)
        robotsubsystems.init()
        oi.init()

    def robotPeriodic(self):
        """
    This function is called every robot packet, no matter the mode. Use
    this for items like diagnostics that you want ran during disabled,
    autonomous, teleoperated and test.
   
    This runs after the mode specific periodic functions, but before
    LiveWindow and SmartDashboard integrated updating.
    """
        pass

    def disabledInit(self):
        """
    This function is called once each time the robot enters Disabled mode.
    You can use it to reset any subsystem information you want to clear when 
    the robot is disabled.
    """
        pass

    def disabledPeriodic(self):
        """
    This function is repeatedly while the robot is in Disabled mode. 
    You generally will not need to alter this method.
    """
        Scheduler.getInstance().run()

    def autonomousInit(self):
        """
    This method is called once at the start of autonomous.
    Put anything in this method that needs to happen when autonomous starts.
    """
        pass

    def autonomousPeriodic(self):
        """
    This function is called periodically during autonomous.
    You generally will not need to alter this method.
    """
        Scheduler.getInstance().run()

    def teleopInit(self):
        """
    This method is called once at the start of teleop.
    Put anything in this method that needs to happen when teleop starts.
    """
        pass

    def teleopPeriodic(self):
        """
    This function is called periodically during teleop.
    You generally will not need to alter this method.
    """
        Scheduler.getInstance().run()

    def testPeriodic(self):
        """
    This method is not called during competition.
    You can put test code in here that is tested from driver station.
    """
        self.pdp = PowerDistributionPanel(0)
        self.pdp.clearStickyFaults()
        self.compressor.clearAllPCMStickyFaults()