當前位置: 首頁>>代碼示例>>Java>>正文


Java Encoder類代碼示例

本文整理匯總了Java中edu.wpi.first.wpilibj.Encoder的典型用法代碼示例。如果您正苦於以下問題:Java Encoder類的具體用法?Java Encoder怎麽用?Java Encoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Encoder類屬於edu.wpi.first.wpilibj包,在下文中一共展示了Encoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: PainTrain

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
public PainTrain(){
    m_leftGearbox   = new ThreeCimBallShifter(  new Victor(1),
                                                new Victor(2),
                                                new Victor(3),
                                                new DoubleSolenoid (1,2) );
            
    m_rightGearbox  = new ThreeCimBallShifter(  new Victor(4),
                                                new Victor(5),
                                                new Victor(6));
    
    m_shooter       = new Shooter(7,8,7,8,9);
    m_intake        = new Intake( 3,
                                  5,
                                  10 );
    m_encodeLeft = new Encoder(2,3);
    m_encodeRight = new Encoder(5,6);
  
    m_compressor    = new Compressor(1,4);
    m_compressor.start();
}
 
開發者ID:wsh32,項目名稱:PainTrain,代碼行數:21,代碼來源:PainTrain.java

示例2: DriveEncoders

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
/**
 * Constructs left and right encoders to be used by the subsystem
 * @param leftChannelA DIO port for the left encoder and channel a
 * @param leftChannelB DIO port for the left encoder and channel b
 * @param rightChannelA DIO port for the right encoder and channel a
 * @param rightChannelB DIO port for the right encoder and channel b
 * @param maxPeriod max period to be considered stopped
 * @param minRate max rate to be considered stopped
 * @param distancePerPulse value to convert a pulse into a distance. This is based on encoder resolution and wheel size.
 * @param reverseDirection should the encoder direction be reversed
 * @param samplesToAverage number of samples to average to calculate period
 */
public DriveEncoders(int leftChannelA, int leftChannelB, int rightChannelA,int rightChannelB,
                     double maxPeriod, int minRate, double distancePerPulse, boolean reverseDirection,int samplesToAverage) {

    encoderLeft  = new Encoder(leftChannelA, leftChannelB, reverseDirection, Encoder.EncodingType.k4X);
    encoderRight  = new Encoder(rightChannelA, rightChannelB, reverseDirection, Encoder.EncodingType.k4X);

    encoderLeft.setMaxPeriod(maxPeriod);
    encoderLeft.setMinRate(minRate);
    encoderLeft.setDistancePerPulse(distancePerPulse);
    encoderLeft.setSamplesToAverage(samplesToAverage);
    encoderRight.setMaxPeriod(maxPeriod);
    encoderRight.setMinRate(minRate);
    encoderRight.setDistancePerPulse(distancePerPulse);
    encoderRight.setSamplesToAverage(samplesToAverage);
}
 
開發者ID:mr-glt,項目名稱:FRC-2017-Command,代碼行數:28,代碼來源:DriveEncoders.java

示例3: initEncoders

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
/**
 * Initializes all the encoders. Is called in the constructor and can
 * be called outside the class.
 *
 * @param _leftFrontEncoder
 *            The front left encoder
 * @param _rightFrontEncoder
 *            The front right encoder
 * @param _leftRearEncoder
 *            The back left encoder
 * @param _rightRearEncoder
 *            The back right encoder
 */
public void initEncoders (Encoder _leftFrontEncoder,
        Encoder _rightFrontEncoder, Encoder _leftRearEncoder,
        Encoder _rightRearEncoder)
{
    // tell the class we have the encoders ready to go!
    isUsingEncoders = true;
    // Actually set up the local encoder objects
    this.leftFrontEncoder = _leftFrontEncoder;
    this.rightFrontEncoder = _rightFrontEncoder;
    this.leftRearEncoder = _leftRearEncoder;
    this.rightRearEncoder = _rightRearEncoder;
    // Set the encoder distance per pulse to a default value so we have it.
    // TODO call with correct value in robot init, possibly remove here
    this.setEncoderDistancePerPulse(DEFAULT_DISTANCE_PER_PULSE);
}
 
開發者ID:FIRST-Team-339,項目名稱:2017,代碼行數:29,代碼來源:Drive.java

示例4: directionChanged

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
/**
 * Checks to see if either side of encoders has changed direction since the last
 * call.
 * 
 * @param leftEncoder
 *            The left encoder to check for direction.
 * @param rightEncoder
 *            The right encoder to check for direction.
 * @return
 *         True if either drive train has changed direction since the last call.
 */
public boolean directionChanged (Encoder leftEncoder,
        Encoder rightEncoder)
{
    // if /Encoder/ - distance from previous call is less than 0
    //
    if (Math.abs(leftEncoder.getDistance())
            - this.brakePreviousDistanceL < 0
            && Math.abs(rightEncoder.getDistance())
                    - this.brakePreviousDistanceR < 0)
        {
        // set brakePreviousDistance to 0 and return true
        this.brakePreviousDistanceL = 0;
        this.brakePreviousDistanceR = 0;
        return true;
        }
    // set brakePreviousDistance to the encoder value
    brakePreviousDistanceL = Math.abs(leftEncoder.getDistance());
    brakePreviousDistanceR = Math.abs(rightEncoder.getDistance());
    return false;
}
 
開發者ID:FIRST-Team-339,項目名稱:2017,代碼行數:32,代碼來源:Drive.java

示例5: Transmission_old

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
/**
 * 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();

}
 
開發者ID:FIRST-Team-339,項目名稱:2017,代碼行數:36,代碼來源:Transmission_old.java

示例6: directionChanged

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
public boolean directionChanged (Encoder leftEncoder,
        Encoder rightEncoder)
{
    // if /Encoder/ - distance from previous call is less than 0
    //
    if (Math.abs(leftEncoder.getDistance())
            - this.brakePreviousDistanceL < 0
            && Math.abs(rightEncoder.getDistance())
                    - this.brakePreviousDistanceR < 0)
        {
        // set brakePreviousDistance to 0 and return true
        this.brakePreviousDistanceL = 0;
        this.brakePreviousDistanceR = 0;
        return true;
        }

        {
        // set brakePreviousDistance to the encoder value
        brakePreviousDistanceL = Math.abs(leftEncoder.getDistance());
        brakePreviousDistanceR = Math.abs(rightEncoder.getDistance());
        return false;
        }
}
 
開發者ID:FIRST-Team-339,項目名稱:2017,代碼行數:24,代碼來源:Transmission_old.java

示例7: HardwareAdaptor

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
private HardwareAdaptor(){
	pdp = new PowerDistributionPanel();
	comp = new Compressor();
	shifter = new DoubleSolenoid(SolenoidMap.SHIFTER_FORWARD, SolenoidMap.SHIFTER_REVERSE);
	
	navx = new AHRS(CoprocessorMap.NAVX_PORT);
	
	dtLeftEncoder = new Encoder(EncoderMap.DT_LEFT_A, EncoderMap.DT_LEFT_B, EncoderMap.DT_LEFT_INVERTED);
	S_DTLeft.linkEncoder(dtLeftEncoder);
	dtRightEncoder = new Encoder(EncoderMap.DT_RIGHT_A, EncoderMap.DT_RIGHT_B, EncoderMap.DT_RIGHT_INVERTED);
	S_DTRight.linkEncoder(dtRightEncoder);
	
	dtLeft = S_DTLeft.getInstance();
	dtRight = S_DTRight.getInstance();
	S_DTWhole.linkDTSides(dtLeft, dtRight);
	dtWhole = S_DTWhole.getInstance();
	
	arduino = S_Arduino.getInstance();
}
 
開發者ID:taco650,項目名稱:MinuteMan,代碼行數:20,代碼來源:HardwareAdaptor.java

示例8: Arm

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
public Arm() {
super("arm", kP, kI, kD);

motor = new Talon(RobotMap.ArmMap.PWM_MOTOR);
motor.setInverted(RobotMap.ArmMap.INV_MOTOR);

encoder = new Encoder(RobotMap.ArmMap.DIO_ENCODER_A, RobotMap.ArmMap.DIO_ENCODER_B);
encoder.setDistancePerPulse(RobotMap.ArmMap.DISTANCE_PER_PULSE);
encoder.setReverseDirection(RobotMap.ArmMap.INV_ENCODER);

upperLimit = new DigitalInput(RobotMap.ArmMap.DIO_LIMIT_TOP);
bottomLimit = new DigitalInput(RobotMap.ArmMap.DIO_LIMIT_BOTTOM);

setAbsoluteTolerance(0.05);
getPIDController().setContinuous(false);
   }
 
開發者ID:Team236,項目名稱:2016-Robot-Final,代碼行數:17,代碼來源:Arm.java

示例9: Shooter

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
public Shooter() {

		shooterLeftSide = new Talon(RobotMap.Pwm.LeftShooterMotor);
		shooterRightSide = new Talon(RobotMap.Pwm.RightShooterMotor);

		encoderLeft = new Encoder(RobotMap.Digital.ShooterLeftChannelA, RobotMap.Digital.ShooterLeftChannelB);
		encoderRight = new Encoder(RobotMap.Digital.ShooterRightChannelA, RobotMap.Digital.ShooterRightChannelB);

		encoderLeft.setPIDSourceType(PIDSourceType.kRate);
		encoderRight.setPIDSourceType(PIDSourceType.kRate);
		encoderLeft.setDistancePerPulse(distancePerPulse);
		encoderRight.setDistancePerPulse(distancePerPulse);

		// leftPID = new PIDSpeedController(encoderLeft, shooterLeftSide, "Shooter", "Left Wheel");
		// rightPID = new PIDSpeedController(encoderRight, shooterRightSide, "Shooter", "Right Wheel");

	}
 
開發者ID:chopshop-166,項目名稱:frc-2016,代碼行數:18,代碼來源:Shooter.java

示例10: directionChanged

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
public boolean directionChanged (Encoder leftEncoder,
        Encoder rightEncoder)
{
    // if /Encoder/ - distance from previous call is less than 0
    //
    if (Math.abs(leftEncoder.getDistance())
            - this.brakePreviousDistanceL < 0
            && Math.abs(rightEncoder.getDistance())
                    - this.brakePreviousDistanceR < 0)
        {
        // set brakePreviousDistance to 0 and return true
        this.brakePreviousDistanceL = 0;
        this.brakePreviousDistanceR = 0;
        return true;
        }
    else
        {
        // set brakePreviousDistance to the encoder value
        brakePreviousDistanceL = Math.abs(leftEncoder.getDistance());
        brakePreviousDistanceR = Math.abs(rightEncoder.getDistance());
        return false;
        }
}
 
開發者ID:FIRST-Team-339,項目名稱:2016,代碼行數:24,代碼來源:Transmission_old.java

示例11: SnobotDriveTrainWithEncoders

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
/**
   * @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());

   }
 
開發者ID:ArcticWarriors,項目名稱:snobot-2017,代碼行數:34,代碼來源:SnobotDriveTrainWithEncoders.java

示例12: ShooterControl

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
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;
}
 
開發者ID:Dinoyan,項目名稱:FRC-2014-robot-project,代碼行數:21,代碼來源:ShooterControl.java

示例13: DrivetrainSubsystem

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
public DrivetrainSubsystem(){
	leftMotor = RobotMap.leftDriveMotor.getController();
	rightMotor = RobotMap.rightDriveMotor.getController();
	drive = new RobotDrive(leftMotor, rightMotor);
	
	accelerometer = new IntegratedBuiltinAccelerometer(Range.k2G);
	
	leftEncoder = new Encoder(RobotMap.leftEncoder[0], RobotMap.leftEncoder[1]);
	rightEncoder = new Encoder(RobotMap.rightEncoder[0], RobotMap.rightEncoder[1]);
	leftEncoder.setReverseDirection(true);
	rightEncoder.setReverseDirection(true);
	
	driveGyro = new AnalogGyro(RobotMap.driveGyroPort);
	driveGyro.reset();
	driveGyro.setSensitivity(0.007);
	
	
}
 
開發者ID:Millerbots,項目名稱:FRC2549-2016,代碼行數:19,代碼來源:DrivetrainSubsystem.java

示例14: Lift

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
public Lift(int motorChannel, int brakeChannelForward, int brakeChannelReverse, int encoderChannelA,
		int encoderChannelB, int boundaryLimitChannel, String subsystem) {
	motor = new Talon(motorChannel);
	brake = new DoubleSolenoid(RobotMap.solenoid.Pcm24, brakeChannelForward, brakeChannelReverse);
	encoder = new Encoder(encoderChannelA, encoderChannelB);
	boundaryLimit = new DigitalInput(boundaryLimitChannel);

	LiveWindow.addActuator(subsystem, "Motor", motor);
	LiveWindow.addActuator(subsystem, "Brake", brake);
	LiveWindow.addSensor(subsystem, "Encoder", encoder);
	LiveWindow.addSensor(subsystem, "Boundary Limit Switch", boundaryLimit);

	encoder.setPIDSourceType(PIDSourceType.kRate);
	pid = new PIDSpeedController(encoder, motor, subsystem, "Speed Control");
	subsystemName = subsystem;
}
 
開發者ID:chopshop-166,項目名稱:frc-2015,代碼行數:17,代碼來源:Lift.java

示例15: SwervePod

import edu.wpi.first.wpilibj.Encoder; //導入依賴的package包/類
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
}
 
開發者ID:Whillikers,項目名稱:SwerveDrive,代碼行數:26,代碼來源:SwervePod.java


注:本文中的edu.wpi.first.wpilibj.Encoder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。