![]() |
Java Encoder Problem
I am new to Java, but have a new mentor who is fluent in Java but not the FRC plugins. We have been trying to get the encoders to update their raw values on the Java debugging screen but have been only getting the output of 0.0. We know the encoders work because they work fine in LabVIEW, but not Java. This is the code I have so far:
private Encoder rightEncoder = new Encoder(4,5,4,6,true,CounterBase.EncodingType.k4X) ; private Encoder leftEncoder = new Encoder(4,7,4,8,true,CounterBase.EncodingType.k4X) ; and then in teleop periodic: System.out.println(" le="+leftEncoder.get() +" re="+rightEncoder.get()); Am I missing anything that would keep the encoders from posting the right values? Thanks. Pete Team 2522 |
Re: Java Encoder Problem
I've personally never had to deal with encoders before, but here's one thing you can try: see if doing rightEncoder.start(); leftEncoder.start(); does anything. If that fails, I'm as puzzled as you are.
|
Re: Java Encoder Problem
Patrick is correct inside of robotInit() you should call the start() method of each encoder that you are using. After that you should get values when you call getDistance().
One thing to note is that my team has had problems with getRate() and had to write our own getRate() method to get accurate results. |
Re: Java Encoder Problem
Yes: the encoder.start()... 3 programmers literally spent 3 hours trying to figure that out... But it turned out that we also wired it up all wrong because I am an idiot... But the team captain said my soldering was pretty good.
Here are the current revisions of our code: you will be surprised how long I had to fight to get the other programmers to agree on using arrays... They thought arrays will just complicate things. Now since I was the lead programmer, I pretty much said "I am doing it" and after I did it, they liked it.... -__-;; BTW the DataStructure is abridged; I only included the encoder stuff and took the rest out. CVEncoder.java: Code:
package edu.wpi.first.wpilibj.Robot2011.Perceive;Code:
package edu.wpi.first.wpilibj.Robot2011; |
Re: Java Encoder Problem
Thank you for the code snippets ... I'll defer on the topic of arrays for now.
But, I wondered if the encoders you are using are the Andy Mark ones we have and are planning to use: US Digital E4P-250-250-D-D-D-B encoder am-0174 http://www.andymark.com/ProductDetai...ctCode=AM-0174 That will at least save me from wondering about code differences vs. hardware differences. Thanks! Stu |
Re: Java Encoder Problem
Quote:
|
Re: Java Encoder Problem
Our team ran into the same exact problem. For some reason, the FPGA counting mechanism doesn't work right. Instead of using the CounterBase.EncodingType.k4X encoding type, try CounterBase.EncodingType.k1X instead. Worked for us.
Good luck! |
| All times are GMT -5. The time now is 08:10 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi