本文整理汇总了Java中edu.wpi.first.wpilibj.Counter类的典型用法代码示例。如果您正苦于以下问题:Java Counter类的具体用法?Java Counter怎么用?Java Counter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Counter类属于edu.wpi.first.wpilibj包,在下文中一共展示了Counter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AbsoluteAnalogEncoder
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public AbsoluteAnalogEncoder(int channel, double minVoltage, double maxVoltage, double offsetDegrees) {
super(channel);
if (minVoltage >= maxVoltage) throw new IllegalArgumentException("Minimum voltage must be less than maximum voltage");
if (offsetDegrees < 0 || offsetDegrees > 360) throw new IllegalArgumentException("Offset must be between 0 and 360 degrees");
_channel = channel;
_minVoltage = minVoltage;
_maxVoltage = maxVoltage;
_offsetDegrees = offsetDegrees;
// Turn counter only ever stores 0 //
_turnCounter = new Counter();
_turnCounter.reset();
_turnCounter.stop();
}
示例2: Launcher
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
/**
* Constructs a new Launcher, with two Talons for winding, a release relay,
* and a limit switch for winding regulation based on input from a
* MaxbotixUltrasonic rangefinder.
*/
public Launcher() {
super("Launcher");
winderL = new Talon(RobotMap.WIND_LEFT_PORT);
winderR = new Talon(RobotMap.WIND_RIGHT_PORT);
releaseMotor = new Relay(RobotMap.RELAY_PORT);
camera = new AxisCameraM1101();
rangefinder = new MaxbotixUltrasonic(RobotMap.ULTRASONIC_RANGEFINDER);
limitSwitch = new DigitalInput(RobotMap.LIMIT_SWITCH);
counter = new Counter(limitSwitch);
counterInit(counter);
}
示例3: Shooter
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public Shooter(Vision vision, JoystickControl controller)
{
this.vision = vision;
this.controller = controller;
averageSpeed = new MovingAverage(ENCODER_AVERAGE_SAMPLES);
feeder = new Relay(FEEDER_RELAY_CHANNEL);
feeder.setDirection(Relay.Direction.kForward);
feederSwitch = new DigitalInput(FEEDER_DIGITAL_SIDECAR_SLOT, FEEDER_DIGITAL_CHANNEL);
encoderInput = new DigitalInput(ENCODER_DIGITAL_SIDECAR_SLOT, ENCODER_DIGITAL_CHANNEL);
shooterEncoder = new Counter(encoderInput);
shooterEncoder.setSemiPeriodMode(true);
shooterMotor = new Motor(SHOOTER_JAGUAR_CHANNEL, SHOOTER_JAGUAR_INVERTED);
cycleCounts = 0;
rateCount = 0.0;
prevTime = 0.0;
currentSpeed = 0.0;
}
示例4: USensor
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public USensor() {
leftPulse = new DigitalOutput(RobotMap.LEFT_PULSE);
left = new Counter(RobotMap.LEFT_ECHO);
left.setMaxPeriod(1);
left.setSemiPeriodMode(true);
left.reset();
rightPulse = new DigitalOutput(RobotMap.RIGHT_PULSE);
right = new Counter(RobotMap.RIGHT_ECHO);
right.setMaxPeriod(1);
right.setSemiPeriodMode(true);
right.reset();
threadInit(() -> {
leftPulse.pulse(RobotMap.US_PULSE);
rightPulse.pulse(RobotMap.US_PULSE);
do {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (left.get() < 2 || right.get() < 2);
leftDistant = left.getPeriod() * 0.5 * RobotMap.SPEED_OF_SOUND;
rightDistant = right.getPeriod() * 0.5 * RobotMap.SPEED_OF_SOUND;
SmartDashboard.putNumber("left dis", leftDistant);
SmartDashboard.putNumber("right dis", rightDistant);
left.reset();
right.reset();
});
}
示例5: FRCPulseCounter
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public FRCPulseCounter(DigitalInput port, boolean pulseLength) {
counter = new Counter();
if(pulseLength){
counter.setPulseLengthMode(0.01);
}else{
counter.setUpSource(port);
counter.setUpDownCounterMode();
counter.setSemiPeriodMode(false);
}
quadrature = false;
}
示例6: Shooter
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public Shooter() {
shooterMotor = new VictorSP(Constants.SHOOTER);
shooterMotor2 = new VictorSP(Constants.SHOOTER_2);
shooterMotor.setInverted(true);
shooterMotor2.setInverted(true);
hallEffect = new Counter(Constants.HALL_EFFECT);
hallEffect.setDistancePerPulse(1);
}
示例7: FlyWheels
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public FlyWheels() {
left = new CANTalon(RobotMap.LEFT_SHOOTER_MOTOR);
right = new CANTalon(RobotMap.RIGHT_SHOOTER_MOTOR);
left.enableBrakeMode(true);
right.enableBrakeMode(true);
right.changeControlMode(CANTalon.TalonControlMode.Follower);
right.reverseOutput(true);
pusher = new DoubleSolenoid(RobotMap.PUSHER_OUT_PORT, RobotMap.PUSHER_IN_PORT);
wheelSwitch = new DigitalInput(RobotMap.FLYWHEEL_ENCODER_SWITCH);
counter = new Counter(wheelSwitch);
}
示例8: setNegativeLimitSwitch
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
/**
* Set the negative limit switch for this Talon.
* <p>
* This limit switch will stop the motor (set the talon to zero) if the limit switch
* is engaged and the motor set value is negative (<0). Any calls to {@link #pidWrite(double)}
* or {@link #set(double)} that contain a negative value will be overridden to zero. Positive
* motor speeds will still be accepted.
*
* @param negativeLimitSwitch - a digital input used for this limit switch.
* @param defaultState - the default state for this limit switch. The value opposite of the default
* state is used to determine if the switch is engaged.
*/
public void setNegativeLimitSwitch(DigitalInput negativeLimitSwitch, boolean defaultState) {
this.negativeLimitSwitch = negativeLimitSwitch;
this.negativeLimitSwitchDefaultState = defaultState;
// If the default state is true, the counter should detect falling edges
this.negativeLimitSwitchCounter = new Counter(this.negativeLimitSwitch);
if (defaultState == false) {
this.negativeLimitSwitchCounter.setUpSourceEdge(true, false);
} else {
this.negativeLimitSwitchCounter.setUpSourceEdge(false, true);
}
this.negativeLimitSwitchCounter.reset();
}
示例9: setPositiveLimitSwitch
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
/**
* Set the positive limit switch for this Talon.
* <p>
* This limit switch will stop the motor (set the talon to zero) if the limit switch
* is engaged and the motor set value is positive (>0). Any calls to {@link #pidWrite(double)}
* or {@link #set(double)} that contain a positive value will be overridden to zero. Negative
* motor speeds will still be accepted.
*
* @param positiveLimitSwitch - a digital input used for this limit switch.
* @param defaultState - the default state for this limit switch. The value opposite of the default
* state is used to determine if the switch is engaged.
*/
public void setPositiveLimitSwitch(DigitalInput positiveLimitSwitch, boolean defaultState) {
this.positiveLimitSwitch = positiveLimitSwitch;
this.positiveLimitSwitchDefaultState = defaultState;
// If the default state is true, the counter should detect falling edges
this.positiveLimitSwitchCounter = new Counter(this.positiveLimitSwitch);
if (defaultState == false) {
this.positiveLimitSwitchCounter.setUpSourceEdge(true, false);
} else {
this.positiveLimitSwitchCounter.setUpSourceEdge(false, true);
}
this.positiveLimitSwitchCounter.reset();
}
示例10: TurtleHallSensor
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public TurtleHallSensor(int port, boolean countHighs) {
c = new Counter();
c.setUpSource(port);
c.setUpDownCounterMode();
c.setSemiPeriodMode(countHighs);
c.setMaxPeriod(1);
c.setDistancePerPulse(1);
c.setSamplesToAverage(6);
}
示例11: Robot
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public Robot() {
stick = new Joystick(0);
try {
/* Construct Digital I/O Objects */
pwm_out_9 = new Victor( getChannelFromPin( PinType.PWM, 9 ));
pwm_out_8 = new Jaguar( getChannelFromPin( PinType.PWM, 8 ));
dig_in_7 = new DigitalInput( getChannelFromPin( PinType.DigitalIO, 7 ));
dig_in_6 = new DigitalInput( getChannelFromPin( PinType.DigitalIO, 6 ));
dig_out_5 = new DigitalOutput( getChannelFromPin( PinType.DigitalIO, 5 ));
dig_out_4 = new DigitalOutput( getChannelFromPin( PinType.DigitalIO, 4 ));
enc_3and2 = new Encoder( getChannelFromPin( PinType.DigitalIO, 3 ),
getChannelFromPin( PinType.DigitalIO, 2 ));
enc_1and0 = new Encoder( getChannelFromPin( PinType.DigitalIO, 1 ),
getChannelFromPin( PinType.DigitalIO, 0 ));
/* Construct Analog I/O Objects */
/* NOTE: Due to a board layout issue on the navX MXP board revision */
/* 3.3, there is noticeable crosstalk between AN IN pins 3, 2 and 1. */
/* For that reason, use of pin 3 and pin 2 is NOT RECOMMENDED. */
an_in_1 = new AnalogInput( getChannelFromPin( PinType.AnalogIn, 1 ));
an_trig_0 = new AnalogTrigger( getChannelFromPin( PinType.AnalogIn, 0 ));
an_trig_0_counter = new Counter( an_trig_0 );
an_out_1 = new AnalogOutput( getChannelFromPin( PinType.AnalogOut, 1 ));
an_out_0 = new AnalogOutput( getChannelFromPin( PinType.AnalogOut, 0 ));
/* Configure I/O Objects */
pwm_out_9.setSafetyEnabled(false); /* Disable Motor Safety for Demo */
pwm_out_8.setSafetyEnabled(false); /* Disable Motor Safety for Demo */
/* Configure Analog Trigger */
an_trig_0.setAveraged(true);
an_trig_0.setLimitsVoltage(MIN_AN_TRIGGER_VOLTAGE, MAX_AN_TRIGGER_VOLTAGE);
} catch (RuntimeException ex ) {
DriverStation.reportError( "Error instantiating MXP pin on navX MXP: "
+ ex.getMessage(), true);
}
}
示例12: initialize
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
@Override
public void initialize() {
m_victor = new Victor(RobotMap.LIFT_MOTOR);
m_victor.enableDeadbandElimination(true);
m_victor.setExpiration(Victor.DEFAULT_SAFETY_EXPIRATION);
m_encoder = new Encoder(RobotMap.ENCODER_DIO_PORTA,
RobotMap.ENCODER_DIO_PORTB, true);
m_encoder.setSamplesToAverage(10);
m_maxLimit = new DigitalInput(RobotMap.LIMIT_DIO_PORT1);
max_counter = new Counter(m_maxLimit);
}
示例13: isSwitchPressed
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
/**
* Measures a physical switch press and translates it to virtual meaning. If
* the winder motor is moving in the negative direction, the mechanism is
* unwinding and so the switch press count should decrease, and if the motor
* is moving in the positive direction, the mechanism is winding, and thus
* the switch press count should increase.
*
* @param counter The Counter object that represents the physical limit
* switch virtually. A physical switch press increments the counter value
* twice: once on the press (by 4 - 10) and once on the release (by 1 - 3).
* The code only acknowledges the presses by ignoring all increases that are
* less than 4.
*/
private void isSwitchPressed(Counter counter) {
if (counter.get() > 3) {
if (winderL.get() <= -0.1) {
currentClick--;
} else if (winderL.get() >= 0.1) {
currentClick++;
} else {
System.out.println("The switch should not have been pressed.");
}
clickTime = Timer.getFPGATimestamp();
}
counter.reset();
}
示例14: update
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public void update (){
enter_wheel_speed = ((Double) WsOutputManager.getInstance().getOutput(WsOutputManager.SHOOTER_VICTOR_ENTER).get((IOutputEnum) null));
exit_wheel_speed = ((Double) WsOutputManager.getInstance().getOutput(WsOutputManager.SHOOTER_VICTOR_EXIT).get((IOutputEnum) null));
//Use instanteous speed to update encoders
if (enter_wheel_speed > 0) {
enter_wheel_encoder+= AMOUNT_TO_CHANGE;
} else {
enter_wheel_encoder-= AMOUNT_TO_CHANGE;
if (enter_wheel_encoder < 0){
enter_wheel_encoder = 0 ;
}
}
if (exit_wheel_speed > 0) {
exit_wheel_encoder+= AMOUNT_TO_CHANGE;
} else {
exit_wheel_encoder-= AMOUNT_TO_CHANGE;
if (exit_wheel_encoder < 0){
exit_wheel_encoder = 0 ;
}
}
((Counter) ((WsShooter) WsSubsystemContainer.getInstance().getSubsystem(WsSubsystemContainer.WS_SHOOTER)).getEnterCounter()).set(enter_wheel_encoder);
((Counter) ((WsShooter) WsSubsystemContainer.getInstance().getSubsystem(WsSubsystemContainer.WS_SHOOTER)).getExitCounter()).set(exit_wheel_encoder);
}
示例15: ShootArm
import edu.wpi.first.wpilibj.Counter; //导入依赖的package包/类
public ShootArm() {
arm = new Talon(Ports.SHOOTER_LAUNCHER);
arm.set(0);
launcherEncoder = new Encoder(Ports.SHOOTER_ENCODER_1, Ports.SHOOTER_ENCODER_2, false, Encoder.EncodingType.k4X);
launcherEncoder.start();
launcherEncoder.setDistancePerPulse(0.96);
launcherEncoder.setMinRate(1);
armHome = new DigitalInput(Ports.SHOOTER_HOME);
armCounter = new Counter(armHome);
armCounter.start();
state = 0;
}