|
Re: Cannot program two ultrasonic sensors. Please help us!
Hi, I'm programming something similar for our team's robot. For your code, I'm not sure if this was intentional or not, but in the Ultrasonic2 class default constructor, you don't seem to turn on automatic mode? However, I don't think that should be an issue.
Here are some possible ideas:
Automatic mode means that the sensor is continuously reading, correct? It's possible that having two ultrasonic sensors would cause interference with each other, if that's what's causing the error. If this were the issue, you should try implementing them without automatic mode (getting them to ping only when prompted).
However, if you cannot find a solution to this specific code, might I suggest implementing your sensors as analog inputs? The Ultrasonic class is, after all, an extension of the AnalogInput class, and what our team has been doing is treating the sensors as basic analog inputs, taking the readings, and then multiplying the number by some constant to retrieve the data in inches.
In this case, the implementation would be nearly identical to that of encoders, in terms of reading data and putting it onto the dashboard.
I hope some of this helps.
|