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