Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Encoders Programming (http://www.chiefdelphi.com/forums/showthread.php?t=120442)

TenaciousDrones 15-10-2013 11:23

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.

otherguy 15-10-2013 11:38

Re: Encoders Programming
 
Everything covered in your other thread is directly applicable.
http://www.chiefdelphi.com/forums/sh...d.php?t=119184

Domenic Rodriguez 15-10-2013 13:19

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.

Ether 15-10-2013 13:38

Re: Encoders Programming
 
Quote:

Originally Posted by TenaciousDrones (Post 1296568)
I was wondering if anyone could tell me how to programm the 2013 KOP quadrature encoders.

It depends on where the encoder is located (e.g. drive wheel gearbox, frisbee shooter wheel, etc) and what you are trying to accomplish with the signal (e.g. track distance in autonomous, control wheel speed, etc).



TenaciousDrones 30-10-2013 08:46

Re: Encoders Programming
 
Im using them on the Toughbox Mini (am-0654) to track distance in autonomous.

TenaciousDrones 30-10-2013 08:53

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());
}

Domenic Rodriguez 30-10-2013 09:50

Re: Encoders Programming
 
Quote:

Originally Posted by TenaciousDrones (Post 1299234)
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?

Code:

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());
}


Check the wiring of the encoders/PWMs. I know that my team has had similar issues when the PWM cables were plugged in backwards.

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.

TenaciousDrones 30-10-2013 12:43

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());
}

Ether 30-10-2013 14:04

Re: Encoders Programming
 
Quote:

Originally Posted by TenaciousDrones (Post 1299283)
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?

Can you draw and post a sketch of how you have it wired? Or take a couple of pictures (preferably with your camera set to "macro").



Joe Ross 30-10-2013 15:44

Re: Encoders Programming
 
Quote:

Originally Posted by TenaciousDrones (Post 1299234)
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?

Can you show your constructor call for the LeftEncoder and RightEncoder object?

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.

TenaciousDrones 31-10-2013 09:21

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);

Joe Ross 31-10-2013 12:05

Re: Encoders Programming
 
Quote:

Originally Posted by TenaciousDrones (Post 1299408)
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);

None of those are the constructor for leftEncoder or rightEncoder. Look for the part where you use new.

Domenic Rodriguez 31-10-2013 12:11

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);
Here's a simple example of using encoders to drive a robot in autonomous: https://gist.github.com/DomenicP/7252269

TenaciousDrones 01-11-2013 08:52

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);

TenaciousDrones 01-11-2013 11:24

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.

Joe Ross 01-11-2013 11:55

Re: Encoders Programming
 
You haven't yet posted how you wired it or taken any pictures, per Ether's request.

TenaciousDrones 01-11-2013 14:00

Re: Encoders Programming
 
1 Attachment(s)
So I have the two bare red wires to one of the grounds and the other to csn and soldered to the black which is connected to the other ground. I also have the blues connected to channel a and the yellow to channel b and red to 5v. the red and blue are in dio 1 and yellow and black are connected to dio 2.

Domenic Rodriguez 04-11-2013 13:45

Re: Encoders Programming
 
1 Attachment(s)
I found another thread related to the magnetic encoders. You might want to look through it if you haven't already: http://www.chiefdelphi.com/forums/sh...d.php?t=111202

Also, here's the non FIRST-specific data sheet for the sensor: http://www.ams.com/eng/content/downl...heet_v1-15.pdf

Unfortunately I can't see the wiring very well from the pictures provided, so I won't be of much help there. It seems the sensor has two modes of output: absolute position, and quadrature output. For you usage, you need to make sure you wire it for quadrature output. Here's the wiring:

Quote:

Originally Posted by Screen Steps Live
To wire the sensor to the FRC Control System, the following connections must be made:
  1. The pin labeled 5V on the sensor should be connected to a 5V (labeled "PWR") pin of the Digital Sidecar Digital I/O bank
  2. The 2 pins labeled GND should be connected to a ground pin (labeled "(-)") on the Digital Sidecar.
  3. The pins A and B should be connected to separate signal pins (labeled "SIG") on the Digital Sidecar.
  4. The pin CSn should be connected to a ground pin on the Digital Sidecar (for a description of the purpose of this pin, see "Incremental Power-up Lock Option" on Page 15 of the datasheet

Source. Attached is a sketch of what (I believe) the wiring should look like.

TenaciousDrones 04-11-2013 13:59

Re: Encoders Programming
 
yep thats exactly how it is wired

Ether 04-11-2013 14:39

Re: Encoders Programming
 
Quote:

Originally Posted by DomenicR (Post 1300083)
Unfortunately I can't see the wiring very well from the pictures provided

^ditto that.

What part number magnet are you using?



Domenic Rodriguez 04-11-2013 14:56

Re: Encoders Programming
 
Here are some other things to consider:

Are both encoders giving you identical output? It might be easier to look at the output using System.out.println() rather than SmartDashboard. The output goes to the console in NetBeans, and from my experience is more useful for debugging.

Are you calling Encoder#start() more than once for the encoders? You should only need to call it once at the beginning of the program, unless you stop counting with Encoder#stop(). I don't know if this would cause the encoder count to reset though.

Have you checked for hardware defects? Ensure that there is nothing wrong with your digital sidecar and cables. As Joe Ross mentioned earlier, the problem you described is often because only one channel of the encoder is being read.

Does your team have any other encoders, such as the US Digital E4P? You could try swapping one out temporarily to see if it behaves any differently. This would help identify it as a hardware or a software issue.

fovea1959 04-11-2013 16:55

Re: Encoders Programming
 
You may want to consider setting up a couple of DigitalInputs in code and read/println the two encoder inputs while slowly spinning the shaft by hand: you should be able to see the inputs toggle. That would tell you if it's wiring (or wrong/bad input) or problems setting up the Counter class....

Ether 14-11-2013 17:18

Re: Encoders Programming
 
Quote:

Originally Posted by TenaciousDrones (Post 1296568)
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.

Hi David. You haven't posted in 10 days. Did you ever get your problem solved? Please tell us about it.



TenaciousDrones 16-12-2013 13:57

Re: Encoders Programming
 
I still haven't figured out the encoder resetting problem sadly. I had about 2 months of just thinking about it while I worked on the Safety Animation but the program I came up with inevitably failed. I might just end up going through and yanking everything because the only thing I can think of is it's a wiring problem.


All times are GMT -5. The time now is 12:21.

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