View Single Post
  #1   Spotlight this post!  
Unread 25-03-2011, 20:14
TomH's Avatar
TomH TomH is offline
Registered User
FRC #0087
Team Role: Alumni
 
Join Date: Jan 2010
Rookie Year: 2009
Location: New Jersey
Posts: 53
TomH has a spectacular aura aboutTomH has a spectacular aura aboutTomH has a spectacular aura about
Encoder and Ultrasonic Help

A few of us got together the other day and worked on a few different things. Two of those things were quad encoders and a ultrasonic sensor.

We had readouts for both but only one seemed to be giving a readout of a value. We were only able to count up to 256ish on one encoder though. How would we properly code and wire these encoders so they could work properly?
Below is some of the code that we have been using to test:

Quote:
import edu.wpi.first.wpilibj.Encoder;

Encoder encoderleft;
Encoder encoderright;

encoderleft = new Encoder (4,5);
encoderright = new Encoder (6,7);
double inchesPerPulse = 0.1;*


double lDistance = encoderleft.getDistance();
int lCount = encoderleft.get();

double rDistance = encoderright.getDistance();
int rCount = encoderright.get();

*Values for inches per pulse is a random number-Asterisks not in real code
As mentioned above, our ultrasonic sensor didn't seem to want to work at all. We were getting infinity on our readouts, and only values when we messed around with the pwm connections. How would we code and wire up the ultrasonic so that it would work as well?
Below is some of the code we used to test:

Quote:
import edu.wpi.first.wpilibj.Ultrasonic;

Ultrasonic ultrasonic1;

ultrasonic1 = new Ultrasonic (8,9);

System.out.println("Ultrasonic distance = " + ultrasonic1.getRangeInches());
Any help is greatly appreciated, and thanks in advance.

-Tom H

Last edited by TomH : 25-03-2011 at 20:20.
Reply With Quote