本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
}
示例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();
}
示例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);
}
示例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");
}
示例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;
}
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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
}