Exemplo n.º 1
0
    def __init__(self, robot):

        self.robot = robot

        # Configure drive motors
        self.frontLeftCIM = wpilib.Victor(1)
        self.frontRightCIM = wpilib.Victor(2)
        self.backLeftCIM = wpilib.Victor(3)
        self.backRightCIM = wpilib.Victor(4)
        wpilib.LiveWindow.addActuator("DriveTrain", "Front Left CIM", self.frontLeftCIM)
        wpilib.LiveWindow.addActuator("DriveTrain", "Front Right CIM", self.frontRightCIM)
        wpilib.LiveWindow.addActuator("DriveTrain", "Back Left CIM", self.backLeftCIM)
        wpilib.LiveWindow.addActuator("DriveTrain", "Back Right CIM", self.backRightCIM)

        # Configure the RobotDrive to reflect the fact that all our motors are
        # wired backwards and our drivers sensitivity preferences.
        self.drive = wpilib.RobotDrive(self.frontLeftCIM, self.frontRightCIM, self.backLeftCIM, self.backRightCIM)
        self.drive.setSafetyEnabled(True)
        self.drive.setExpiration(.1)
        self.drive.setSensitivity(.5)
        self.drive.setMaxOutput(1.0)
        self.drive.setInvertedMotor(wpilib.RobotDrive.MotorType.kFrontLeft, True)
        self.drive.setInvertedMotor(wpilib.RobotDrive.MotorType.kFrontRight, True)
        self.drive.setInvertedMotor(wpilib.RobotDrive.MotorType.kRearLeft, True)
        self.drive.setInvertedMotor(wpilib.RobotDrive.MotorType.kRearRight, True)

        # Configure encoders
        self.rightEncoder = wpilib.Encoder(1, 2,
                                           reverseDirection=True,
                                           encodingType=wpilib.Encoder.EncodingType.k4X)
        self.leftEncoder = wpilib.Encoder(3, 4,
                                          reverseDirection=False,
                                          encodingType=wpilib.Encoder.EncodingType.k4X)
        self.rightEncoder.setPIDSourceType(wpilib.Encoder.PIDSourceType.kDisplacement)
        self.leftEncoder.setPIDSourceType(wpilib.Encoder.PIDSourceType.kDisplacement)

        if robot.isReal():
            # Converts to feet
            self.rightEncoder.setDistancePerPulse(0.0785398)
            self.leftEncoder.setDistancePerPulse(0.0785398)
        else:
            # Convert to feet 4in diameter wheels with 360 tick simulated encoders.
            self.rightEncoder.setDistancePerPulse((4*math.pi)/(360*12))
            self.leftEncoder.setDistancePerPulse((4*math.pi)/(360*12))

        wpilib.LiveWindow.addSensor("DriveTrain", "Right Encoder", self.rightEncoder)
        wpilib.LiveWindow.addSensor("DriveTrain", "Left Encoder", self.leftEncoder)

        # Configure gyro
        # -> the original pacgoat example is at channel 2, but that was before WPILib
        #    moved to zero-based indexing. You need to change the gyro channel in
        #    /usr/share/frcsim/models/PacGoat/robots/PacGoat.SDF, from 2 to 0. 
        self.gyro = wpilib.AnalogGyro(0)
        if robot.isReal():
            # TODO: Handle more gracefully
            self.gyro.setSensitivity(0.007)

        wpilib.LiveWindow.addSensor("DriveTrain", "Gyro", self.gyro)

        super().__init__()
Exemplo n.º 2
0
    def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)
        self.rstick = wpilib.Joystick(1)

        self.l_motor = wpilib.Jaguar(1)
        self.r_motor = wpilib.Jaguar(2)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)

        self.drive = wpilib.drive.DifferentialDrive(self.l_motor, self.r_motor)

        self.motor = wpilib.Jaguar(4)

        self.limit1 = wpilib.DigitalInput(1)
        self.limit2 = wpilib.DigitalInput(2)

        self.position = wpilib.AnalogInput(2)

        self.leftEncoder = wpilib.Encoder(0, 1)
        self.leftEncoder.setDistancePerPulse(
            (self.WHEEL_DIAMETER) / self.ENCODER_COUNTS_PER_REV)
        self.leftEncoder.setSimDevice(0)

        self.rightEncoder = wpilib.Encoder(3, 4)
        self.rightEncoder.setDistancePerPulse(
            (self.WHEEL_DIAMETER) / self.ENCODER_COUNTS_PER_REV)
Exemplo n.º 3
0
    def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)
        self.rstick = wpilib.Joystick(1)

        self.l_motor = wpilib.Jaguar(1)
        self.r_motor = wpilib.Jaguar(2)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(0)

        self.drive = wpilib.drive.DifferentialDrive(self.l_motor, self.r_motor)

        self.motor = wpilib.Jaguar(4)

        self.limit1 = wpilib.DigitalInput(1)
        self.limit2 = wpilib.DigitalInput(2)

        self.position = wpilib.AnalogInput(2)
        self.left_encoder = wpilib.Encoder(1, 2)
        self.right_encoder = wpilib.Encoder(3, 4)

        self.kinematics = DifferentialDriveKinematics(TRACK_WIDTH)
        self.chassis_speeds = ChassisSpeeds()
        self.chassis_speeds.vx = 0.0
        self.chassis_speeds.omega = 0.0

        if is_sim:
            self.physics = physics.PhysicsEngine()
            self.last_tm = time.time()
Exemplo n.º 4
0
    def robotInit(self):
        """Robot-wide initialization code should go here"""

        # Basic robot chassis setup
        self.stick = wpilib.Joystick(0)

        # Create a robot drive with two PWM controlled Talon SRXs.

        self.leftMotor = wpilib.PWMTalonSRX(1)
        self.rightMotor = wpilib.PWMTalonSRX(2)

        self.robot_drive = wpilib.drive.DifferentialDrive(
            self.leftMotor, self.rightMotor)

        self.leftEncoder = wpilib.Encoder(0, 1, reverseDirection=False)

        # The right-side drive encoder
        self.rightEncoder = wpilib.Encoder(2, 3, reverseDirection=True)

        # Sets the distance per pulse for the encoders
        self.leftEncoder.setDistancePerPulse((6 * math.pi) / 1024)
        self.rightEncoder.setDistancePerPulse((6 * math.pi) / 1024)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(0)

        # Use PIDController to control angle
        turnController = wpilib.controller.PIDController(
            self.kP, self.kI, self.kD, self.kF)
        turnController.setTolerance(self.kToleranceDegrees)

        self.turnController = turnController

        self.rotateToAngleRate = 0
Exemplo n.º 5
0
    def __init__(self):
        # Mapping object stores port numbers for all connected motors, sensors, and joysticks. See map.py.
        Mapping = Map()

        # Init drivetrain
        self.driveTrain = [wpilib.Spark(Mapping.frontLeftM),
                           wpilib.Spark(Mapping.frontRightM),
                           wpilib.Spark(Mapping.backLeftM),
                           wpilib.Spark(Mapping.backRightM)]

        self.driveTrain[0].setInverted(True)
        self.driveTrain[2].setInverted(True)

        # Init motors
        self.elevatorM = wpilib.Spark(Mapping.elevatorM)
        self.elevatorM.setInverted(True)
        self.winchM = wpilib.Spark(Mapping.winchM)
        self.intakeM = wpilib.Spark(Mapping.intakeM)
        self.jawsM = wpilib.Spark(Mapping.jawsM)

        # Soleniods
        self.jawsSol = wpilib.DoubleSolenoid(Mapping.jawsSol['out'], Mapping.jawsSol['in'])

        # Init sensors
        self.gyroS = wpilib.AnalogGyro(Mapping.gyroS)
        self.elevatorLimitS = wpilib.DigitalInput(Mapping.elevatorLimitS)
        self.jawsLimitS = wpilib.DigitalInput(Mapping.jawsLimitS)
        self.metaboxLimitS = wpilib.DigitalInput(Mapping.metaboxLimitS)

        # Encoders
        self.elevatorEncoderS = wpilib.Encoder(7, 8, True)
        self.elevatorEncoderS.setDistancePerPulse(0.08078)

        self.driveYEncoderS = wpilib.Encoder(2, 3)
        self.driveYEncoderS.setDistancePerPulse(0.015708)
Exemplo n.º 6
0
    def robotInit(self):
        self.leftFront = wpilib.Talon(3)
        self.leftRear = wpilib.Talon(1)
        self.rightFront = wpilib.Talon(4)
        self.rightRear = wpilib.Talon(2)

        # Create motor groups for WPI-style differential driving

        self.leftDrive = wpilib.SpeedControllerGroup(self.leftFront,
                                                     self.leftRear)
        self.rightDrive = wpilib.SpeedControllerGroup(self.rightFront,
                                                      self.rightRear)

        self.drive = wpilib.drive.DifferentialDrive(self.leftDrive,
                                                    self.rightDrive)

        self.controller = wpilib.Joystick(0)

        self.forward = wpilib.buttons.JoystickButton(self.controller,
                                                     PS4Button["TRIANGLE"])
        self.backward = wpilib.buttons.JoystickButton(self.controller,
                                                      PS4Button["CROSS"])
        self.right = wpilib.buttons.JoystickButton(self.controller,
                                                   PS4Button["CIRCLE"])
        self.left = wpilib.buttons.JoystickButton(self.controller,
                                                  PS4Button["SQUARE"])

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 7
0
    def robotInit(self):
        '''Robot initialization function'''
        gyroChannel = 0  # analog input

        self.joystickChannel = 0  # usb number in DriverStation

        # channels for motors
        self.leftMotorChannel = 1
        self.rightMotorChannel = 0
        self.leftRearMotorChannel = 3
        self.rightRearMotorChannel = 2

        self.angleSetpoint = 0.0
        self.pGain = 1  # propotional turning constant

        # gyro calibration constant, may need to be adjusted
        # gyro value of 360 is set to correspond to one full revolution
        self.voltsPerDegreePerSecond = .0128

        self.left = wpilib.SpeedControllerGroup(
            wpilib.Talon(self.leftMotorChannel),
            wpilib.Talon(self.leftRearMotorChannel))
        self.right = wpilib.SpeedControllerGroup(
            wpilib.Talon(self.rightMotorChannel),
            wpilib.Talon(self.rightRearMotorChannel))
        self.myRobot = DifferentialDrive(self.left, self.right)

        self.gyro = wpilib.AnalogGyro(gyroChannel)
        self.joystick = wpilib.Joystick(self.joystickChannel)
Exemplo n.º 8
0
 def robotInit(self):
     #update channels
     self.frontR = wpi.Talon(1)
     self.frontL = wpi.Talon(2)
     self.rearR = wpi.Talon(0)
     self.rearL = wpi.Talon(3)
     self.gyro = wpi.AnalogGyro(0)
     self.joystick = wpi.Joystick(0)
     self.right = wpi.SpeedControllerGroup(self.frontR, self.rearR)
     self.left = wpi.SpeedControllerGroup(self.frontL, self.rearL)
     self.dTrain = wpi.drive.DifferentialDrive(self.right, self.left)
     self.xDeadZone = .05
     self.yDeadZone = .05
     self.xConstant = .55
     self.yConstant = .85
     logging.basicConfig(level=logging.DEBUG)
     NetworkTables.initialize(server='10.28.75.2')
     NetworkTables.addConnectionListener(connectionListener,
                                         immediateNotify=True)
     with cond:
         print("Waiting")
         if not notified[0]:
             cond.wait()
     print("Connected")
     self.table = NetworkTables.getTable('SmartDashboard')
Exemplo n.º 9
0
    def robotInit(self):
        """Robot initialization function"""
        self.frontLeftMotor = wpilib.Talon(self.frontLeftChannel)
        self.rearLeftMotor = wpilib.Talon(self.rearLeftChannel)
        self.frontRightMotor = wpilib.Talon(self.frontRightChannel)
        self.rearRightMotor = wpilib.Talon(self.rearRightChannel)

        # invert the left side motors
        self.frontLeftMotor.setInverted(True)

        # you may need to change or remove this to match your robot
        self.rearLeftMotor.setInverted(True)

        self.drive = MecanumDrive(
            self.frontLeftMotor,
            self.rearLeftMotor,
            self.frontRightMotor,
            self.rearRightMotor,
        )

        self.drive.setExpiration(0.1)

        self.lstick = wpilib.Joystick(self.lStickChannel)
        self.rstick = wpilib.Joystick(self.rStickChannel)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 10
0
    def __init__(self, robot):
        super().__init__("DriveTrain")
        self.robot = robot

        self.front_left_motor = wpilib.Talon(1)
        self.back_left_motor = wpilib.Talon(2)
        self.front_right_motor = wpilib.Talon(3)
        self.back_right_motor = wpilib.Talon(4)

        left_motors = wpilib.SpeedControllerGroup(
            self.front_left_motor, self.back_left_motor
        )
        right_motors = wpilib.SpeedControllerGroup(
            self.front_right_motor, self.back_right_motor
        )
        self.drive = wpilib.drive.DifferentialDrive(left_motors, right_motors)

        self.left_encoder = wpilib.Encoder(1, 2)
        self.right_encoder = wpilib.Encoder(3, 4)

        # Encoders may measure differently in the real world and in
        # simulation. In this example the robot moves 0.042 barleycorns
        # per tick in the real world, but the simulated encoders
        # simulate 360 tick encoders. This if statement allows for the
        # real robot to handle this difference in devices.
        if robot.isReal():
            self.left_encoder.setDistancePerPulse(0.042)
            self.right_encoder.setDistancePerPulse(0.042)
        else:
            # Circumference in ft = 4in/12(in/ft)*PI
            self.left_encoder.setDistancePerPulse((4.0 / 12.0 * math.pi) / 360.0)
            self.right_encoder.setDistancePerPulse((4.0 / 12.0 * math.pi) / 360.0)

        self.rangefinder = wpilib.AnalogInput(6)
        self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 11
0
    def robotInit(self):
        """Robot initialization function"""
        self.frontLeftMotor = wpilib.Talon(self.frontLeftChannel)
        self.rearLeftMotor = wpilib.Talon(self.rearLeftChannel)
        self.frontRightMotor = wpilib.Talon(self.frontRightChannel)
        self.rearRightMotor = wpilib.Talon(self.rearRightChannel)

        self.lstick = wpilib.Joystick(self.lStickChannel)
        self.rstick = wpilib.Joystick(self.rStickChannel)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)

        self.sd = NetworkTables.getTable("SmartDashboard")
        # Setting up Kinematics (an algorithm to determine chassi speed from wheel speed)
        # The 2d Translation tells the algorithm how far off center (in Meter) our wheels are
        # Ours are about 11.3 (x) by 10.11(y) inches off, so this equates to roughly .288 X .257 Meters
        # We use the X and Y Offsets above.

        m_frontLeftLocation = Translation2d(XOffset, YOffset)
        m_frontRightLocation = Translation2d(XOffset, (-1 * YOffset))
        m_backLeftLocation = Translation2d((-1 * XOffset), (YOffset))
        m_backRightLocation = Translation2d((-1 * XOffset), (-1 * YOffset))

        # Creat our kinematics object using the wheel locations.
        self.m_kinematics = MecanumDriveKinematics(
            m_frontLeftLocation,
            m_frontRightLocation,
            m_backLeftLocation,
            m_backRightLocation,
        )
        # Create the Odometry Object
        self.MecanumDriveOdometry = MecanumDriveOdometry(
            self.m_kinematics,
            Rotation2d.fromDegrees(-self.gyro.getAngle()),
            Pose2d(0, 0, Rotation2d(0)),
        )

        self.drive = MecanumDrive(
            self.frontLeftMotor,
            self.rearLeftMotor,
            self.frontRightMotor,
            self.rearRightMotor,
        )
        self.f_l_encoder = wpilib.Encoder(0, 1)
        self.f_l_encoder.setDistancePerPulse(
            (math.pi * self.WHEEL_DIAMETER) / self.ENCODER_COUNTS_PER_REV)

        self.r_l_encoder = wpilib.Encoder(3, 4)
        self.r_l_encoder.setDistancePerPulse(
            (math.pi * self.WHEEL_DIAMETER) / self.ENCODER_COUNTS_PER_REV)

        self.f_r_encoder = wpilib.Encoder(1, 2)
        self.f_r_encoder.setDistancePerPulse(
            (math.pi * self.WHEEL_DIAMETER) / self.ENCODER_COUNTS_PER_REV)

        self.r_r_encoder = wpilib.Encoder(3, 4)
        self.r_r_encoder.setDistancePerPulse(
            (math.pi * self.WHEEL_DIAMETER) / self.ENCODER_COUNTS_PER_REV)
Exemplo n.º 12
0
 def __init__(self, robot, name=None):
     '''Initialize'''
     super().__init__(name=name)
     self.robot = robot
     self.gyro = wpilib.AnalogGyro(1)
     self.left_motor = wpilib.Jaguar(1)
     self.right_motor = wpilib.Jaguar(2)
     self.robot_drive = wpilib.RobotDrive(self.left_motor, self.right_motor)
Exemplo n.º 13
0
    def robotInit(self):
        """This function initiates the robot's components and parts"""

        # Here we create a function for the command class to return the robot
        # instance, so that we don't have to import the robot module for each
        # command.
        Command.getRobot = lambda _: self

        # This launches the camera server between the robot and the computer
        wpilib.CameraServer.launch()

        self.joystick = wpilib.Joystick(0)

        self.lr_motor = ctre.WPI_TalonSRX(1)
        self.lf_motor = ctre.WPI_TalonSRX(2)

        self.rr_motor = ctre.WPI_TalonSRX(5)
        self.rf_motor = ctre.WPI_TalonSRX(6)

        self.left = wpilib.SpeedControllerGroup(self.lf_motor, self.lr_motor)
        self.right = wpilib.SpeedControllerGroup(self.rf_motor, self.rr_motor)

        self.drivetrain_solenoid = wpilib.DoubleSolenoid(2, 3)

        self.drivetrain_gyro = wpilib.AnalogGyro(1)

        # Here we create the drivetrain as a whole, combining all the different
        # robot drivetrain compontents.
        self.drivetrain = drivetrain.Drivetrain(self.left, self.right,
                                                self.drivetrain_solenoid,
                                                self.drivetrain_gyro,
                                                self.rf_motor)

        self.l_gripper = wpilib.VictorSP(0)
        self.r_gripper = wpilib.VictorSP(1)

        self.grippers = grippers.Grippers(self.l_gripper, self.r_gripper)

        self.elevator_motor = wpilib.VictorSP(2)

        self.elevator_top_switch = wpilib.DigitalInput(4)
        self.elevator_bot_switch = wpilib.DigitalInput(5)

        self.elevator = elevator.Elevator(self.elevator_motor,
                                          self.elevator_top_switch,
                                          self.elevator_bot_switch)

        self.handles_solenoid = wpilib.DoubleSolenoid(0, 1)

        self.handles = handles.Handles(self.handles_solenoid)

        # This creates the instance of the autonomous program that will run
        # once the autonomous period begins.
        self.autonomous = AutonomousProgram()

        # This gets the instance of the joystick with the button function
        # programmed in.
        self.josytick = oi.getJoystick()
Exemplo n.º 14
0
    def robotInit(self):
        self.lJoy = wpilib.Joystick(0)
        self.rJoy = wpilib.Joystick(1)

        self.FL = ctre.CANTalon(2)
        self.FR = ctre.CANTalon(1)
        self.BL = ctre.CANTalon(0)
        self.BR = ctre.CANTalon(3)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 15
0
    def __init__(self, robot):
        super().__init__()
        self.robot = robot

        self.front_left_motor = wpilib.Talon(1)
        self.back_left_motor = wpilib.Talon(2)
        self.front_right_motor = wpilib.Talon(3)
        self.back_right_motor = wpilib.Talon(4)

        self.drive = wpilib.RobotDrive(
            self.front_left_motor,
            self.back_left_motor,
            self.front_right_motor,
            self.back_right_motor,
        )

        self.left_encoder = wpilib.Encoder(1, 2)
        self.right_encoder = wpilib.Encoder(3, 4)

        # Encoders may measure differently in the real world and in
        # simulation. In this example the robot moves 0.042 barleycorns
        # per tick in the real world, but the simulated encoders
        # simulate 360 tick encoders. This if statement allows for the
        # real robot to handle this difference in devices.
        if robot.isReal():
            self.left_encoder.setDistancePerPulse(0.042)
            self.right_encoder.setDistancePerPulse(0.042)
        else:
            # Circumference in ft = 4in/12(in/ft)*PI
            self.left_encoder.setDistancePerPulse(
                (4.0 / 12.0 * math.pi) / 360.0)
            self.right_encoder.setDistancePerPulse(
                (4.0 / 12.0 * math.pi) / 360.0)

        self.rangefinder = wpilib.AnalogInput(6)
        self.gyro = wpilib.AnalogGyro(1)

        wpilib.LiveWindow.addActuator("Drive Train", "Front_Left Motor",
                                      self.front_left_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Back Left Motor",
                                      self.back_left_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Front Right Motor",
                                      self.front_right_motor)
        wpilib.LiveWindow.addActuator("Drive Train", "Back Right Motor",
                                      self.back_right_motor)
        wpilib.LiveWindow.addSensor("Drive Train", "Left Encoder",
                                    self.left_encoder)
        wpilib.LiveWindow.addSensor("Drive Train", "Right Encoder",
                                    self.right_encoder)
        wpilib.LiveWindow.addSensor("Drive Train", "Rangefinder",
                                    self.rangefinder)
        wpilib.LiveWindow.addSensor("Drive Train", "Gyro", self.gyro)
Exemplo n.º 16
0
    def __init__(self):
        '''
        Constructor
        '''
        self.x = 0
        self.y = 0
        self.z = 0

        self.yavg = [0] * 50

        self.i = 0

        self.gyro = wpilib.AnalogGyro(0)
Exemplo n.º 17
0
    def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)
        self.rstick = wpilib.Joystick(1)

        self.lr_motor = wpilib.Jaguar(1)
        self.rr_motor = wpilib.Jaguar(2)
        self.lf_motor = wpilib.Jaguar(3)
        self.rf_motor = wpilib.Jaguar(4)

        self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor,
                                             self.rf_motor, self.rr_motor)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 18
0
    def robotInit(self):
        ''' Robot initilization function '''

        # initialize networktables
        self.smart_dashboard = NetworkTables.getTable("SmartDashboard")
        self.smart_dashboard.putNumber('shooter_speed', self.shooter_speed)
        self.smart_dashboard.putNumber('gear_arm_opening_speed',
                                       self.gear_arm_opening_speed)
        self.smart_dashboard.putNumber('gear_arm_closing_speed',
                                       self.gear_arm_closing_speed)
        self.smart_dashboard.putNumber('loader_speed', self.loader_speed)

        # initialize and launch the camera
        wpilib.CameraServer.launch()

        # object that handles basic drive operatives
        self.drive_rf_motor = wpilib.Victor(portmap.motors.right_front)
        self.drive_rr_motor = wpilib.Victor(portmap.motors.right_rear)
        self.drive_lf_motor = wpilib.Victor(portmap.motors.left_front)
        self.drive_lr_motor = wpilib.Victor(portmap.motors.left_rear)
        self.shooter_motor = wpilib.Victor(portmap.motors.shooter)
        self.gear_arm_motor = wpilib.Spark(portmap.motors.gear_arm)
        self.loader_motor = wpilib.Spark(portmap.motors.loader)

        # initialize drive
        self.drive = wpilib.RobotDrive(self.drive_lf_motor,
                                       self.drive_lr_motor,
                                       self.drive_rf_motor,
                                       self.drive_rr_motor)

        self.drive.setExpiration(0.1)

        # joysticks 1 & 2 on the driver station
        self.left_stick = wpilib.Joystick(portmap.joysticks.left_joystick)
        self.right_stick = wpilib.Joystick(portmap.joysticks.right_joystick)

        # initialize gyro
        self.gyro = wpilib.AnalogGyro(1)

        # initialize autonomous components
        self.components = {
            'drive': self.drive,
            'gear_arm_motor': self.gear_arm_motor
        }

        self.automodes = AutonomousModeSelector('autonomous', self.components)
Exemplo n.º 19
0
    def createObjects(self):

        self.lr_motor = ctre.WPI_TalonSRX(1)
        self.lf_motor = ctre.WPI_TalonSRX(2)

        self.rr_motor = ctre.WPI_TalonSRX(5)
        self.rf_motor = ctre.WPI_TalonSRX(6)

        self.rf_motor.configSelectedFeedbackSensor(
            ctre.WPI_TalonSRX.FeedbackDevice.CTRE_MagEncoder_Relative)
        self.talon.setSensorPhase(True)
        self.setOutputRange(self.MIN_SPEED, self.MAX_SPEED)

        self.setAbsoluteTolerance(self.ABS_TOLERANCE)

        self.ABS_TOLERANCE = (3 / self.DIST_TO_TICKS)

        self.left = wpilib.SpeedControllerGroup(self.lf_motor, self.lr_motor)
        self.right = wpilib.SpeedControllerGroup(self.rf_motor, self.rr_motor)

        self.drive = wpilib.drive.DifferentialDrive(self.left, self.right)

        self.drivetrain_solenoid = wpilib.DoubleSolenoid(2, 3)
        self.drivetrain_gyro = wpilib.AnalogGyro(1)

        self.elevator_motor = wpilib.VictorSP(2)

        self.top_switch = wpilib.DigitalInput(4)
        self.bot_switch = wpilib.DigitalInput(5)

        self.handles_solenoid = wpilib.DoubleSolenoid(0, 1)

        self.l_gripper_motor = wpilib.VictorSP(0)
        self.r_gripper_motor = wpilib.VictorSP(1)

        self.joystick = wpilib.Joystick(0)

        self.trigger = wpilib.buttons.JoystickButton(self.joystick, 1)
        self.button_2 = wpilib.buttons.JoystickButton(self.joystick, 2)
        self.button_3 = wpilib.buttons.JoystickButton(self.joystick, 3)
        self.button_4 = wpilib.buttons.JoystickButton(self.joystick, 4)
        self.button_5 = wpilib.buttons.JoystickButton(self.joystick, 5)
        self.button_7 = wpilib.buttons.JoystickButton(self.joystick, 7)
        self.button_10 = wpilib.buttons.JoystickButton(self.joystick, 10)
        self.button_11 = wpilib.buttons.JoystickButton(self.joystick, 11)
Exemplo n.º 20
0
    def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)
        self.rstick = wpilib.Joystick(1)

        self.lf_motor = wpilib.Jaguar(1)
        self.lr_motor = wpilib.Jaguar(2)
        self.rf_motor = wpilib.Jaguar(3)
        self.rr_motor = wpilib.Jaguar(4)

        l_motor = wpilib.SpeedControllerGroup(self.lf_motor, self.lr_motor)
        r_motor = wpilib.SpeedControllerGroup(self.rf_motor, self.rr_motor)

        self.drive = wpilib.drive.DifferentialDrive(l_motor, r_motor)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 21
0
    def robotInit(self):
        """Robot initialization function"""
        self.frontLeftMotor = wpilib.Talon(self.frontLeftChannel)
        self.rearLeftMotor = wpilib.Talon(self.rearLeftChannel)
        self.frontRightMotor = wpilib.Talon(self.frontRightChannel)
        self.rearRightMotor = wpilib.Talon(self.rearRightChannel)

        self.drive = MecanumDrive(
            self.frontLeftMotor,
            self.rearLeftMotor,
            self.frontRightMotor,
            self.rearRightMotor,
        )

        self.lstick = wpilib.Joystick(self.lStickChannel)
        self.rstick = wpilib.Joystick(self.rStickChannel)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 22
0
    def robotInit(self):
        '''Robot-wide initialization code should go here'''

        self.lstick = wpilib.Joystick(0)

        self.l_motor = wpilib.Spark(1)
        self.r_motor = wpilib.Spark(2)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)

        self.robot_drive = wpilib.RobotDrive(self.l_motor, self.r_motor)

        self.l_encoder = wpilib.Encoder(0, 1)
        self.l_encoder.setDistancePerPulse(
            (math.pi * self.WHEEL_DIAMETER) / self.ENCODER_COUNTS_PER_REV)

        self.r_encoder = wpilib.Encoder(2, 3)
        self.r_encoder.setDistancePerPulse(
            (math.pi * self.WHEEL_DIAMETER) / self.ENCODER_COUNTS_PER_REV)
Exemplo n.º 23
0
    def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)
        self.rstick = wpilib.Joystick(1)

        self.l_motor = wpilib.Jaguar(1)
        self.r_motor = wpilib.Jaguar(2)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)

        self.drive = wpilib.drive.DifferentialDrive(self.l_motor, self.r_motor)

        self.motor = wpilib.Jaguar(4)

        self.limit1 = wpilib.DigitalInput(1)
        self.limit2 = wpilib.DigitalInput(2)

        self.position = wpilib.AnalogInput(2)
Exemplo n.º 24
0
    def robotInit(self):
        self.lr_motor = wpilib.Spark(frontLeftChannel)
        self.rr_motor = wpilib.Spark(rearLeftChannel)
        self.lf_motor = wpilib.Spark(frontRightChannel)
        self.rf_motor = wpilib.Spark(rearRightChannel)
        self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor,
                                             self.rf_motor, self.rr_motor)
        self.robot_drive.setExpiration(Expiration)
        self.robot_drive.setInvertedMotor(
            wpilib.RobotDrive.MotorType.kFrontLeft, True)
        self.robot_drive.setInvertedMotor(
            wpilib.RobotDrive.MotorType.kRearLeft, True)

        self.stick = wpilib.Joystick(JoystickNum)
        self.gyro1 = wpilib.AnalogGyro(GyroNum)
        self.motorClimbOn = wpilib.Spark(ClimbMotor)
        self.solenoid2 = wpilib.DoubleSolenoid(Solenoid2Num,
                                               SolenoidUselessNum)
        self.solenoid13 = wpilib.DoubleSolenoid(Solenoid1Num, Solenoid3Num)
        self.a = 0
        self.b = 0
Exemplo n.º 25
0
    def robotInit(self):
        """Robot-wide initialization code should go here"""

        self.lstick = wpilib.Joystick(0)
        self.rstick = wpilib.Joystick(1)

        self.l_motor = wpilib.Jaguar(1)
        self.r_motor = wpilib.Jaguar(2)

        # Position gets automatically updated as robot moves
        self.gyro = wpilib.AnalogGyro(1)

        self.robot_drive = wpilib.RobotDrive(self.l_motor, self.r_motor)

        self.motor = wpilib.Jaguar(4)

        self.light_sensor_left = wpilib.DigitalInput(1)
        self.light_sensor_middle = wpilib.DigitalInput(2)
        self.light_sensor_right = wpilib.DigitalInput(3)

        self.position = wpilib.AnalogInput(2)
Exemplo n.º 26
0
 def robotInit(self):
     '''Robot-wide initialization code should go here'''
     
     self.lstick = wpilib.Joystick(0)
     self.rstick = wpilib.Joystick(1)
     
     self.lr_motor = wpilib.Jaguar(1)
     self.rr_motor = wpilib.Jaguar(2)
     self.lf_motor = wpilib.Jaguar(3)
     self.rf_motor = wpilib.Jaguar(4)
     
     self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor,
                                          self.rf_motor, self.rr_motor)
     
     # The output function of a mecanum drive robot is always
     # +1 for all output wheels. However, traditionally wired
     # robots will be -1 on the left, 1 on the right.
     self.robot_drive.setInvertedMotor(wpilib.RobotDrive.MotorType.kFrontLeft, True)
     self.robot_drive.setInvertedMotor(wpilib.RobotDrive.MotorType.kRearLeft, True)
     
     # Position gets automatically updated as robot moves
     self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 27
0
    def robotInit(self):
        """Robot initialization function"""

        # object that handles basic drive operations
        self.left = wpilib.Victor(0)
        self.right = wpilib.Victor(1)
        self.gyro = wpilib.AnalogGyro(0)
        self.gyro.reset()
        self.myRobot = DifferentialDrive(self.left, self.right)
        self.myRobot.setExpiration(0.1)
        NetworkTables.initialize(server='127.0.0.1')
        self.smartdash = NetworkTables.getTable('SmartDashboard')
        self.gearshift = wpilib.DoubleSolenoid(0, 0, 1)
        wpilib.CameraServer.launch("vision.py:main")
        self.ll = NetworkTables.getTable("limelight")
        self.ll.putNumber('ledStatus', 1)
        # joysticks 1 & 2 on the driver station
        self.leftStick = wpilib.Joystick(2)
        self.rightStick = wpilib.Joystick(1)
        self.trigger = ButtonDebouncer(self.rightStick, 1, period=.5)
        self.smartdash.putNumber('tx', 1)
        self.gearshift.set(1)
        self.pdp = wpilib.PowerDistributionPanel(0)
        self.accelerometer = wpilib.BuiltInAccelerometer()
        self.gyro.initSendable
        self.myRobot.initSendable
        self.gearshift.initSendable
        self.pdp.initSendable
        self.accelerometer.initSendable
        self.acc = wpilib.AnalogAccelerometer(3)
        self.setpoint = 90.0
        self.P = .3
        self.I = 0
        self.D = 0

        self.integral = 0
        self.previous_error = 0
        self.rcw = 0
Exemplo n.º 28
0
    def robotInit(self):
        '''Robot initialization function'''

        # object that handles basic drive operations
        self.frontLeftMotor = wpilib.Spark(1)
        # self.middleLeftMotor = wpilib.Spark(4)
        self.rearLeftMotor = wpilib.Spark(2)

        self.frontRightMotor = wpilib.Spark(3)
        # self.middleRightMotor = wpilib.Spark(1)
        self.rearRightMotor = wpilib.Spark(4)

        self.ihigh_motor = wpilib.Spark(6)
        self.ilow_motor = wpilib.Spark(9)

        self.left = wpilib.SpeedControllerGroup(self.frontLeftMotor,
                                                self.rearLeftMotor)
        self.right = wpilib.SpeedControllerGroup(self.frontRightMotor,
                                                 self.rearRightMotor)

        self.myRobot = DifferentialDrive(self.left, self.right)
        self.myRobot.setExpiration(0.1)

        self.high = 0
        self.low = 0
        self.gameData = ''

        # joysticks 1 & 2 on the driver station
        self.Stick1 = wpilib.XboxController(0)
        self.Stick2 = wpilib.Joystick(1)

        self.aSolenoidLow = wpilib.DoubleSolenoid(2, 3)
        self.aSolenoidHigh = wpilib.DoubleSolenoid(0, 1)
        self.iSolenoid = wpilib.DoubleSolenoid(4, 5)

        self.gyro = wpilib.AnalogGyro(0)
Exemplo n.º 29
0
    def robotInit(self):
        front_left_motor = ctre.WPI_TalonSRX(
            robotmap.mecanum['front_left_motor'])
        back_left_motor = ctre.WPI_TalonSRX(
            robotmap.mecanum['back_left_motor'])
        front_right_motor = ctre.WPI_TalonSRX(
            robotmap.mecanum['front_right_motor'])
        back_right_motor = ctre.WPI_TalonSRX(
            robotmap.mecanum['back_right_motor'])

        front_left_motor.setInverted(True)
        #back_left_motor.setInverted(True)

        self.drive = wpilib.drive.MecanumDrive(front_left_motor,
                                               back_left_motor,
                                               front_right_motor,
                                               back_right_motor)

        self.drive.setExpiration(0.1)

        self.lstick = wpilib.XboxController(0)
        self.rstick = wpilib.XboxController(1)

        self.gyro = wpilib.AnalogGyro(1)
Exemplo n.º 30
0
def createAnalogGyro():
    return wpilib.AnalogGyro(0)