![]() |
Encoders Programming
Hello my name is David and I'm tge lead programmer for FRC Team 4780 and I was wondering if anyone could tell me how to programm the 2013 KOP quadrature encoders.
|
Re: Encoders Programming
Everything covered in your other thread is directly applicable.
http://www.chiefdelphi.com/forums/sh...d.php?t=119184 |
Re: Encoders Programming
Also you should check out the Javadoc page for the Encoder class. If you weren't aware, you can find the Javadoc for WPILib at 'C:\Users\username\sunspotfrcsdk\doc\javadoc\index.html' on any computer set up for Java development. Alternatively, here's a link to a copy on the web. Particularly note the Encoder#get() and Encoder#getRate() methods, which give you the position and the rotation rate of the encoder respectively.
|
Re: Encoders Programming
Quote:
|
Re: Encoders Programming
Im using them on the Toughbox Mini (am-0654) to track distance in autonomous.
|
Re: Encoders Programming
Hey so I've been trying to get the encoders programmed on the Toughbox Mini (am-0654) but have been running into a problem. Everytime I get a distance from the encoders it goes from 0.3 to 0.0, any suggestions?
public void takeJoystickInputs(Joystick right) { SmartDashboard.putData("Left Encoder Distance", leftEncoder); SmartDashboard.putData("Right Encoder Distance", rightEncoder); if ((36+((leftEncoder.getDistance()+ -rightEncoder.getDistance())/2)) > 0) {robotDrive2.arcadeDrive(right.getY(), -right.getX());} else robotDrive2.drive(0, 0); //robotDrive2.arcadeDrive(right.getY(), -right.getX()); } |
Re: Encoders Programming
Quote:
Also note that using the Encoder#getDistance() method requires you to have set a distance with Encoder#setDistancePerPulse(double). If you didn't set this value, you will be getting inaccurate readings. Assuming the encoders are 360 pulses/revolution (which the kit E4Ps should be), the number you need is just the distance your robot travels in one encoder revolution divided by 360. |
Re: Encoders Programming
Hey so I've been trying to get the encoders programmed on the Toughbox Mini (am-0654) but have been running into a problem. Everytime I get a distance from the encoders it goes from 0.3 to 0.0, any suggestions?
public void takeJoystickInputs(Joystick right) { SmartDashboard.putData("Left Encoder Distance", leftEncoder); SmartDashboard.putData("Right Encoder Distance", rightEncoder); if ((36+((leftEncoder.getDistance()+ -rightEncoder.getDistance())/2)) > 0) {robotDrive2.arcadeDrive(right.getY(), -right.getX());} else robotDrive2.drive(0, 0); //robotDrive2.arcadeDrive(right.getY(), -right.getX()); } |
Re: Encoders Programming
Quote:
|
Re: Encoders Programming
Quote:
An encoder that toggles between 0 and another value is because the software is only reading a single channel, instead of both channels. This could be because of a wiring problem or a software initialization problem (as in you hooked channel A and B to DIO 1 and 2, but told the software to use DIO 2 and 3. Switching A & B makes the encoder count in reverse, but still counts. |
Re: Encoders Programming
public void takeEncoderInputs() {
leftEncoder.start(); rightEncoder.start(); leftEncoder.setDistancePerPulse(18.84/1620); rightEncoder.setDistancePerPulse(18.84/1620); leftEncoder.getDistance(); rightEncoder.getDistance(); SmartDashboard.putData("Left Encoder Distance", leftEncoder); SmartDashboard.putData("Right Encoder Distance", rightEncoder); |
Re: Encoders Programming
Quote:
|
Re: Encoders Programming
Looking at your other thread, I see you are using the AS5145B Magnetic Encoders, not the US Digital E4Ps. According to this page, these encoders output 1024 pulses per revolution, unlike the E4Ps which are only 360 pulses/revolution.
Have you looked at this page yet? It explains how quadrature encoders work, and gives some examples of how to use the WPILib Encoder class. The constructor call is where you create the Encoder object, usually as an instance variable of your robot class. For example, to create an Encoder with the A channel in DIO 1, the B channel in DIO 2, counting the normal direction and 4X decoding, you would use this: Code:
Encoder myEncoder = new Encoder(1, 2, false, EncodingType.k4X); |
Re: Encoders Programming
My bad, here you go
driveTrainLeftEncoder = new Encoder(1, 1, 1, 2, false, EncodingType.k4X); driveTrainRightEncoder = new Encoder(1, 3, 1, 4, false, EncodingType.k4X); |
Re: Encoders Programming
I've gone through my wiring and code several times and still can't figure out why the encoders' values keep resetting. It feel like I'm so close but so far away from because of this.
|
| All times are GMT -5. The time now is 13:03. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi