Announcement

Collapse
No announcement yet.

Override line errors?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Override line errors?

    We recently added servos to this teleop program:


    package org.firstinspires.ftc.teamcode;

    import com.qualcomm.robotcore.eventloop.opmode.Disabled;
    import com.qualcomm.robotcore.util.ElapsedTime;
    import com.qualcomm.robotcore.hardware.Servo;
    import com.qualcomm.robotcore.hardware.DcMotor;
    import com.qualcomm.robotcore.util.ElapsedTime;
    import com.qualcomm.robotcore.eventloop.opmode.OpMode;
    import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
    import com.qualcomm.robotcore.util.Range;

    /**
    * This file contains an example of an iterative (Non-Linear) "OpMode".
    * An OpMode is a 'program' that runs in either the autonomous or the teleop period of an FTC match.
    * The names of OpModes appear on the menu of the FTC Driver Station.
    * When an selection is made from the menu, the corresponding OpMode
    * class is instantiated on the Robot Controller and executed.
    *
    * This particular OpMode just executes a basic Tank Drive Teleop for a two wheeled robot
    * It includes all the skeletal structure that all iterative OpModes contain.
    *
    * Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
    * Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list
    */

    @TeleOp(name="Tom", group="Iterative Opmode")

    public class Tom extends OpMode
    {
    // Declare OpMode members.
    private ElapsedTime runtime = new ElapsedTime();
    private DcMotor leftDrive = null;
    private DcMotor rightDrive = null;
    private Servo top_hand = null;
    private Servo lowerArm = null;
    private Servo upperArm = null;
    private Servo leftHand = null;




    private double handOffset = 0.0 ; // Servo mid position
    private final double CLAW_SPEED = 0.01 ; // sets rate to move serv
    private final double HAND_SPEED = 0.01 ; // sets rate to move serv
    private double upper;
    private double lower;
    /*
    * Code to run ONCE when the driver hits INIT
    */
    @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");
    top_hand = hardwareMap.get(Servo.class, "top_hand");
    leftHand = hardwareMap.get(Servo.class, "leftHand");
    upperArm = hardwareMap.get(Servo.class, "upperArm");
    lowerArm = hardwareMap.get(Servo.class, "lowerArm");


    // 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.REVERSE);
    rightDrive.setDirection(DcMotor.Direction.FORWARD) ;

    // Tell the driver that initialization is complete.
    telemetry.addData("Status", "Initialized");

    }


    @Override
    public void init_loop() {
    }

    /*
    * Code to run ONCE when the driver hits PLAY
    */
    @Override
    public void start() {
    runtime.reset();
    }

    /*
    * Code to run REPEATEDLY after the driver hits PLAY but before they hit STOP
    */
    @Override
    public void loop() {
    // Setup a variable for each drive wheel to save power level for telemetry
    double leftPower;
    double rightPower;

    // Choose to drive using either Tank Mode, or POV Mode
    // Comment out the method that's not used. The default below is POV.

    // POV Mode uses left stick to go forward, and right stick to turn.
    // - This uses basic math to combine motions and is easier to drive straight.
    //double drive = -gamepad1.left_stick_y;
    //double turn = gamepad1.right_stick_x;
    //leftPower = Range.clip(drive + turn, -1.0, 1.0) ;
    //rightPower = Range.clip(drive - turn, -1.0, 1.0) ;


    if (gamepad1.right_bumper) {
    handOffset += CLAW_SPEED;
    }
    else if (gamepad1.left_bumper)
    handOffset -= CLAW_SPEED;


    //Press front bumpers to move hand and pick up score elements
    if (gamepad2.right_bumper) {
    handOffset += HAND_SPEED;
    }
    else if (gamepad2.left_bumper)
    handOffset -= HAND_SPEED;


    // Tank Mode uses one stick to control each wheel.
    // - This requires no math, but it is hard to drive forward slowly and keep straight.
    rightPower = -gamepad1.left_stick_y ;
    leftPower = -gamepad1.right_stick_y ;

    // Send calculated power to arm
    leftDrive.setPower(leftPower);
    rightDrive.setPower(rightPower);

    upper = gamepad2.left_stick_y*.5 ;
    lower = gamepad2.right_stick_y*.5 ;

    upperArm.setPosition(upper);
    lowerArm.setPosition(lower);


    // Show the elapsed game time and wheel power.
    telemetry.addData("Status", "Run Time: " + runtime.toString());
    telemetry.addData("Motors", "left (%.2f), right (%.2f)", leftPower, rightPower);

    }

    /*
    * Code to run ONCE after the driver hits STOP
    */
    @Override
    public void stop() {
    }

    }



    The errors lie in these lines :

    ​​​​​​​@Override
    public void init_loop() {
    }



    These errors pop up every time:
    :

    Build started at Mon Oct 01 2018 08:16:51 GMT-0700 (Pacific Daylight Time)
    org/firstinspires/ftc/teamcode/HardwarePushbot.java line 105, column 29: ERROR: incompatible types: com.qualcomm.robotcore.hardware.Servo cannot be converted to com.qualcomm.robotcore.hardware.DcMotor
    org/firstinspires/ftc/teamcode/HardwarePushbot.java line 106, column 17: ERROR: cannot find symbol
    symbol: method setPosition(double)
    location: variable upperArm of type com.qualcomm.robotcore.hardware.DcMotor
    org/firstinspires/ftc/teamcode/HardwarePushbot.java line 107, column 29: ERROR: incompatible types: com.qualcomm.robotcore.hardware.Servo cannot be converted to com.qualcomm.robotcore.hardware.DcMotor
    org/firstinspires/ftc/teamcode/HardwarePushbot.java line 108, column 17: ERROR: cannot find symbol
    symbol: method setPosition(double)
    location: variable lowerArm of type com.qualcomm.robotcore.hardware.DcMotor


    Build finished in 0.5 seconds
    Build FAILED!


    We cannot figure out how to fix this. Any ideas? Any help would be greatly appreciated!
    Last edited by thensley; 10-01-2018, 11:25 AM.

  • #2
    The code that you posted doesn't seem to have anything to do with this error. The build error states that the problem is located in the file HardwarePushbot.java. Could you post the code for that file?

    Comment


    • #3
      package org.firstinspires.ftc.teamcode;

      import com.qualcomm.robotcore.hardware.DcMotor;
      import com.qualcomm.robotcore.hardware.HardwareMap;
      import com.qualcomm.robotcore.hardware.Servo;
      import com.qualcomm.robotcore.util.ElapsedTime;

      /**
      * This is NOT an opmode.
      *
      * This class can be used to define all the specific hardware for a single robot.
      * In this case that robot is a Pushbot.
      * See PushbotTeleopTank_Iterative and others classes starting with "Pushbot" for usage examples.
      *
      * This hardware class assumes the following device names have been configured on the robot:
      * Note: All names are lower case and some have single spaces between words.
      *
      * Motor channel: Left drive motor: "left_drive"
      * Motor channel: Right drive motor: "right_drive"
      * Motor channel: Manipulator drive motor: "left_arm"
      * Servo channel: Servo to open left claw: "left_hand"
      * Servo channel: Servo to open right claw: "right_hand"
      */
      public class HardwarePushbot
      {
      /* Public OpMode members. */
      public DcMotor leftDrive = null;
      public DcMotor rightDrive = null;
      public Servo leftClaw = null;
      public Servo leftHand = null;
      public DcMotor lowerArm = null;
      public DcMotor upperArm = null;


      public static final double MID_SERVO = 0.5 ;
      // public static final double ARM_UP_POWER = 0.45 ;
      // public static final double ARM_DOWN_POWER = -0.45 ;

      /* local OpMode members. */
      HardwareMap hwMap = null;
      private ElapsedTime period = new ElapsedTime();

      /* Constructor */
      public HardwarePushbot(){

      }

      /* Initialize standard Hardware interfaces */
      public void init(HardwareMap ahwMap) {
      // Save reference to Hardware map
      hwMap = ahwMap;

      // Define and Initialize Motors
      leftDrive = hwMap.get(DcMotor.class, "left_drive");
      rightDrive = hwMap.get(DcMotor.class, "right_drive");
      //leftArm = hwMap.get(DcMotor.class, "left_arm");
      leftDrive.setDirection(DcMotor.Direction.REVERSE); // Set to REVERSE if using AndyMark motors
      rightDrive.setDirection(DcMotor.Direction.FORWARD) ;// Set to FORWARD if using AndyMark motors

      // Set all motors to zero power
      leftDrive.setPower(0);
      rightDrive.setPower(0);
      //leftArm.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_USING_ENCODE R);
      rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCOD ER);
      // leftArm.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODE R);


      leftClaw = hwMap.get(Servo.class, "leftClaw");
      leftClaw.setPosition(MID_SERVO);
      leftHand = hwMap.get(Servo.class, "leftHand");
      leftHand.setPosition(MID_SERVO);
      upperArm = hwMap.get(Servo.class, "upperArm");
      upperArm.setPosition(MID_SERVO);
      lowerArm = hwMap.get(Servo.class, "lowerArm");
      lowerArm.setPosition(MID_SERVO);

      }
      }

      Comment


      • #4
        The variables upperArm and lowerArm are declared as DcMotors, but you attempt to get a Servo from the hardware map.

        If upperArm and lowerArm are supposed to be DcMotors then you should change the lines
        Code:
        upperArm = hwMap.get(Servo.class, "upperArm");
        lowerArm = hwMap.get(Servo.class, "lowerArm");
        to
        Code:
        upperArm = hwMap.get(DcMotor.class, "upperArm");
        lowerArm = hwMap.get(DcMotor.class, "lowerArm");
        and use setPower() instead of setPosition().


        If upperArm and lowerArm are supposed to be Servos then they should be declared like so
        Code:
        public Servo upperArm = null;
        public Servo lowerArm = null;

        Comment

        Working...
        X