本文整理匯總了Java中edu.wpi.first.wpilibj.Victor.set方法的典型用法代碼示例。如果您正苦於以下問題:Java Victor.set方法的具體用法?Java Victor.set怎麽用?Java Victor.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edu.wpi.first.wpilibj.Victor
的用法示例。
在下文中一共展示了Victor.set方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ControlToggleRunMotor
import edu.wpi.first.wpilibj.Victor; //導入方法依賴的package包/類
public void ControlToggleRunMotor(Victor vMotor, int speed) {
if (!toggleMotor) {
vMotor.set(speed);
toggleMotor = true;
}else if (toggleMotor) {
vMotor.set(0.0);
toggleMotor = false;
}
}
示例2: ControlHoldRunMotor
import edu.wpi.first.wpilibj.Victor; //導入方法依賴的package包/類
public void ControlHoldRunMotor(Victor vMotor, int speed, boolean holdingButton) {
if (holdingButton) {
vMotor.set(speed);
}else{
vMotor.set(0.0);
}
}
示例3: VictorPair
import edu.wpi.first.wpilibj.Victor; //導入方法依賴的package包/類
public VictorPair(int a, double adjA, int b, double adjB) {
va = new Victor(a);
va.set(0);
adjustA = adjA;
vb = new Victor(b);
vb.set(0);
adjustB = adjB;
}
示例4: EncoderShooter
import edu.wpi.first.wpilibj.Victor; //導入方法依賴的package包/類
public EncoderShooter() {
backMotor = new Victor(RobotMap.BACK_SHOOTER_MOTOR);
frontMotor = new Victor(RobotMap.FRONT_SHOOTER_MOTOR);
counter = new Counter(RobotMap.SHOOTER_ENCODER);
counter.setUpDownCounterMode();
counter.start();
setpoint = RobotMap.DEFAULT_SETPOINT;
backMotor.set(RobotMap.BACK_SHOOTING_SPEED);
}
示例5: testServoMechanism
import edu.wpi.first.wpilibj.Victor; //導入方法依賴的package包/類
@Test
public void testServoMechanism() {
// Make the motor and encoder.
Victor motor = new Victor(1);
Encoder encoder = new Encoder(1, 2);
final double cpr = 360.0;
final double encoder_angular_distance_per_pulse = 2.0*Math.PI / cpr;
final double pulley_radius = 0.0143256; // .564 in (18T 5mm pitch)
// arc length = 2*pi*r*central_angle/360
final double encoder_linear_distance_per_pulse = pulley_radius * 2.0 * Math.PI / cpr;
// Make a servo mechanism.
DCMotor transmission = DCMotor.makeTransmission(DCMotor.makeRS775(), 2, 10.5, 0.8);
// Load is nominally 1kg*m^2
ServoMechanism mechanism = new ServoMechanism(new PWMObserver(1), new EncoderSetter(1, 2), 0,
encoder_angular_distance_per_pulse, transmission, .007, new ServoMechanism.Limits(0.0, 1.8));
// Check against limits.
assert(mechanism.withinLowerLimits());
assert(mechanism.withinUpperLimits());
// Drive the load down.
motor.set(-1.0);
mechanism.step(12.0, 0.0, 0.01);
mechanism.step(12.0, 0.0, 0.01);
mechanism.step(12.0, 0.0, 0.01);
assertFalse(mechanism.withinLowerLimits());
assert(mechanism.withinUpperLimits());
// Check encoder went in reverse.
assert(encoder.getRaw() < 0);
// Reset the mechanism.
mechanism.reset(0.0);
assertEquals(encoder.getRaw(), 0);
assert(mechanism.withinLowerLimits());
// Simple 100Hz PID controller.
final double period = 0.01;
final double setpoint = 1.5; // Do a 1.5m lift
final double proportional_gain = 10.0;
final double integral_gain = 100.0;
final double derivative_gain = 0.2;
double last_error = setpoint;
double error_sum = 0;
int last_encoder = 0;
for (int i = 0; i < 200; ++i) {
double error = setpoint - encoder.getRaw() * encoder_linear_distance_per_pulse;
double derivative = (error - last_error) / period;
last_error = error;
if (proportional_gain * error < 1.0) {
error_sum += error * period;
}
motor.set(proportional_gain * error + integral_gain * error_sum + derivative_gain * derivative);
last_encoder = encoder.getRaw();
mechanism.step(12.0, -9.8/pulley_radius, period); // Gravity reacting against the lift
double velocity = (encoder.getRaw() - last_encoder) * encoder_linear_distance_per_pulse / period;
if (i % 10 == 0) {
System.out.println("Time: " + i * period + ", Error: " + error + ", Command: " + motor.get() + ", Velocity: " + velocity);
}
}
assertEquals(encoder.getRaw() * encoder_linear_distance_per_pulse, setpoint, 1E-3);
}
示例6: Intake
import edu.wpi.first.wpilibj.Victor; //導入方法依賴的package包/類
public Intake() {
intakeRoller = new Victor(Ports.LOADER_INTAKE_ROLLER);
intakeRoller.set(0);
extender = new DoubleSolenoid(Ports.LOADER_EXTENDER_1, Ports.LOADER_EXTENDER_2);
}
示例7: RampedSpeedController
import edu.wpi.first.wpilibj.Victor; //導入方法依賴的package包/類
/**
* Constructor that creates a Victor to use as the speed controller with the channel number
* for the Victor to use
* @param channel the number of the channel to create the speed controller with
*/
public RampedSpeedController(int channel) {
controller = new Victor(channel);
controller.set(0);
}