Go to Post Ok, according to this, I am a hacker...Now will someone please come fix my computer??? - Beth Sweet [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rating: Thread Rating: 13 votes, 4.69 average. Display Modes
  #1   Spotlight this post!  
Unread 29-01-2011, 20:57
agentace agentace is offline
Registered User
FRC #2522
 
Join Date: Feb 2010
Location: Lynnwood High School
Posts: 8
agentace is an unknown quantity at this point
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
Reply With Quote
  #2   Spotlight this post!  
Unread 29-01-2011, 21:07
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2011, 03:13
AllenGregoryIV's Avatar
AllenGregoryIV AllenGregoryIV is offline
Engineering Coach
AKA: Allen "JAG" Gregory
FRC #3847 (Spectrum)
Team Role: Coach
 
Join Date: Jul 2008
Rookie Year: 2003
Location: Texas
Posts: 2,549
AllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond reputeAllenGregoryIV has a reputation beyond repute
Send a message via AIM to AllenGregoryIV
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 30-01-2011, 10:14
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
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;

import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.Robot2011.DataStructure;

/**
 *
 * @author Robotics2011
 */
public class CVEncoder
{
    private Encoder spin[];
    private int numOfEncoders;

    public CVEncoder(int n)//takes in number of encoders
    {
        numOfEncoders = n;
        if(numOfEncoders > 8)
        {
            numOfEncoders = 8;
        }
        else if(numOfEncoders < 0)
        {
            numOfEncoders = 0;
        }

        spin = new Encoder[numOfEncoders];
        int counter = 1;
        for(int i = 0; i < numOfEncoders; i ++)
        {
            spin[i] = new Encoder(i + counter, i + counter + 1);
            counter ++;
        }
        for(int i = 0; i < numOfEncoders; i ++)
        {
            spin[i].start();//took 3 hours to figure this out, but electronics was still at fault
        }
    }

    public void setRotation(double circumference, int c)//to caculate rate and dist; circumference in feet
    {
        spin[c].setDistancePerPulse(circumference / 360.0);//cirumference divided by 360 degrees [per pulse]
    }
    //rate - ft/s
    //dist - ft
    //direction - 1 is forward, -1 if backward
    public void update(DataStructure dat)//update inhited privates with dist, dir, and rate
    {
        for(int num = 0; num < numOfEncoders; num ++)
        {
            //Direction formatting
            double direction = 0;
            if(spin[num].getStopped() == false && spin[num].getDirection() == true)//allegedly, Encoder class returns negative int for forward
                direction = 1.0;
            else if(spin[num].getStopped() == false && spin[num].getDirection() == false)
                direction = -1.0;
            dat.setDirection(num, direction);
            dat.setDistance(num, spin[num].getDistance());
            dat.setRate(num, spin[num].getRate());
            dat.setStopped(num, spin[num].getStopped());
            dat.setPulses(num, spin[num].get());
        }
    }
    public void neutralize(DataStructure dat)
    {
        for(int num = 0; num < numOfEncoders; num ++)
        {
            spin[num].stop();
            spin[num].start();
            spin[num].reset();
        }
        update(dat);
    }
    public int numberOfEncoders()
    {
        return numOfEncoders;
    }
}
DataStructure.java:
Code:
package edu.wpi.first.wpilibj.Robot2011;
/**
 *
 * @author Robotics2011
 */
public class DataStructure
{
    //Encoder Variables
    private int numEncoders;//set number of encoders
    private double rate[];
    private double distance[];
    private double direction[];
    private double pulses[];
    private boolean stopped[];

  public DataStructure()
    {
        //Setting Encoder Variables to 0
        numEncoders = 0;
    }
public void constructEncoders(int num)
    {
        numEncoders = num;
        rate = new double[numEncoders];
        distance = new double[numEncoders];
        direction = new double[numEncoders];
        pulses = new double[numEncoders];
        stopped = new boolean[numEncoders];
        for(int i = 0; i < numEncoders; i ++)
        {
            rate[i] = 0.0;
            distance[i] = 0.0;
            direction[i] = 0.0;
            pulses[i] = 0.0;
            stopped[i] = true;
        }
    }

//Start Encoder Accessors and Manipulators
    public void setRate(int num, double x)
    {
        rate[num] = x;
    }
    public double getRate(int num)
    {
        return rate[num];
    }
    public void setDistance(int num, double d)
    {
        distance[num] = d;
    }
    public double getDistance(int num)
    {
        return distance[num];
    }
    public void setDirection(int num, double d)
    {
        direction[num] = d;
    }
    public double getDirection(int num)
    {
        return direction[num];
    }
    public void setPulses(int num, double i)
    {
        pulses[num] = i;
    }
    public double getPulses(int num)
    {
        return pulses[num];
    }
    public void setStopped(int num, boolean b)
    {
        stopped[num] = b;
    }
    public boolean getStopped(int num)
    {
        return stopped[num];
    }
    //End Encoder Accessors and Manipulators
}
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #5   Spotlight this post!  
Unread 08-02-2011, 10:17
java4first java4first is offline
(Java) Programming Mentor
AKA: Stu
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Nov 2010
Rookie Year: 2011
Location: Goffstown, NH
Posts: 56
java4first is an unknown quantity at this point
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
Reply With Quote
  #6   Spotlight this post!  
Unread 08-02-2011, 11:13
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Java Encoder Problem

Quote:
Originally Posted by java4first View Post
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
We are using the exact same ones
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #7   Spotlight this post!  
Unread 08-02-2011, 22:02
CapnKernul CapnKernul is offline
Registered User
FRC #1515
 
Join Date: Feb 2011
Location: Beverly Hills
Posts: 3
CapnKernul is an unknown quantity at this point
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!
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 10:33.

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