We are trying to strafe during teleop and it works its just not smooth or accurate. Our autonomous works great, it seems like during teleop its at half power and jerky. I am attaching our code, hardware first then our teleop.
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
public class HardwarePushbot
{
//Motors
public DcMotor left1 = null;
public DcMotor left2 = null;
public DcMotor right1 = null;
public DcMotor right2 = null;
public DcMotor intake = null;
public DcMotorEx shooter = null;
public DcMotor lift = null;
public Servo leftHand = null;
public Servo rightHand = null;
/* 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
left1 = hwMap.get(DcMotor.class, "left1");
left2 = hwMap.get(DcMotor.class, "left2");
right1 = hwMap.get(DcMotor.class, "right1");
right2 = hwMap.get(DcMotor.class, "right2");
shooter = hwMap.get(DcMotorEx.class, "shooter");
intake = hwMap.get(DcMotor.class, "intake");
lift = hwMap.get(DcMotor.class, "lift");
//Set motor direction
left1.setDirection(DcMotor.Direction.REVERSE);
left2.setDirection(DcMotor.Direction.REVERSE);
right1.setDirection(DcMotor.Direction.FORWARD);
right2.setDirection(DcMotor.Direction.FORWARD);
intake.setDirection(DcMotor.Direction.REVERSE);
shooter.setDirection(DcMotor.Direction.FORWARD);
lift.setDirection(DcMotor.Direction.FORWARD);
// Define and Initialize Servos
leftHand = hwMap.get (Servo.class,"leftHand");
rightHand = hwMap.get (Servo.class,"rightHand");
// Set all motors to zero power
left1.setPower(0);
left2.setPower(0);
right1.setPower(0);
right2.setPower(0);
intake.setPower(0);
shooter.setPower(0);
lift.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
left1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER) ;
left2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER) ;
right1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
right2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
intake.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
lift.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// set the drive motors to brake when zero power is applied
left1.setZeroPowerBehavior(DcMotor.ZeroPowerBehavi or.BRAKE);
left2.setZeroPowerBehavior(DcMotor.ZeroPowerBehavi or.BRAKE);
right1.setZeroPowerBehavior(DcMotor.ZeroPowerBehav ior.BRAKE);
right2.setZeroPowerBehavior(DcMotor.ZeroPowerBehav ior.BRAKE);
//set the shooter motor to run using encoders to use velocity instead of motor power
shooter.setMode(DcMotor.RunMode.RUN_USING_ENCODER) ;
}
}
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
public class HardwarePushbot
{
//Motors
public DcMotor left1 = null;
public DcMotor left2 = null;
public DcMotor right1 = null;
public DcMotor right2 = null;
public DcMotor intake = null;
public DcMotorEx shooter = null;
public DcMotor lift = null;
public Servo leftHand = null;
public Servo rightHand = null;
/* 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
left1 = hwMap.get(DcMotor.class, "left1");
left2 = hwMap.get(DcMotor.class, "left2");
right1 = hwMap.get(DcMotor.class, "right1");
right2 = hwMap.get(DcMotor.class, "right2");
shooter = hwMap.get(DcMotorEx.class, "shooter");
intake = hwMap.get(DcMotor.class, "intake");
lift = hwMap.get(DcMotor.class, "lift");
//Set motor direction
left1.setDirection(DcMotor.Direction.REVERSE);
left2.setDirection(DcMotor.Direction.REVERSE);
right1.setDirection(DcMotor.Direction.FORWARD);
right2.setDirection(DcMotor.Direction.FORWARD);
intake.setDirection(DcMotor.Direction.REVERSE);
shooter.setDirection(DcMotor.Direction.FORWARD);
lift.setDirection(DcMotor.Direction.FORWARD);
// Define and Initialize Servos
leftHand = hwMap.get (Servo.class,"leftHand");
rightHand = hwMap.get (Servo.class,"rightHand");
// Set all motors to zero power
left1.setPower(0);
left2.setPower(0);
right1.setPower(0);
right2.setPower(0);
intake.setPower(0);
shooter.setPower(0);
lift.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
left1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER) ;
left2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER) ;
right1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
right2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
intake.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
lift.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// set the drive motors to brake when zero power is applied
left1.setZeroPowerBehavior(DcMotor.ZeroPowerBehavi or.BRAKE);
left2.setZeroPowerBehavior(DcMotor.ZeroPowerBehavi or.BRAKE);
right1.setZeroPowerBehavior(DcMotor.ZeroPowerBehav ior.BRAKE);
right2.setZeroPowerBehavior(DcMotor.ZeroPowerBehav ior.BRAKE);
//set the shooter motor to run using encoders to use velocity instead of motor power
shooter.setMode(DcMotor.RunMode.RUN_USING_ENCODER) ;
}
}
Here is our teleop:
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.util.Range;
@TeleOp(name="Bruh_Fast", group="Pushbot")
public class Bruh_Fast extends OpMode{
/* Declare OpMode members. */
HardwarePushbot robot = new HardwarePushbot();
@Override
public void init() {
robot.init(hardwareMap);
telemetry.addData("Say", "Hello Driver");
}
@Override
public void init_loop() {
}
@Override
public void start() {
}
@Override
public void loop() {
double left;
double right;
double intake;
double shooter;
double lift;
// Run wheels in tank mode (note: The joystick goes negative when pushed forwards, so negate it)
left = -gamepad1.left_stick_y * .8;
right = -gamepad1.right_stick_y * .8;
//intake is run using gamepad 2 left stick
intake = -gamepad2.left_stick_y;
robot.left1.setPower(left);
robot.left2.setPower(left);
robot.right1.setPower(right);
robot.right2.setPower(right);
robot.intake.setPower(intake);
// Use gamepad 1 B to strafe right
if (gamepad1.b)
{robot.left1.setPower(.8);
robot.left2.setPower(-.8);
robot.right1.setPower(-.8);
robot.right2.setPower(.8);}
//use gamepad 1 x to strafe left
if (gamepad1.x)
{robot.left1.setPower(-.8);
robot.left2.setPower(.8);
robot.right1.setPower(.8);
robot.right2.setPower(-.8); }
//Gamepad 2 buttons y and a control the linear lift
if (gamepad2.y)
{robot.lift.setPower(.8);
}
else if (gamepad2.a)
{robot.lift.setPower(-.8);
}
else
{robot.lift.setPower(0);
}
//Gamepad 1 right bumper shoots at the high goal
if(gamepad1.right_bumper)
{robot.shooter.setPower(.7);}
//Gamepad 1 left bumper shoots at the power shots
else if (gamepad1.left_bumper)
{robot.shooter.setPower(.65);}
else
{robot.shooter.setPower(0);}
telemetry.addData("left", "%.2f", left);
telemetry.addData("right", "%.2f", right);
/* Servos */
// Servo Hands Grab Wobble Goal
// gamepad 2 b button closes both hands
if(gamepad2.b){
robot.leftHand.setPosition(.85);
robot.rightHand.setPosition(.15);
}
//gamepad 2 button x opens both hands
else if (gamepad2.x){
robot.leftHand.setPosition(.2);
robot.rightHand.setPosition(.8);}
// gamepad 2 left bumper closes the left hand only
if(gamepad2.left_bumper){
robot.leftHand.setPosition(.85);}
//gamepad 2 right bumper closes the right hand only
if (gamepad2.right_bumper){
robot.rightHand.setPosition(.15);}
}
/*
* Code to run ONCE after the driver hits STOP
*/
@Override
public void stop() {
}
}
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
public class HardwarePushbot
{
//Motors
public DcMotor left1 = null;
public DcMotor left2 = null;
public DcMotor right1 = null;
public DcMotor right2 = null;
public DcMotor intake = null;
public DcMotorEx shooter = null;
public DcMotor lift = null;
public Servo leftHand = null;
public Servo rightHand = null;
/* 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
left1 = hwMap.get(DcMotor.class, "left1");
left2 = hwMap.get(DcMotor.class, "left2");
right1 = hwMap.get(DcMotor.class, "right1");
right2 = hwMap.get(DcMotor.class, "right2");
shooter = hwMap.get(DcMotorEx.class, "shooter");
intake = hwMap.get(DcMotor.class, "intake");
lift = hwMap.get(DcMotor.class, "lift");
//Set motor direction
left1.setDirection(DcMotor.Direction.REVERSE);
left2.setDirection(DcMotor.Direction.REVERSE);
right1.setDirection(DcMotor.Direction.FORWARD);
right2.setDirection(DcMotor.Direction.FORWARD);
intake.setDirection(DcMotor.Direction.REVERSE);
shooter.setDirection(DcMotor.Direction.FORWARD);
lift.setDirection(DcMotor.Direction.FORWARD);
// Define and Initialize Servos
leftHand = hwMap.get (Servo.class,"leftHand");
rightHand = hwMap.get (Servo.class,"rightHand");
// Set all motors to zero power
left1.setPower(0);
left2.setPower(0);
right1.setPower(0);
right2.setPower(0);
intake.setPower(0);
shooter.setPower(0);
lift.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
left1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER) ;
left2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER) ;
right1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
right2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
intake.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
lift.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// set the drive motors to brake when zero power is applied
left1.setZeroPowerBehavior(DcMotor.ZeroPowerBehavi or.BRAKE);
left2.setZeroPowerBehavior(DcMotor.ZeroPowerBehavi or.BRAKE);
right1.setZeroPowerBehavior(DcMotor.ZeroPowerBehav ior.BRAKE);
right2.setZeroPowerBehavior(DcMotor.ZeroPowerBehav ior.BRAKE);
//set the shooter motor to run using encoders to use velocity instead of motor power
shooter.setMode(DcMotor.RunMode.RUN_USING_ENCODER) ;
}
}
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.ElapsedTime;
public class HardwarePushbot
{
//Motors
public DcMotor left1 = null;
public DcMotor left2 = null;
public DcMotor right1 = null;
public DcMotor right2 = null;
public DcMotor intake = null;
public DcMotorEx shooter = null;
public DcMotor lift = null;
public Servo leftHand = null;
public Servo rightHand = null;
/* 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
left1 = hwMap.get(DcMotor.class, "left1");
left2 = hwMap.get(DcMotor.class, "left2");
right1 = hwMap.get(DcMotor.class, "right1");
right2 = hwMap.get(DcMotor.class, "right2");
shooter = hwMap.get(DcMotorEx.class, "shooter");
intake = hwMap.get(DcMotor.class, "intake");
lift = hwMap.get(DcMotor.class, "lift");
//Set motor direction
left1.setDirection(DcMotor.Direction.REVERSE);
left2.setDirection(DcMotor.Direction.REVERSE);
right1.setDirection(DcMotor.Direction.FORWARD);
right2.setDirection(DcMotor.Direction.FORWARD);
intake.setDirection(DcMotor.Direction.REVERSE);
shooter.setDirection(DcMotor.Direction.FORWARD);
lift.setDirection(DcMotor.Direction.FORWARD);
// Define and Initialize Servos
leftHand = hwMap.get (Servo.class,"leftHand");
rightHand = hwMap.get (Servo.class,"rightHand");
// Set all motors to zero power
left1.setPower(0);
left2.setPower(0);
right1.setPower(0);
right2.setPower(0);
intake.setPower(0);
shooter.setPower(0);
lift.setPower(0);
// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
left1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER) ;
left2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER) ;
right1.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
right2.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
intake.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER );
lift.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
// set the drive motors to brake when zero power is applied
left1.setZeroPowerBehavior(DcMotor.ZeroPowerBehavi or.BRAKE);
left2.setZeroPowerBehavior(DcMotor.ZeroPowerBehavi or.BRAKE);
right1.setZeroPowerBehavior(DcMotor.ZeroPowerBehav ior.BRAKE);
right2.setZeroPowerBehavior(DcMotor.ZeroPowerBehav ior.BRAKE);
//set the shooter motor to run using encoders to use velocity instead of motor power
shooter.setMode(DcMotor.RunMode.RUN_USING_ENCODER) ;
}
}
Here is our teleop:
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.util.Range;
@TeleOp(name="Bruh_Fast", group="Pushbot")
public class Bruh_Fast extends OpMode{
/* Declare OpMode members. */
HardwarePushbot robot = new HardwarePushbot();
@Override
public void init() {
robot.init(hardwareMap);
telemetry.addData("Say", "Hello Driver");
}
@Override
public void init_loop() {
}
@Override
public void start() {
}
@Override
public void loop() {
double left;
double right;
double intake;
double shooter;
double lift;
// Run wheels in tank mode (note: The joystick goes negative when pushed forwards, so negate it)
left = -gamepad1.left_stick_y * .8;
right = -gamepad1.right_stick_y * .8;
//intake is run using gamepad 2 left stick
intake = -gamepad2.left_stick_y;
robot.left1.setPower(left);
robot.left2.setPower(left);
robot.right1.setPower(right);
robot.right2.setPower(right);
robot.intake.setPower(intake);
// Use gamepad 1 B to strafe right
if (gamepad1.b)
{robot.left1.setPower(.8);
robot.left2.setPower(-.8);
robot.right1.setPower(-.8);
robot.right2.setPower(.8);}
//use gamepad 1 x to strafe left
if (gamepad1.x)
{robot.left1.setPower(-.8);
robot.left2.setPower(.8);
robot.right1.setPower(.8);
robot.right2.setPower(-.8); }
//Gamepad 2 buttons y and a control the linear lift
if (gamepad2.y)
{robot.lift.setPower(.8);
}
else if (gamepad2.a)
{robot.lift.setPower(-.8);
}
else
{robot.lift.setPower(0);
}
//Gamepad 1 right bumper shoots at the high goal
if(gamepad1.right_bumper)
{robot.shooter.setPower(.7);}
//Gamepad 1 left bumper shoots at the power shots
else if (gamepad1.left_bumper)
{robot.shooter.setPower(.65);}
else
{robot.shooter.setPower(0);}
telemetry.addData("left", "%.2f", left);
telemetry.addData("right", "%.2f", right);
/* Servos */
// Servo Hands Grab Wobble Goal
// gamepad 2 b button closes both hands
if(gamepad2.b){
robot.leftHand.setPosition(.85);
robot.rightHand.setPosition(.15);
}
//gamepad 2 button x opens both hands
else if (gamepad2.x){
robot.leftHand.setPosition(.2);
robot.rightHand.setPosition(.8);}
// gamepad 2 left bumper closes the left hand only
if(gamepad2.left_bumper){
robot.leftHand.setPosition(.85);}
//gamepad 2 right bumper closes the right hand only
if (gamepad2.right_bumper){
robot.rightHand.setPosition(.15);}
}
/*
* Code to run ONCE after the driver hits STOP
*/
@Override
public void stop() {
}
}
Comment