public static void calibrateMotor (SpeedController motor) { if (hasRunVictorOnce == false) { time.stop(); time.reset(); time.start(); hasRunVictorOnce = true; } if (time.get() <= 2.0) motor.set(1.0); else if (time.get() >= 2.0 && time.get() <= 3.0) motor.set(0.0); else if (time.get() >= 3.0 && time.get() <= 5.0) motor.set(-1.0); else motor.set(0.0); }
@Override public SpeedController getSpeedController (MotorPosition position) { switch (position) { case LEFT_FRONT: return this.leftFrontMotor; case LEFT_REAR: return this.leftRearMotor; case RIGHT_FRONT: return this.rightFrontMotor; case RIGHT_REAR: return this.rightRearMotor; default: return null; } }
@Override public SpeedController getSpeedController(MotorPosition position) { switch (position) { case LEFT_FRONT: return this.leftMotor; case LEFT_REAR: return this.leftMotor; case RIGHT_FRONT: return this.rightMotor; case RIGHT_REAR: return this.rightMotor; default: return null; } }
@Override public SpeedController getSpeedController(MotorPosition position) { switch (position) { case LEFT_FRONT: return this.leftFrontMotor; case LEFT_REAR: return this.leftRearMotor; case RIGHT_FRONT: return this.rightFrontMotor; case RIGHT_REAR: return this.rightRearMotor; default: return null; } }
public Transmission_old ( final SpeedController rightFrontSpeedController, final SpeedController rightRearSpeedController, final SpeedController leftFrontSpeedController, final SpeedController leftRearSpeedController) { this.isFourWheel = true; this.oneOrRightSpeedController = rightFrontSpeedController; this.leftSpeedController = leftFrontSpeedController; this.rightRearSpeedController = rightRearSpeedController; this.leftRearSpeedController = leftRearSpeedController; // initialize mecanum drive /* * this.mecanumDrive = new RobotDrive(this.leftSpeedController, * this.leftRearSpeedController, * this.oneOrRightSpeedController, * this.rightRearSpeedController); * this.mecanumDrive.setSafetyEnabled(false); */ this.initPIDControllers(); this.init(); }
/** * Constructor for a four-wheel drive transmission class with * already-initialized encoders * * @param rightFrontSpeedController * @param rightRearSpeedController * @param leftFrontSpeedController * @param leftRearSpeedController * @param rightFrontEncoder * @param rightRearEncoder * @param leftFrontEncoder * @param leftRearEncoder */ public Transmission_old ( final SpeedController rightFrontSpeedController, final SpeedController rightRearSpeedController, final SpeedController leftFrontSpeedController, final SpeedController leftRearSpeedController, Encoder rightFrontEncoder, Encoder rightRearEncoder, Encoder leftFrontEncoder, Encoder leftRearEncoder) { this.isFourWheel = true; this.oneOrRightSpeedController = rightFrontSpeedController; this.leftSpeedController = leftFrontSpeedController; this.rightRearSpeedController = rightRearSpeedController; this.leftRearSpeedController = leftRearSpeedController; this.initEncoders(rightFrontEncoder, rightRearEncoder, leftFrontEncoder, leftRearEncoder); this.initPIDControllers(); this.init(); }
/** * This function allows a transmission to control the * power of a speed controller based on the current * gear. This applies to any of the speed controllers * (either Jaguar or Victor) Note that it must be the * right joystick. * * @method controls * @param joystickInputValue * - a float value which is used to set * the motor speed to that value * @param rightSpeedController * - the right or ONLY motor to * control * @author Bob Brown * @written Sep 20, 2009 * ------------------------------------------------------- */ public void controls (final double joystickInputValue, // the input value from the // joystick that controls this // speed controller final SpeedController rightSpeedController) // if we only have one Motor // to control then we consider // it to be the right Motor { // ------------------------------------- // call the ControlSpeedController() with // the correct motor direction // ------------------------------------- this.controlSpeedController(joystickInputValue * this.rightJoystickIsReversed.get(), rightSpeedController, WhichJoystick.ONE_JOYSTICK); }
/** * @param aLeftMotor * The First Left Motor * @param aLeftMotorB * The Second Left Motor * @param aRightMotor * The First Right Motor * @param aRightMotorB * The Second Right Motor * @param aDriverJoyStick * The Driver Joystick * @param aLogger * The Logger * */ public SnobotDriveTrainWithEncoders( SpeedController aLeftMotor, SpeedController aLeftMotorB, SpeedController aRightMotor, SpeedController aRightMotorB, Encoder aLeftEncoder, Encoder aRightEncoder, IDriverJoystick aDriverJoyStick, Logger aLogger) { super(aLeftMotor, aLeftMotorB, aRightMotor, aRightMotorB, aDriverJoyStick, aLogger); mLeftEncoder = aLeftEncoder; mRightEncoder = aRightEncoder; mLeftEncoder.setDistancePerPulse(Properties2016.sLEFT_ENCODER_DIST_PER_PULSE.getValue()); mRightEncoder.setDistancePerPulse(Properties2016.sRIGHT_ENCODER_DIST_PER_PULSE.getValue()); }
ShooterControl(Encoder encoder, SpeedController pullBackSpeedController, double speedControllerMaxRpm, DigitalInput limitSwitch, DoubleSolenoid gearControl, Servo latchServo, Relay angleControl) { m_latchReleaseServo = latchServo; m_currentState = SHOOTER_CONTROL_STATE_WAIT; m_encoder = encoder; m_pullBackSpeedController = pullBackSpeedController; m_angleControl = angleControl; m_speedControllerMaxRpm = speedControllerMaxRpm; m_limitSwitch = limitSwitch; m_pullBackEncoderRpm = new EncoderRPM(); m_pullBackEncoderRpm.Init(m_pullBackSpeedController, m_encoder, (-1)*m_speedControllerMaxRpm, m_speedControllerMaxRpm, 0.05, 100, m_limitSwitch); m_releaseFromMidptEncoderRpm = new EncoderRPM(); m_releaseFromMidptEncoderRpm.Init(m_pullBackSpeedController, m_encoder,(-1)*m_speedControllerMaxRpm/4,m_speedControllerMaxRpm,0.05, 3); m_gearControl = gearControl; m_latchReleased = false; m_gearReleased = false; m_isPulledBack = false; }
public SwervePod(SpeedController turningMotor, SpeedController driveMotor, Encoder encoder, double encoderDistancePerTick, AngularSensor directionSensor) { // Initialize motors // _turningMotor = turningMotor; _driveMotor = driveMotor; // Initialize sensors // _encoder = encoder; _encoder.setPIDSourceParameter(PIDSource.PIDSourceParameter.kRate); _encoder.setDistancePerPulse(encoderDistancePerTick); _encoder.start(); _directionSensor = directionSensor; // Initialize PID loops // // Turning // PIDTurning = new PIDController(Kp_turning, Ki_turning, Kd_turning, _directionSensor, _turningMotor); PIDTurning.setOutputRange(minSpeed, maxSpeed); PIDTurning.setContinuous(true); PIDTurning.setAbsoluteTolerance(tolerance_turning); PIDTurning.enable(); // Linear driving // PIDDriving = new PIDController(Kp_driving, Ki_driving, Kd_driving, _encoder, _driveMotor); PIDDriving.setOutputRange(minSpeed, maxSpeed); PIDDriving.disable(); //TODO: Enable }
/** * Constructor for RobotDrive with 6 motors specified as SpeedController * objects. Speed controller input version of RobotDrive (see previous * comments). * * @param rearLeftMotor The back left SpeedController object used to drive * the robot. * @param frontLeftMotor The front left SpeedController object used to drive * the robot * @param rearRightMotor The back right SpeedController object used to drive * the robot. * @param frontRightMotor The front right SpeedController object used to * drive the robot. * @param middleLeftMotor The middle left SpeedController object used to * drive the robot. * @param middleRightMotor The middle right SpeedController object used to * drive the robot. */ public RobotDrive6(SpeedController frontLeftMotor, SpeedController rearLeftMotor, SpeedController frontRightMotor, SpeedController rearRightMotor, SpeedController middleLeftMotor, SpeedController middleRightMotor) { if (frontLeftMotor == null || rearLeftMotor == null || frontRightMotor == null || rearRightMotor == null) { m_frontLeftMotor = m_rearLeftMotor = m_frontRightMotor = m_rearRightMotor = null; throw new NullPointerException("Null motor provided"); } m_frontLeftMotor = frontLeftMotor; m_rearLeftMotor = rearLeftMotor; m_frontRightMotor = frontRightMotor; m_rearRightMotor = rearRightMotor; m_middleLeftMotor = middleLeftMotor; m_middleRightMotor = middleRightMotor; m_sensitivity = kDefaultSensitivity; m_maxOutput = kDefaultMaxOutput; for (int i = 0; i < kMaxNumberOfMotors; i++) { m_invertedMotors[i] = 1; } m_allocatedSpeedControllers = false; setupMotorSafety(); drive(0, 0); }
/** * Constructor for RobotDrive with 2 motors specified as SpeedController * objects. The SpeedController version of the constructor enables programs * to use the RobotDrive classes with subclasses of the SpeedController * objects, for example, versions with ramping or reshaping of the curve to * suit motor bias or dead-band elimination. * * @param leftMotor The left SpeedController object used to drive the robot. * @param rightMotor the right SpeedController object used to drive the * robot. */ public RobotDriveSteering(SpeedController leftMotor, SpeedController rightMotor) { if (leftMotor == null || rightMotor == null) { m_rearLeftMotor = m_rearRightMotor = null; throw new NullPointerException("Null motor provided"); } m_frontLeftMotor = null; m_rearLeftMotor = leftMotor; m_frontRightMotor = null; m_rearRightMotor = rightMotor; m_sensitivity = kDefaultSensitivity; m_maxOutput = kDefaultMaxOutput; for (int i = 0; i < kMaxNumberOfMotors; i++) { m_invertedMotors[i] = 1; } m_allocatedSpeedControllers = false; setupMotorSafety(); drive(0, 0); }
/** * Constructor for RobotDrive with 4 motors specified as SpeedController * objects. Speed controller input version of RobotDrive (see previous * comments). * * @param rearLeftMotor The back left SpeedController object used to drive * the robot. * @param frontLeftMotor The front left SpeedController object used to drive * the robot * @param rearRightMotor The back right SpeedController object used to drive * the robot. * @param frontRightMotor The front right SpeedController object used to * drive the robot. */ public RobotDriveSteering(SpeedController frontLeftMotor, SpeedController rearLeftMotor, SpeedController frontRightMotor, SpeedController rearRightMotor) { if (frontLeftMotor == null || rearLeftMotor == null || frontRightMotor == null || rearRightMotor == null) { m_frontLeftMotor = m_rearLeftMotor = m_frontRightMotor = m_rearRightMotor = null; throw new NullPointerException("Null motor provided"); } m_frontLeftMotor = frontLeftMotor; m_rearLeftMotor = rearLeftMotor; m_frontRightMotor = frontRightMotor; m_rearRightMotor = rearRightMotor; m_sensitivity = kDefaultSensitivity; m_maxOutput = kDefaultMaxOutput; for (int i = 0; i < kMaxNumberOfMotors; i++) { m_invertedMotors[i] = 1; } m_allocatedSpeedControllers = false; setupMotorSafety(); drive(0, 0); }
public DriveTrainSubsystem() { motors = new SpeedController[RobotMap.DRIVE_TRAIN.MOTORS.length]; for (int i = 0; i < RobotMap.DRIVE_TRAIN.MOTORS.length; i++) { motors[i] = new Victor(RobotMap.DRIVE_TRAIN.MOTORS[i]); } doubleSidedPid = new PIDController649(EncoderBasedDriving.AUTO_DRIVE_P, EncoderBasedDriving.AUTO_DRIVE_I, EncoderBasedDriving.AUTO_DRIVE_D, this, this); doubleSidedPid.setAbsoluteTolerance(EncoderBasedDriving.ABSOLUTE_TOLERANCE); doubleSidedPid.setOutputRange(-EncoderBasedDriving.MAX_MOTOR_POWER, EncoderBasedDriving.MAX_MOTOR_POWER); encoders = new Encoder[RobotMap.DRIVE_TRAIN.ENCODERS.length / 2]; for (int x = 0; x < RobotMap.DRIVE_TRAIN.ENCODERS.length; x += 2) { encoders[x / 2] = new Encoder(RobotMap.DRIVE_TRAIN.ENCODERS[x], RobotMap.DRIVE_TRAIN.ENCODERS[x + 1], x == 0, EncodingType.k2X); encoders[x / 2].setDistancePerPulse(EncoderBasedDriving.ENCODER_DISTANCE_PER_PULSE); } lastRates = new Vector(); shifterSolenoid = new DoubleSolenoid(RobotMap.DRIVE_TRAIN.FORWARD_SOLENOID_CHANNEL, RobotMap.DRIVE_TRAIN.REVERSE_SOLENOID_CHANNEL); }
/** * Creates a new shooter. * * @param shooterMotor1 * @param shooterMotor2 * @param feeder * @param raiser * @param flywheelEncoder * @param raiserPot */ public Shooter(SpeedController shooterMotor1, SpeedController shooterMotor2, GRTSolenoid feeder, SpeedController raiser, GRTEncoder flywheelEncoder, Potentiometer raiserPot, GRTSwitch lowerLimit) { super("Shooter mech"); this.feeder = feeder; this.shooterMotor1 = shooterMotor1; this.shooterMotor2 = shooterMotor2; this.raiser = raiser; this.flywheelEncoder = flywheelEncoder; this.raiserPot = raiserPot; updateConstants(); lowerLimit.addListener(this); raiserPot.addListener(this); GRTConstants.addListener(this); }
/** * This function allows a transmission to control the * power of two speed controllers based on the current * gear. This is used with the left and right * drive motors, left and right joysticks and the two * buttons that denote whether or not to upshift or downshift. * * @method Controls * @param upShiftSwitch * - boolean - used to denote whether or not to * upshift at this time * @param downShiftSwitch * - boolean - used to denote whether or not to * downshift at this time * @param leftJoystickInputValue * - float - used to set * the left motor speed to that value * @param leftSpeedController * - SpeedController - controls the left motor * @param rightJoystickInputValue * - float - used to set * the right motor speed to that value * @param rightSpeedController * - SpeedController - controls the right motor * @author Bob Brown * @written Jan 13, 2011 * ------------------------------------------------------- */ public void controls (final boolean upShiftSwitch, // the switch that denotes an upShift final boolean downShiftSwitch, // the switch that denotes an downShift final double leftJoystickInputValue, // the input value from the left // joystick that controls the // left speed controller final SpeedController leftSpeedController, // the left Motor speed controller final double rightJoystickInputValue, // the input value from the right // joystick that controls the // right speed controller final SpeedController rightSpeedController) // the right Motor speed controller { // ------------------------------------- // make the gears correct as the user wants // them now. // ------------------------------------- this.checkShiftButtons(upShiftSwitch, downShiftSwitch); // ------------------------------------- // since we have two motors to control, // call controls() to process the input // ------------------------------------- this.controls(leftJoystickInputValue, leftSpeedController, rightJoystickInputValue, rightSpeedController); }
/** * This function allows a transmission to control the * power of two speed controllers based on the current * gear. This is most often used with the left and right * drive motors. This applies to any of the speed controllers * (either Jaguar or Victor). That is the * joystick that can be reversed if it is necessary. * * @method Controls * @param leftJoystickInputValue * - a float value which is used to set * the left motor speed to that value * @param leftSpeedController * - controls the left motor * @param rightJoystickInputValue * - a float value which is used to set * the right motor speed to that value * @param rightSpeedController * - controls the right motor * @author Bob Brown * @written Sep 20, 2009 * ------------------------------------------------------- */ public void controls (final double leftJoystickInputValue, // the input value from the left // joystick that controls the // left speed controller final SpeedController leftSpeedController, // the left Motor speed controller final double rightJoystickInputValue, // the input value from the right // joystick that controls the // right speed controller final SpeedController rightSpeedController) // the right Motor speed controller { // ------------------------------------- // since we have two motors to control, // call the ControlSpeedController() with // the correct motor direction // ------------------------------------- this.controlSpeedController(leftJoystickInputValue * this.leftJoystickIsReversed.get(), leftSpeedController, WhichJoystick.LEFT_JOYSTICK); this.controlSpeedController(rightJoystickInputValue * this.rightJoystickIsReversed.get(), rightSpeedController, WhichJoystick.RIGHT_JOYSTICK); }
/** * constructor * * @method RelativeSpeedController * @param speedController * The speed controller to control with * velocity commands * @param maxSpeed * The maximum speed that a command of 1.0 * should represent * @author Josh Shields * @written Jan 15, 2011 * ------------------------------------------------------- */ public RelativeSpeedController (final SpeedController speedController, // The // speed // controller // to // control // with // velocity // commands final double maxSpeed) // The maximum speed that a command of 1.0 // should represent { this.speedController = speedController; this.maxSpeed = maxSpeed; }
/** * Gets a controller held in this container by the index * @param index the index of the controller * @return a controller from the container * @throws IllegalArgumentException if the index is negative * @throws IndexOutOfBoundsException if the index exceeds the array size */ public SpeedController getController(int index){ if(index < 0) throw new IllegalArgumentException("Index must be non-negative"); else if(index >= motor_controllers.length) throw new IndexOutOfBoundsException("Index out of bounds of list - " + motor_controllers.length); return motor_controllers[index]; }
/** * {@inheritDoc} * <p> * Sets all the speed controllers contained in this object . * </p> */ @Override public void enableBrakeMode(boolean mode) { this.brakeMode = mode; for(int i = 0; i < motor_controllers.length; i++){ SpeedController c = motor_controllers[i]; if(c instanceof CANTalon) ((CANTalon)c).enableBrakeMode(mode); } }
public Motor(SpeedController motor) { if(motor == null) { throw new IllegalArgumentException("SpeedController argument was null when instantiating Motor object"); } this.motor = motor; if(motor instanceof CANTalon) { motorType = MotorType.CANTALON; } else if(motor instanceof Talon) { motorType = MotorType.TALON; } else { motorType = MotorType.UNKNOWN; } switch(motorType) { case CANTALON: CANTalon cMotor = (CANTalon) motor; cMotor.changeControlMode(CANTalon.TalonControlMode.PercentVbus); cMotor.enableBrakeMode(true); break; default: break; } }
@Override public void set(double setpoint) { _setpoint = (setpoint < -1.0 ? -1.0 : (setpoint > 1.0 ? 1.0 : setpoint)); for (SpeedController sc : _controllers) { sc.set(_setpoint); } }
@Override public void setInverted(boolean isInverted) { _isInverted = isInverted; for (SpeedController sc : _controllers) { sc.setInverted(_isInverted); } }
/** * Swerve Module basic constructor without drive PID * * @param _spinController * @param _driveController * @param _spinEncoder */ public SwerveModule(SpeedController _spinController, SpeedController _driveController, Encoder _spinEncoder) { this.name = ""; this.spinController = _spinController; this.driveController = _driveController; this.spinEncoder = _spinEncoder; this.driveEncoder = null; spinLoop = new PIDLoop("" + this.spinController.toString(), .1, .1, 0, new PIDEncoder(this.spinEncoder)); // generic PID values in here, they need to be tuned or input }
/** * Swerve Module basic constructor * * @param _spinController SpeedController of the spin motor * @param _driveController SpeedController of the drive motor * @param _spinEncoder Encoder to tell the angle of the drive wheel (may be changed to a Potentiometer) * @param _driveEncoder Encoder to tell the position of the drive wheel (may be changed to a Potentiometer) */ public SwerveModule(SpeedController _spinController, SpeedController _driveController, Encoder _spinEncoder, Encoder _driveEncoder) { this.name = ""; this.spinController = _spinController; this.driveController = _driveController; this.spinEncoder = _spinEncoder; this.driveEncoder = _driveEncoder; spinLoop = new PIDLoop("" + this.spinController.toString(), .1, .1, 0, new PIDEncoder(this.spinEncoder)); // generic PID values in here, they need to be tuned or input driveLoop = new PIDLoop("" + this.driveController.toString(), .1, 0, .1, new PIDEncoder(this.driveEncoder)); }
/** * Swerve Module constructor with a name * * @param _name the name of the module * @param _spinController SpeedController of the spin motor * @param _driveController SpeedController of the drive motor * @param _spinEncoder Encoder to tell the angle of the drive wheel (may be changed to a Potentiometer) * @param _driveEncoder Encoder to tell the position of the drive wheel (may be changed to a Potentiometer) */ public SwerveModule(String _name, SpeedController _spinController, SpeedController _driveController, Encoder _spinEncoder, Encoder _driveEncoder) { this.name = _name; this.spinController = _spinController; this.driveController = _driveController; this.spinEncoder = _spinEncoder; this.driveEncoder = _driveEncoder; spinLoop = new PIDLoop(this.name + "spin", .1, .1, 0, new PIDEncoder(this.spinEncoder)); // generic PID values in here, they need to be tuned or input driveLoop = new PIDLoop(this.name + "drive", .1, 0, .1, new PIDEncoder(this.driveEncoder)); }
public void reset() { for (int i = 0; i < motors.length; i++) { if (motors[i] == null) { continue; } if (motors[i] instanceof CANTalon) { ((CANTalon) motors[i]).delete(); } else if (motors[i] instanceof Victor) { ((Victor) motors[i]).free(); } } motors = new SpeedController[64]; for (int i = 0; i < solenoids.length; i++) { if (solenoids[i] == null) { continue; } solenoids[i].free(); } solenoids = new Solenoid[64]; for (int i = 0; i < relays.length; i++) { if (relays[i] == null) { continue; } relays[i].free(); } relays = new Relay[64]; for (int i = 0; i < analogInputs.length; i++) { if (analogInputs[i] == null) { continue; } analogInputs[i].free(); } analogInputs = new AnalogInput[64]; if (compressor != null) compressor.free(); }
public ManipulatorArm (SpeedController armMotorController, SpeedController intakeMotor, RobotPotentiometer armPot, IRSensor ballIsInArmSensor) { this.motor = armMotorController; this.armPot = armPot; this.intakeMotor = intakeMotor; this.hasBallSensor = ballIsInArmSensor; }
/** Transmission class to control a four-wheel mecanum drive robot. * * @param rightFrontSpeedController * @param rightRearSpeedController * @param leftFrontSpeedController * @param leftRearSpeedController * * @author Noah Golmant * #written 23 July 2015 */ public TransmissionMecanum (SpeedController rightFrontSpeedController, SpeedController rightRearSpeedController, SpeedController leftFrontSpeedController, SpeedController leftRearSpeedController) { super(rightFrontSpeedController, rightRearSpeedController, leftFrontSpeedController, leftRearSpeedController); }
public Gearbox(SpeedController motor1, SpeedController motor2, SpeedController motor3, Encoder encoder, DoubleSolenoid shifter) { m_motor1 = motor1; m_motor2 = motor2; m_motor3 = motor3; m_encoder = encoder; m_shifter = shifter; }
/** * Takes 2 speed controllers and joy stick arguments * * @param aSpeedControllerLeft * Argument for left Speed Controller * @param aSpeedControllerRight * Argument for right Speed Controller * @param aDriverJoystick * Argument Driver Joy stick */ public SnobotDriveTrain( SpeedController aSpeedControllerLeft, SpeedController aSpeedControllerRight, DriverJoystick aDriverJoystick) { mSpeedControllerLeft = aSpeedControllerLeft; mSpeedControllerRight = aSpeedControllerRight; mRobotDrive = new RobotDrive(mSpeedControllerLeft, mSpeedControllerRight); mJoystick = aDriverJoystick; mRobotDrive.setSafetyEnabled(false); }
public SnobotShooter(SpeedController aShooterMotor, Solenoid aShooterSolenoid, OperatorJoystick aShooterJoystick) { mShooterJoystick = aShooterJoystick; mShooterSolenoid = aShooterSolenoid; mShooterMotor = aShooterMotor; mIncreaseSpeedButton = new LatchedButton(); mDecreaseSpeedButton = new LatchedButton(); }
public SnobotDriveTrain( SpeedController aLeftMotor, SpeedController aRightMotor, Encoder aLeftDriveEncoder, Encoder aRightDriveEncoder, IDriverJoystick aDriverJoystick, ILogger aLogger) { super(aLeftMotor, null, aRightMotor, null, aDriverJoystick, aLogger); mLeftDriveEncoder = aLeftDriveEncoder; mRightDriveEncoder = aRightDriveEncoder; mLeftDriveEncoder.setDistancePerPulse(Properties2017.sLEFT_ENCODER_DIST_PER_PULSE.getValue()); mRightDriveEncoder.setDistancePerPulse(Properties2017.sRIGHT_ENCODER_DIST_PER_PULSE.getValue()); }