Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def createObjects(self):
# #INITIALIZE JOYSTICKS##
self.joystick1 = wpilib.Joystick(0)
self.joystick2 = wpilib.Joystick(1)
# #INITIALIZE MOTORS##
self.lf_motor = wpilib.CANTalon(5)
self.lr_motor = wpilib.CANTalon(10)
self.rf_motor = wpilib.CANTalon(15)
self.rr_motor = wpilib.CANTalon(20)
self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
self.leftArm = wpilib.CANTalon(25)
self.rightArm = wpilib.CANTalon(30)
self.leftBall = wpilib.Talon(9)
self.winchMotor = wpilib.Talon(0)
self.kickMotor = wpilib.Talon(1)
##DRIVE ENCODERS##
self.rf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontRightMotor, True)
self.lf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontLeftMotor)
##NavX##
self.navX = navx.AHRS.create_spi()
def createObjects(self):
# #INITIALIZE JOYSTICKS##
self.joystick1 = wpilib.Joystick(0)
self.joystick2 = wpilib.Joystick(1)
# #INITIALIZE MOTORS##
self.lf_motor = wpilib.CANTalon(5)
self.lr_motor = wpilib.CANTalon(10)
self.rf_motor = wpilib.CANTalon(15)
self.rr_motor = wpilib.CANTalon(20)
self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
self.leftArm = wpilib.CANTalon(25)
self.rightArm = wpilib.CANTalon(30)
self.leftBall = wpilib.Talon(9)
self.winchMotor = wpilib.Talon(0)
self.kickMotor = wpilib.Talon(1)
##DRIVE ENCODERS##
self.rf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontRightMotor, True)
self.lf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontLeftMotor)
##NavX##
self.navX = navx.AHRS.create_spi()
##SMART DASHBOARD##
self.sd = NetworkTable.getTable('SmartDashboard')
##AUTO FUNCTIONALITY##
self.auto_portcullis = portcullis.PortcullisLift(self.sd, self.drive, self.intake)
# #INITIALIZE JOYSTICKS##
self.joystick1 = wpilib.Joystick(0)
self.joystick2 = wpilib.Joystick(1)
# #INITIALIZE MOTORS##
self.lf_motor = wpilib.CANTalon(5)
self.lr_motor = wpilib.CANTalon(10)
self.rf_motor = wpilib.CANTalon(15)
self.rr_motor = wpilib.CANTalon(20)
self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
self.leftArm = wpilib.CANTalon(25)
self.rightArm = wpilib.CANTalon(30)
self.leftBall = wpilib.Talon(9)
self.winchMotor = wpilib.Talon(0)
self.kickMotor = wpilib.Talon(1)
self.flashlight = wpilib.Relay(0)
self.lightTimer = wpilib.Timer()
self.turningOffState = 0
self.lastState = False
##DRIVE ENCODERS##
self.rf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontRightMotor, True)
self.lf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontLeftMotor)
def createObjects(self):
# #INITIALIZE JOYSTICKS##
self.joystick1 = wpilib.Joystick(0)
self.joystick2 = wpilib.Joystick(1)
# #INITIALIZE MOTORS##
self.lf_motor = wpilib.CANTalon(5)
self.lr_motor = wpilib.CANTalon(10)
self.rf_motor = wpilib.CANTalon(15)
self.rr_motor = wpilib.CANTalon(20)
self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
self.leftArm = wpilib.CANTalon(25)
self.rightArm = wpilib.CANTalon(30)
self.leftBall = wpilib.Talon(9)
self.winchMotor = wpilib.Talon(0)
self.kickMotor = wpilib.Talon(1)
##DRIVE ENCODERS##
self.rf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontRightMotor, True)
self.lf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontLeftMotor)
##NavX##
self.navX = navx.AHRS.create_spi()
##SMART DASHBOARD##
self.sd = NetworkTable.getTable('SmartDashboard')
##AUTO FUNCTIONALITY##
posVal = int(tm_diff*1023) # Encoder Position difference when in Position mode based on time
armDict['limit_switch_closed_for'] = True
armDict['limit_switch_closed_rev'] = True
lWheelPercentVal = int(lfDict['value']*tm_diff*10)
rWheelPercentVal = int(rfDict['value']*tm_diff*10)
except:
pass
else:
if armDict['mode_select'] == wpilib.CANTalon.ControlMode.PercentVbus: # If manual operation
self.armAct += armPercentVal # Add the calculated encoder change value to the 'actual value'
armDict['enc_position'] += armPercentVal # Add the calculated encoder change value to the recorded encoder value
elif armDict['mode_select'] == wpilib.CANTalon.ControlMode.Position: #If in auto mode
#err = armDict['value'] - armDict['enc_position']
#self.iErr +=err*tm_diff
#self.iErr = max(min(self.iErr, 300), -300)
#output = (armDict['params'][1]*err)+(armDict['params'][2]*self.iErr)*250/(1023)
#if abs(output) < 300:
# output = 0
if armDict['enc_position'] < armDict['value']: #If the current position is less than the target position
armDict['enc_position'] += posVal # Add calculated encoder value to recorded value
self.armAct += posVal
else: # If the current position is more than the target position
armDict['enc_position'] -= posVal # Subtract calculated encoder position
self.armAct -=posVal
#output*=tm_diff
#armDict['enc_position'] += output
#armDict['enc_position'] = int(armDict['enc_position'])
#self.armAct += output
import wpilib
from networktables.networktable import NetworkTable
import logging
logger = logging.getLogger('arm')
forward = 1
reverse = -1
off = 0
class ArmMode:
MANUAL = 1
AUTO = 2
class Arm:
leftArm = wpilib.CANTalon
rightArm = wpilib.CANTalon
leftBall = wpilib.Talon
def __init__(self):
self.isCalibrating = False
self.isCalibrated = False
self.sd = NetworkTable.getTable('SmartDashboard')
self.positions = [
self.sd.getAutoUpdateValue('Arm/Bottom', 3600),
self.sd.getAutoUpdateValue('Arm/Middle', 2635),
self.sd.getAutoUpdateValue('Arm/Top', -20),
]
self.position_threshold = self.sd.getAutoUpdateValue('Arm/On Target Threshold', 25)
self.wanted_pid = (
def createObjects(self):
# #INITIALIZE JOYSTICKS##
self.joystick1 = wpilib.Joystick(0)
self.joystick2 = wpilib.Joystick(1)
# #INITIALIZE MOTORS##
self.lf_motor = wpilib.CANTalon(5)
self.lr_motor = wpilib.CANTalon(10)
self.rf_motor = wpilib.CANTalon(15)
self.rr_motor = wpilib.CANTalon(20)
self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
self.leftArm = wpilib.CANTalon(25)
self.rightArm = wpilib.CANTalon(30)
self.leftBall = wpilib.Talon(9)
self.winchMotor = wpilib.Talon(0)
self.kickMotor = wpilib.Talon(1)
self.flashlight = wpilib.Relay(0)
self.lightTimer = wpilib.Timer()
self.turningOffState = 0
def createObjects(self):
# #INITIALIZE JOYSTICKS##
self.joystick1 = wpilib.Joystick(0)
self.joystick2 = wpilib.Joystick(1)
# #INITIALIZE MOTORS##
self.lf_motor = wpilib.CANTalon(5)
self.lr_motor = wpilib.CANTalon(10)
self.rf_motor = wpilib.CANTalon(15)
self.rr_motor = wpilib.CANTalon(20)
self.robot_drive = wpilib.RobotDrive(self.lf_motor, self.lr_motor, self.rf_motor, self.rr_motor)
self.leftArm = wpilib.CANTalon(25)
self.rightArm = wpilib.CANTalon(30)
self.leftBall = wpilib.Talon(9)
self.winchMotor = wpilib.Talon(0)
self.kickMotor = wpilib.Talon(1)
##DRIVE ENCODERS##
self.rf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontRightMotor, True)
self.lf_encoder = driveEncoders.DriveEncoders(self.robot_drive.frontLeftMotor)
rfDict = hal_data['CAN'][15]
armPercentVal = int(armDict['value']*tm_diff*2) # Encoder position increaser when in PercentVbus mode based on time and thrust value
posVal = int(tm_diff*1023) # Encoder Position difference when in Position mode based on time
armDict['limit_switch_closed_for'] = True
armDict['limit_switch_closed_rev'] = True
lWheelPercentVal = int(lfDict['value']*tm_diff*10)
rWheelPercentVal = int(rfDict['value']*tm_diff*10)
except:
pass
else:
if armDict['mode_select'] == wpilib.CANTalon.ControlMode.PercentVbus: # If manual operation
self.armAct += armPercentVal # Add the calculated encoder change value to the 'actual value'
armDict['enc_position'] += armPercentVal # Add the calculated encoder change value to the recorded encoder value
elif armDict['mode_select'] == wpilib.CANTalon.ControlMode.Position: #If in auto mode
#err = armDict['value'] - armDict['enc_position']
#self.iErr +=err*tm_diff
#self.iErr = max(min(self.iErr, 300), -300)
#output = (armDict['params'][1]*err)+(armDict['params'][2]*self.iErr)*250/(1023)
#if abs(output) < 300:
# output = 0
if armDict['enc_position'] < armDict['value']: #If the current position is less than the target position
armDict['enc_position'] += posVal # Add calculated encoder value to recorded value
self.armAct += posVal
else: # If the current position is more than the target position
armDict['enc_position'] -= posVal # Subtract calculated encoder position
self.armAct -=posVal
#output*=tm_diff
self.manual_value = 0
self.want_auto = False
self.mode = ArmMode.MANUAL
self.last_mode = ArmMode.MANUAL
#self.manual_value = -.25
self.manual_value = 0
# These need to be set by subclasses
self.current_pid = (0, 0, 0)
self.new_pid = None
self.leftArm.changeControlMode(wpilib.CANTalon.ControlMode.PercentVbus)
self.rightArm.changeControlMode(wpilib.CANTalon.ControlMode.Follower)
self.rightArm.reverseOutput(True)
self.leftBallSpeed = 0