本文整理汇总了Java中com.qualcomm.robotcore.hardware.DcMotor类的典型用法代码示例。如果您正苦于以下问题:Java DcMotor类的具体用法?Java DcMotor怎么用?Java DcMotor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DcMotor类属于com.qualcomm.robotcore.hardware包,在下文中一共展示了DcMotor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
public void init(HardwareMap ahwMap) {
// save reference to HW Map
hwMap = ahwMap;
// Define and Initialize Motors
leftMotor = hwMap.dcMotor.get("left_drive");
rightMotor = hwMap.dcMotor.get("right_drive");
leftMotor.setDirection(DcMotor.Direction.REVERSE);
// Set all motors to zero power
leftMotor.setPower(0);
rightMotor.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
leftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
rightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// Define and initialize ALL installed servos.
arm = hwMap.servo.get("arm");
claw = hwMap.servo.get("claw");
arm.setPosition(ARM_HOME);
claw.setPosition(CLAW_HOME);
}
示例2: initTeleOp
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
/**
* Initializes all drive and ball motors in NO ENCODERS mode
* @param hwMap
*/
public void initTeleOp(HardwareMap hwMap) {
this.hwMap = hwMap;
initDrive();
initBall();
// initCap();
// initServos();
for(DcMotor driveMotor : driveMotors) {
driveMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
driveMotor.setDirection(DcMotorSimple.Direction.FORWARD);
driveMotor.setPower(0);
}
for(DcMotor ballMotor : ballMotors) {
ballMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
ballMotor.setDirection(DcMotorSimple.Direction.FORWARD);
ballMotor.setPower(0);
}
// cap.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
// cap.setDirection(DcMotorSimple.Direction.FORWARD);
// cap.setPower(0);
}
示例3: init
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
public void init(HardwareMap ahwMap) {
// save reference to HW Map
hwMap = ahwMap;
// Define and Initialize Motors
leftDrive = hwMap.get(DcMotor.class, "left_drive");
rightDrive = hwMap.get(DcMotor.class, "right_drive");
leftDrive.setDirection(DcMotor.Direction.REVERSE);
// Set all motors to zero power
leftDrive.setPower(0);
rightDrive.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
leftDrive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
rightDrive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// Define and initialize ALL installed servos.
arm = hwMap.get(Servo.class, "arm");
claw = hwMap.get(Servo.class, "claw");
arm.setPosition(ARM_HOME);
claw.setPosition(CLAW_HOME);
}
示例4: init
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
@Override
public void init() {
telemetry.addData("Status", "Initialized");
// Initialize the hardware variables. Note that the strings used here as parameters
// to 'get' must correspond to the names assigned during the robot configuration
// step (using the FTC Robot Controller app on the phone).
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
// Most robots need the motor on one side to be reversed to drive forward
// Reverse the motor that runs backwards when connected directly to the battery
leftDrive.setDirection(DcMotor.Direction.FORWARD);
rightDrive.setDirection(DcMotor.Direction.REVERSE);
// Tell the driver that initialization is complete.
telemetry.addData("Status", "Initialized");
}
示例5: elevePanier
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
protected void elevePanier(int pos)
{
robot.montePanier.setPower(0);
robot.montePanier.setTargetPosition(pos);/*-70*/
robot.montePanier.setMode(DcMotor.RunMode.RUN_TO_POSITION);
robot.montePanier.setPower(1);
/*- while (robot.montePanier.isBusy()) {
if (! OPMode.opModActif){break;}
}
robot.montePanier.setTargetPosition(pos);
robot.montePanier.setPower(0.4);*/
while (robot.montePanier.isBusy()) {
if (!OPMode.opModActif) {
break;
}
}
//robot.montePanier.setPower(1);
robot.montePanier.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
/*robot.montePanier.setMode(DcMotor.RunMode.RUN_USING_ENCODER);*/
}
示例6: elevePanier2
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
protected void elevePanier2(int pos)
{
robot.montePanier.setPower(0);
robot.montePanier.setTargetPosition(pos);/*-40*/
robot.montePanier.setMode(DcMotor.RunMode.RUN_TO_POSITION);
robot.montePanier.setPower(1);
while (robot.montePanier.getCurrentPosition()<pos-70){
if (! OPMode.opModActif){break;}
}
robot.montePanier.setPower(0.4);
while (robot.montePanier.isBusy()) {
if (! OPMode.opModActif){break;}
}
/*robot.montePanier.setTargetPosition(pos);
robot.montePanier.setPower(0.4);
while (robot.montePanier.isBusy()) {
if (!OPMode.opModActif) {
break;
}
}*/
//robot.montePanier.setPower(1);
robot.montePanier.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
/*robot.montePanier.setMode(DcMotor.RunMode.RUN_USING_ENCODER);*/
}
示例7: initilaize
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
public void initilaize()
{
//Assigning previously declared variables to expansion hub names
//colorSense = hardwareMap.colorSensor.get("colorMR");
//servo1 = hardwareMap.servo.get("servo1");
// servo2 = hardwareMap.servo.get("servo2");
// servo3 = hardwareMap.servo.get("servo3");
//rangeSense = hardwareMap.opticalDistanceSensor.get("rangeREV");
//Creating motors
motor2 = hardwareMap.dcMotor.get("motor2");
motor1 = hardwareMap.dcMotor.get("motor1");
motor4 = hardwareMap.dcMotor.get("motor4");
motor3 = hardwareMap.dcMotor.get("motor3");
motor1.setDirection(DcMotor.Direction.REVERSE);
motor4.setDirection(DcMotor.Direction.REVERSE);
//Setting up encoders
motor1.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
motor2.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
motor3.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
motor4.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
}
示例8: init
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
@Override
public void init(){
motor1 = hardwareMap.dcMotor.get("motor1");
motor1.setDirection(DcMotor.Direction.REVERSE);
motor2 = hardwareMap.dcMotor.get("motor2");
motor2.setDirection(DcMotor.Direction.FORWARD);
motor3 = hardwareMap.dcMotor.get("motor3");
motor3.setDirection(DcMotor.Direction.REVERSE);
motor4 = hardwareMap.dcMotor.get("motor4");
motor4.setDirection(DcMotor.Direction.FORWARD);
motor5 = hardwareMap.dcMotor.get("motor5");
motor5.setDirection(DcMotor.Direction.REVERSE);
motor6 = hardwareMap.dcMotor.get("motor6");
motor6.setDirection(DcMotor.Direction.FORWARD);
leftcr = hardwareMap.servo.get("leftcr");
rightcr = hardwareMap.servo.get("rightcr");
leftcr.setDirection(Servo.Direction.REVERSE);
rightcr.setDirection(Servo.Direction.FORWARD);
}
示例9: runOpMode
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
@Override
public void runOpMode() throws InterruptedException
{
motorLeft = this.hardwareMap.dcMotor.get("motorLeft");
motorRight = this.hardwareMap.dcMotor.get("motorRight");
motorLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
motorRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
waitForStart();
runMotorsBothDirections(1.0);
Thread.sleep(500);
runMotorsBothDirections(0.1);
Thread.sleep(500);
runMotorsBothDirections(1.0);
}
示例10: init
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
public void init(HardwareMap ahwMap) {
// save reference to HW Map
hwMap = ahwMap;
// Define and Initialize Motors
leftMotor = hwMap.dcMotor.get("left motor");
rightMotor = hwMap.dcMotor.get("right motor");
leftMotor.setDirection(DcMotor.Direction.REVERSE);
// Set all motors to zero power
leftMotor.setPower(0);
rightMotor.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
leftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
rightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// Define and initialize ALL installed servos.
arm = hwMap.servo.get("arm");
claw = hwMap.servo.get("claw");
arm.setPosition(ARM_HOME);
claw.setPosition(CLAW_HOME);
}
示例11: initRobot
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
private void initRobot()
{
lfWheel = hardwareMap.dcMotor.get("lfWheel");
rfWheel = hardwareMap.dcMotor.get("rfWheel");
lrWheel = hardwareMap.dcMotor.get("lrWheel");
rrWheel = hardwareMap.dcMotor.get("rrWheel");
lfWheel.setDirection(LEFTWHEEL_DIRECTION);
lrWheel.setDirection(LEFTWHEEL_DIRECTION);
rfWheel.setDirection(RIGHTWHEEL_DIRECTION);
rrWheel.setDirection(RIGHTWHEEL_DIRECTION);
lfWheel.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rfWheel.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
lrWheel.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rrWheel.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
lfWheel.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
rfWheel.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
lrWheel.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
rrWheel.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
gyro = (ModernRoboticsI2cGyro)hardwareMap.gyroSensor.get("gyroSensor");
gyro.resetZAxisIntegrator();
}
示例12: init_loop
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
@Override
public void init_loop() {
devMode = DcMotorController.DeviceMode.WRITE_ONLY;
motorRight.setDirection(DcMotor.Direction.REVERSE);
//motorLeft.setDirection(DcMotor.Direction.REVERSE);
// set the mode
// Nxt devices start up in "write" mode by default, so no need to switch device modes here.
motorLeft.setMode(DcMotorController.RunMode.RUN_WITHOUT_ENCODERS);
motorRight.setMode(DcMotorController.RunMode.RUN_WITHOUT_ENCODERS);
wristPosition = 0.6;
clawPosition = 0.5;
}
示例13: runOpMode
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
leftMotor = hardwareMap.dcMotor.get("left_drive");
rightMotor = hardwareMap.dcMotor.get("right_drive");
rightMotor.setDirection(DcMotor.Direction.REVERSE);
leftMotor.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
rightMotor.setMode(DcMotorController.RunMode.RUN_USING_ENCODERS);
waitForStart();
for(int i=0; i<4; i++) {
leftMotor.setPower(1.0);
rightMotor.setPower(1.0);
sleep(1000);
leftMotor.setPower(0.5);
rightMotor.setPower(-0.5);
sleep(500);
}
leftMotor.setPowerFloat();
rightMotor.setPowerFloat();
}
示例14: DriveTrain
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
public DriveTrain(ExtensibleGamepad controlGamepad, DcMotor leftFront, DcMotor rightFront, DcMotor leftRear, DcMotor rightRear) {
this.leftFront = leftFront;
this.rightFront = rightFront;
this.leftRear = leftRear;
this.rightRear = rightRear;
rightFront.setDirection(DcMotorSimple.Direction.REVERSE);
rightRear.setDirection(DcMotorSimple.Direction.REVERSE);
leftFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rightFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
rightFront.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
this.controlGamepad = controlGamepad;
//this.drive = drive;
disableMap = new double[4];
for (int i = 0; i < disableMap.length; i++) {
disableMap[i] = 1;
}
}
示例15: init
import com.qualcomm.robotcore.hardware.DcMotor; //导入依赖的package包/类
public void init(HardwareMap ahwMap) {
// Save reference to Hardware map
hwMap = ahwMap;
// Define and Initialize Motors
leftMotor = hwMap.dcMotor.get("left_drive");
rightMotor = hwMap.dcMotor.get("right_drive");
armMotor = hwMap.dcMotor.get("left_arm");
leftMotor.setDirection(DcMotor.Direction.FORWARD); // Set to REVERSE if using AndyMark motors
rightMotor.setDirection(DcMotor.Direction.REVERSE);// Set to FORWARD if using AndyMark motors
// Set all motors to zero power
leftMotor.setPower(0);
rightMotor.setPower(0);
armMotor.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
leftMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
rightMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
armMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// Define and initialize ALL installed servos.
leftClaw = hwMap.servo.get("left_hand");
rightClaw = hwMap.servo.get("right_hand");
leftClaw.setPosition(MID_SERVO);
rightClaw.setPosition(MID_SERVO);
}