OCCRA
Go to Post Oh, and your t-square and pencil can't crash, unlike your laptop :D - scottydoh [more]
Home
Go Back   Chief Delphi > Other > FIRST Tech Challenge
CD-Media  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-12-2018, 08:00 PM
Robohawk Robohawk is offline
Registered User
VRC #14697
 
Join Date: Nov 2018
Location: Fennville
Posts: 1
Robohawk is an unknown quantity at this point
[FTC]: FTC Android Studio java encoder help.

Hey, me and my buddy are first time FTC mentors and do not understand how to program the encoders in autonomous. Any examples we find are coded in different libraries or use different Op Modes. I anyone can point us in the right direction or give us tips, it would be much appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 11-20-2018, 12:00 AM
LLR11541 LLR11541 is offline
Registered User
FTC #11541
 
Join Date: Nov 2018
Location: Renton, WA
Posts: 3
LLR11541 is an unknown quantity at this point
Re: [FTC]: FTC Android Studio java encoder help.

This is our teams encoder test program for 2 wheels. If using Mencanum this might not work. We use 2 main methods with encoders, one being saying a distance to go, which lets the motors stop automatically. The second way to use an encoder is to track it and to look at the value to stop your self.


In this program we set a distance and let the motors stop automatically. For Mencanum wheels I would recommend tracking the values on one wheel.
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//This is the Hardware base, in this we show we connected the hardware
// to our program.
//////////////////////////////////////////////////
public class HardwareTestingBase
{
/* Public OpMode members. */
public DcMotor left_drive = null;
public DcMotor right_drive = null;
public NormalizedColorSensor colorSensor = null;

/* local OpMode members. */
HardwareMap hardwareMap = null;

private static final double COUNTS_PER_MOTOR_REV = 537.6 ; // eg: Countable events per revolution of Output shaft
private static final double DRIVE_GEAR_REDUCTION = 1.0 ; // This is < 1.0 if geared UP
private static final double WHEEL_DIAMETER_INCHES = 4.0 ; // For figuring circumference
public static final double COUNTS_PER_INCH = (COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) /
(WHEEL_DIAMETER_INCHES * 3.1415);

private ElapsedTime period = new ElapsedTime();

/* Constructor */
public HardwareTestingBase(){

}

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

// Define and Initialize Motors
left_drive = hardwareMap.get(DcMotor.class, "left");
right_drive = hardwareMap.get(DcMotor.class, "right");

left_drive.setDirection(DcMotor.Direction.FORWARD) ; // Set to REVERSE if using AndyMark motors
right_drive.setDirection(DcMotor.Direction.REVERSE );// Set to FORWARD if using AndyMark motors

// Get a reference to our sensor object.
colorSensor = hardwareMap.get(NormalizedColorSensor.class, "colorsensor");

// Set all motors to zero power
left_drive.setPower(0);
right_drive.setPower(0);

// Set all motors to run without encoders.
// May want to use RUN_USING_ENCODERS if encoders are installed.
left_drive.setMode(DcMotor.RunMode.RUN_USING_ENCOD ER);
right_drive.setMode(DcMotor.RunMode.RUN_USING_ENCO DER);
}
}
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//This is the encoder program!!!
//In this program we use a state machine (because our mentor made us! But now it is helpful when running things in parallel).
// This program was based off of the sample code by the sample program
//PushbotAutoDriveByEncoder_Linear.
/////////////////////////////////////////////////////////////////////////////////////
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous ;
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.hardware.DcMotor;
import com.qualcomm.robotcore.util.Range;

@Autonomous(name="TestingBase: Encoder Iterative Test", group="TestingBase")

public class TestingBaseEncoder_Iterative extends OpMode {

/* Declare OpMode members. */
HardwareTestingBase robot = new HardwareTestingBase(); // use the class created to define a Pushbot's hardware

static final double FORWARD_SPEED = 0.1;
static final double TURN_SPEED = 0.25;

enum RobotState
{
Setup,
Start,
Finish,
Done
}
RobotState state = RobotState.Setup;


/*
* Code to run ONCE when the driver hits INIT
*/
@Override
public void init() {
int newLeftTarget;
int newRightTarget;

/* Initialize the hardware variables.
* The init() method of the hardware class does all the work here
*/
robot.init(hardwareMap);

// Send telemetry message to signify robot waiting;
telemetry.addData("Say", "Hello Driver"); //
}

/*
* Code to run REPEATEDLY after the driver hits INIT, but before they hit PLAY
*/
@Override
public void init_loop() {
}

@Override
public void start() {
}

/*
* Code to run REPEATEDLY after the driver hits PLAY but before they hit STOP
*/
@Override
public void loop() {
telemetry.addData("Current State", state.toString());

switch (state)
{
case Setup:
encoderDrive_Start(FORWARD_SPEED, 12, 12); // S1: Forward 47 Inches with 5 Sec timeout
state = RobotState.Start;
break;

case Start:
if (encoderDrive_IsDone()) {
state = RobotState.Finish;
}
break;

case Finish:
encoderDrive_Complete();
state = RobotState.Done;
break;
}
}

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

public void encoderDrive_Start(double speed,
double leftInches, double rightInches) {

int newLeftTarget;
int newRightTarget;

// Determine new target position, and pass to motor controller
newLeftTarget = robot.left_drive.getCurrentPosition() + (int) (leftInches * HardwareTestingBase.COUNTS_PER_INCH);
newRightTarget = robot.right_drive.getCurrentPosition() + (int) (rightInches * HardwareTestingBase.COUNTS_PER_INCH);
robot.left_drive.setTargetPosition(newLeftTarget);
robot.right_drive.setTargetPosition(newRightTarget );

// Turn On RUN_TO_POSITION
robot.left_drive.setMode(DcMotor.RunMode.RUN_TO_PO SITION);
robot.right_drive.setMode(DcMotor.RunMode.RUN_TO_P OSITION);

// reset the timeout time and start motion.
robot.left_drive.setPower(Math.abs(speed));
robot.right_drive.setPower(Math.abs(speed));
}

public boolean encoderDrive_IsDone() {
return !(robot.left_drive.isBusy() && robot.right_drive.isBusy());
}

public void encoderDrive_Complete() {
// Stop all motion;
robot.left_drive.setPower(0);
robot.right_drive.setPower(0);

// Turn off RUN_TO_POSITION
robot.left_drive.setMode(DcMotor.RunMode.RUN_USING _ENCODER);
robot.right_drive.setMode(DcMotor.RunMode.RUN_USIN G_ENCODER);
}
// I hope this helps!
Reply With Quote
  #3   Spotlight this post!  
Unread 11-20-2018, 12:12 AM
LLR11541 LLR11541 is offline
Registered User
FTC #11541
 
Join Date: Nov 2018
Location: Renton, WA
Posts: 3
LLR11541 is an unknown quantity at this point
Re: [FTC]: FTC Android Studio java encoder help.

Or go to TestingBaseEncoder

or

TestingBaseEncoder

and here is the sample code from ftc


PushbotAutoDriveByEncoder
Reply With Quote
  #4   Spotlight this post!  
Unread 11-20-2018, 12:22 AM
LLR11541 LLR11541 is offline
Registered User
FTC #11541
 
Join Date: Nov 2018
Location: Renton, WA
Posts: 3
LLR11541 is an unknown quantity at this point
Re: [FTC]: FTC Android Studio java encoder help.

Noticed the titles were not correct...

TestingBaseEncoder_Iterative
TestingBaseEncoder_Linear


Quote:
Originally Posted by LLR11541 View Post
Or go to TestingBaseEncoder

or

TestingBaseEncoder

and here is the sample code from ftc


PushbotAutoDriveByEncoder
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:57 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi