Go to Post FIRST is like Starbucks coffee, it's addicting and you just can't seem to get away from it... - Beth Sweet [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Media   CD-Spy  
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 23-02-2016, 08:22
joeojazz joeojazz is offline
Registered User
FRC #5712
 
Join Date: Jan 2016
Location: Hemlock
Posts: 42
joeojazz is an unknown quantity at this point
Encoder Problems

Hi can anyone help with encoder code we are using java and can't seem to receive any variables back from them.
Thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 23-02-2016, 10:19
otherguy's Avatar
otherguy otherguy is online now
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Encoder Problems

What type of encoder (model #) are you using?

How have you wired it up to the roboRIO?

Can you provide a copy of your code so we can check it?

Have you tried following the java encoder code example here?: https://wpilib.screenstepslive.com/s...or-other-shaft
__________________
http://team2168.org

Last edited by otherguy : 23-02-2016 at 10:23.
Reply With Quote
  #3   Spotlight this post!  
Unread 23-02-2016, 10:19
Pratik Kunapuli's Avatar
Pratik Kunapuli Pratik Kunapuli is offline
Probably browning-out on Astro-Turf
FRC #1648 (G3 Robotics)(EWCP)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Atlanta, GA
Posts: 143
Pratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to all
Re: Encoder Problems

Quote:
Originally Posted by joeojazz View Post
Hi can anyone help with encoder code we are using java and can't seem to receive any variables back from them.
Thanks
Can you give more details as to what encoder you are using, how it is wired, and what your code looks like?
__________________
Official Driving Record: 101-59-0
2012-2015 Student 341 Miss Daisy
2015-Current Mentor 1648 G3 Robotics
Reply With Quote
  #4   Spotlight this post!  
Unread 23-02-2016, 10:33
marshall's Avatar
marshall marshall is online now
My pants are louder than yours.
FRC #0900 (The Zebracorns)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2003
Location: North Carolina
Posts: 1,246
marshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond reputemarshall has a reputation beyond repute
Re: Encoder Problems

Quote:
Originally Posted by joeojazz View Post
Hi can anyone help with encoder code we are using java and can't seem to receive any variables back from them.
Thanks
Got 99 problems and quadrature is 1, no wait... 2 of them?

-Check wiring
-Check the encoder
-Hook up a scope to the lines and see if you get the response you expect
-Check your code, are you calling on the right variables? Are they changing as expected? Is anything being overwritten or called incorrectly? Perhaps you could share a snippet of your code to help with debugging.
__________________
"La mejor salsa del mundo es la hambre" - Miguel de Cervantes
"The future is unwritten" - Joe Strummer
"Simplify, then add lightness" - Colin Chapman
Reply With Quote
  #5   Spotlight this post!  
Unread 23-02-2016, 10:38
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,018
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Encoder Problems

Quote:
Originally Posted by joeojazz View Post
Hi can anyone help with encoder code we are using java and can't seem to receive any variables back from them.
The more effort you put into providing detailed information, the more likely you are to receive quick and accurate advice.

What are you using the encoder for? To measure speed, or distance, or both? Drivetrain? Shooter wheelspeed control?

What motor controller are you using, and do you have the encoder wired to the roboRIO or to the motor controller (TalonSRX)?


Reply With Quote
  #6   Spotlight this post!  
Unread 23-02-2016, 14:49
joeojazz joeojazz is offline
Registered User
FRC #5712
 
Join Date: Jan 2016
Location: Hemlock
Posts: 42
joeojazz is an unknown quantity at this point
Re: Encoder Problems

Sorry for the lack of information.

We are trying to use encoders attached to the sonic shifter from AndyMark.

Sonic Shifter:
http://www.andymark.com/Sonic-Shifte...nicoptions.htm

And the encoder being used with the sonic shifter is the am-3132:
http://www.andymark.com/product-p/am-3132.htm

We have them wired from the encoder into the RoboRio's DIO ports. Each encoder requires two ports because they each have 2 signal channels (A and B).
Code:
package org.usfirst.frc.team5712.robot;

import com.kauailabs.navx_mxp.AHRS;
import com.ni.vision.NIVision.Image;

import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.CounterBase;
import edu.wpi.first.wpilibj.CounterBase.EncodingType;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SerialPort;
import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.Servo;
import edu.wpi.first.wpilibj.Timer;

/**
 * 
 * @author Phillip Spannagel
 *
 */
public class Robot extends IterativeRobot {

	Joystick driveStick;
	CameraServer forwardCam, reverseCam;

	VictorSP leftFront, leftRear, rightFront, rightRear, shooterR, shooterL, armLift;

	Servo servo;
	RobotDrive drive;

	SerialPort serial_port;
	
	SendableChooser autonomous;
	
	AHRS gyro;
	Encoder encoderLeft, encoderRight, encoderLift;

	double angle;
	int tickGoal = 15 * 24;
	int shootCount = 0;
	int autoLoopCounter = 0;
	
	public void robotInit() {
		driveStick = new Joystick(0);

		leftFront = new VictorSP(0);
		leftRear = new VictorSP(1);
		rightFront = new VictorSP(2);
		rightRear = new VictorSP(3);
		shooterL = new VictorSP(4);
		shooterR = new VictorSP(5);
		armLift = new VictorSP(6);
		
		servo = new Servo(7);

		drive = new RobotDrive(leftFront, leftRear, rightFront, rightRear);

		serial_port = new SerialPort(57600, SerialPort.Port.kMXP);
		byte update_rate_hz = 50;

		gyro = new AHRS(serial_port, update_rate_hz);
		gyro.resetDisplacement();

		encoderRight = new Encoder(0, 1, false, Encoder.EncodingType.k4X);
		encoderRight.setDistancePerPulse(1);
		encoderRight.setMaxPeriod(.1);
		encoderRight.setMinRate(10);
		encoderRight.setSamplesToAverage(7);

		encoderLeft = new Encoder(2, 3, false, Encoder.EncodingType.k4X);
		encoderLeft.setDistancePerPulse(1);
		encoderLeft.setMaxPeriod(.1);
		encoderLeft.setMinRate(10);
		encoderLeft.setSamplesToAverage(7);

		encoderLift = new Encoder(4, 5, false, Encoder.EncodingType.k4X);
		encoderLift.setDistancePerPulse(1);

		forwardCam = CameraServer.getInstance();
		reverseCam = CameraServer.getInstance();

		forwardCam.setQuality(50);
		reverseCam.setQuality(50);

		forwardCam.startAutomaticCapture();
		reverseCam.startAutomaticCapture();
	}

	public void autonomousInit() {

		// drive.setInvertedMotor(RobotDrive.MotorType.kFrontLeft, true);
		// drive.setInvertedMotor(RobotDrive.MotorType.kFrontRight, true);
		// drive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, true);
		// drive.setInvertedMotor(RobotDrive.MotorType.kRearRight, true);
		//start = true;
		
		gyro.zeroYaw();
		
		servo.setAngle(180);
		
		encoderLeft.reset();
		encoderRight.reset();
	}

	public void autonomousPeriodic() {
		
		angle = gyro.getYaw();
		
			
		if (autoLoopCounter < 500) {
			drive.drive(-0.3, 0.0);//start moving
			
			// gyro drive "straight"
			if (angle < -2)
			{
				rightFront.set(-0.5);
				rightRear.set(-0.5);
				
			}
			if (angle > 2) 
			{
				leftFront.set(-0.5);
				leftRear.set(-0.5);
			}
			
			}
			else if (autoLoopCounter == 500) 
			{
				drive.drive(0, 0);
				gyro.zeroYaw();
				
			}
			
			else if (autoLoopCounter < 700)
			{
					leftFront.set(-.3);
					leftRear.set(-.3);
					rightFront.set(.3);
					rightRear.set(.3);
					if(gyro.getYaw() > -145 && gyro.getYaw() < -150) {
						leftFront.set(0);
						leftRear.set(0);
						rightFront.set(0);
						rightRear.set(0);
				}
			}
			

		autoLoopCounter++;
		
		SmartDashboard.putNumber("Yaw", gyro.getYaw());
		SmartDashboard.putNumber("Servo Angle", servo.getAngle());
		/*
		 * SmartDashboard.putNumber("Count (Left)", encoderLeft.get());
		 * SmartDashboard.putNumber("Count (Right)", encoderRight.get());
		 * 
		 * SmartDashboard.putNumber("Distance (Left)",
		 * encoderLeft.getDistance()); SmartDashboard.putNumber("Raw (Left)",
		 * encoderLeft.getRaw()); SmartDashboard.putNumber("Rate (Left)",
		 * encoderLeft.getRate());
		 * 
		 * SmartDashboard.putNumber("Distance (Right)",
		 * encoderRight.getDistance()); SmartDashboard.putNumber("Raw (Right)",
		 * encoderRight.getRaw()); SmartDashboard.putNumber("Rate (Right)",
		 * encoderRight.getRate());
		 */
		SmartDashboard.putNumber("encoder (Lift)", encoderLift.get());

	}

	public void teleopPeriodic() {

		drive.arcadeDrive(driveStick);

		if (driveStick.getRawButton(1) == true) {
			drive.arcadeDrive(driveStick);
			shooterL.set(1.0);
			shooterR.set(-1.0);
			servo.setAngle(90);
			shootCount++;

			if (shootCount > 50) {
				shooterL.set(0);
				shooterR.set(0);
				servo.setAngle(180);
				shootCount = 0;
			}
		}

		if (driveStick.getRawButton(1) == false && shootCount != 0) {
			shootCount = 1;
		}

		// set servo angle
		if (driveStick.getRawButton(8) == true) {
			servo.setAngle(180);
		}
		if (driveStick.getRawButton(9) == true) {
			servo.setAngle(30);
		}

		// intake
		if (driveStick.getRawButton(2) == true) {
			shooterL.set(-.6);
			shooterR.set(.6);
		} else if (driveStick.getRawButton(2) == false) {
			shooterL.set(0);
			shooterR.set(0);
		}

		// raise and lower shooting arm
		if (driveStick.getRawButton(3) == true) {
			armLift.set(.5);
		} else if (driveStick.getRawButton(4) == true) {
			armLift.set(-.5);
		} else if (driveStick.getRawButton(3) == false) {
			armLift.set(0);
		}
	}
	public void testPeriodic() {
		/*if(start = true){
		if(angle < 180)
		{
			leftFront.set(.5);
			leftRear.set(.5);
			rightRear.set(-.5);
			rightRear.set(-0.5);
		}
		else if(angle == 180)
		{
			leftFront.set(0);
			leftRear.set(0);
			rightRear.set(0);
			rightFront.set(0);
		}
		if(angle == 180){
			start = false;
		}
	}
	if(start = false){
			gyro.resetDisplacement();
			gyro.zeroYaw();
		}
	*/
	}
}
I included all of our code. Please let me know if you need any more information.

Last edited by joeojazz : 23-02-2016 at 16:43.
Reply With Quote
  #7   Spotlight this post!  
Unread 23-02-2016, 15:52
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Encoder Problems

This looks suspicious:
Code:
	// Encoder encoderLeft, encoderRight,
Doesn't the encoderRight = new Encoder(); line give you an error because encoderRight isn't defined?
Reply With Quote
  #8   Spotlight this post!  
Unread 23-02-2016, 15:59
otherguy's Avatar
otherguy otherguy is online now
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Yea, I agree with Alan. This code shouldn't even compile.

Code:
//Encoder encoderLeft, encoderRight
Shouldn't be commented out.
__________________
http://team2168.org
Reply With Quote
  #9   Spotlight this post!  
Unread 23-02-2016, 16:24
joeojazz joeojazz is offline
Registered User
FRC #5712
 
Join Date: Jan 2016
Location: Hemlock
Posts: 42
joeojazz is an unknown quantity at this point
Re: Encoder Problems

We had commented sections of the encoder code that were not working. Before I pasted the code on here I attempted to un-comment everything, but it seems I forgot a couple lines.

Sorry everybody.
Reply With Quote
  #10   Spotlight this post!  
Unread 23-02-2016, 16:25
joeojazz joeojazz is offline
Registered User
FRC #5712
 
Join Date: Jan 2016
Location: Hemlock
Posts: 42
joeojazz is an unknown quantity at this point
Re: Encoder Problems

Even when the code was un-commented we still were not receiving values. I edited the code, so it should be able to compile now.

Last edited by joeojazz : 23-02-2016 at 16:44. Reason: Typo
Reply With Quote
  #11   Spotlight this post!  
Unread 23-02-2016, 20:16
Pratik Kunapuli's Avatar
Pratik Kunapuli Pratik Kunapuli is offline
Probably browning-out on Astro-Turf
FRC #1648 (G3 Robotics)(EWCP)
Team Role: Mentor
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Atlanta, GA
Posts: 143
Pratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to allPratik Kunapuli is a name known to all
Re: Encoder Problems

The E4T encoder has a very specific installation process, especially when interfacing with the AndyMark gearbox. I would make sure that the disk for the encoder is the correct distance away from the sensor (by using the spacing tool), as I've seen incorrect installations return no values.
__________________
Official Driving Record: 101-59-0
2012-2015 Student 341 Miss Daisy
2015-Current Mentor 1648 G3 Robotics
Reply With Quote
  #12   Spotlight this post!  
Unread 23-02-2016, 23:19
otherguy's Avatar
otherguy otherguy is online now
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
If you put a meter between find and channel A and B, you should be able to see the logic levels change as the wheel turns.
If you can measure this, the encoder is working properly and its either a wiring or code problem.
If you don't get fluctuating values on the meter, then its likely that the disk within the encoder isn't installed correctly per Pratiks suggestion
__________________
http://team2168.org
Reply With Quote
  #13   Spotlight this post!  
Unread 27-02-2016, 14:47
otherguy's Avatar
otherguy otherguy is online now
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Find = Ground. Autocorrect...

...Put a meter between ground and channel A or B...
__________________
http://team2168.org
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 14:08.

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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi