Coding a CR Servo

We are attempting to program a CR servo on our FTC robot, but we are running into some problems with the servo continuing to move even after the program says “STOP”. Does anyone have any code or solution? to our problem

An FRC Team here but what language are you using, my team used a servo last year.

java

We’ve actually noticed the same thing now that I read the original post. We called it the phantom but ours just jumped about a bit. If it seems to keep moving after the robot is supposed to stop, in robot init try setting it to the home angle.

Even though I am taking a break this year being a CSA, I need to see your code to help you. Can you throw it up on Github or upload it somewhere I can see it?

Thank you in advance!

Agreed, that would be very helpful!

alright ill post it to git hub and post the link

package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.CRServo;

@TeleOp(name = “TestServo2 (Blocks to Java)”, group = “”)
public class TestServo2 extends LinearOpMode {

private CRServo con_servo;

/**

  • This function is executed when this Op Mode is selected from the Driver Station.
    */
    @Override
    public void runOpMode() {
    con_servo = hardwareMap.crservo.get(“con_servo”);
waitForStart();
while (opModeIsActive()) {
  if (gamepad1.a) {
    con_servo.setPower(1);
  }
  if (gamepad1.b) {
    con_servo.setPower(-1);
  }
  if (gamepad1.atRest()) {
    con_servo.setPower(0);
  }
  telemetry.update();
}

}
}

Try changing the if at rest statement to else. I’ll try to look at some documentation for FTC but if 8 were to do a setPower on a servo in FRC it would translate that to an angle and it would keep going.

i change the code to positions instead of Power
It did nothing

if (gamepad1.a) {
con_servo.setPosition(-10);
}
if (gamepad1.b) {
con_servo.setPosition(10);
}
if (gamepad1.x) {
con_servo.setPosition(0);

when it sets it to zero it just keeps spinning

Yes that makes sense because it’s trying to get to the position value, is there a way you can change it to off?

Try just the set method, that’s how I used the servo in FRC last year. Once I get you our shop I’ll mess around with some FTC programming and try to figure it out.

Simplest fix is following:

import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.CRServo;

@TeleOp(name = “TestServo2 (Blocks to Java)”, group = “”)
public class TestServo2 extends LinearOpMode {

private CRServo con_servo;

/**
* This function is executed when this Op Mode is selected from the Driver Station.
*/
@Override
public void runOpMode() {
con_servo = hardwareMap.crservo.get(“con_servo”);


waitForStart();
while (opModeIsActive()) {
  if (gamepad1.a) {
    con_servo.setPower(1);
  }
  if (gamepad1.b) {
    con_servo.setPower(-1);
  }
  if (gamepad1.atRest()) {
    con_servo.setPower(0);
  }
  telemetry.update();
}
con_servo.setPower(0); // You have a potential to have a run after the loop, just shut it off when the opmode closes


}
}

That is it! Enjoy!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.