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