Ultrasonic Rangefinder always -1

I have a problem with my new Ultrasonic Rangefinder which I am trying to isolate where the problem is


-ROBOTC 2.32
-Cortex Microcontroller with VEXnet Controller
-Squarebot design robot upsized to 25x25 chassis with 4” wheels.
-Ultrasonic Rangefinder Output wire in Digital port 8, Input Wire on Digital port 9 (in agreement with program). First use of Rangefinder out of box. So far in other ROBOTC programs, Line -Trackers and Encoders work fine.
-Sample Program “Forward until Close Proximity”
-Changes: motors reversed
-Behavior: Robot runs into 12” wide, 8” object. Debugger shows value SONAR (cm) -1 in black during runtime and continuous refresh with objects in front. Never red like with other sensors receiving data.

Please let me know if you have any ideas to further isolate the problem.

Thanks,

Jake

Hi Jacob,

The Input wire must always be plugged into the lower port number - it should be plugged into Port 8, while Output should be plugged into Port 9.

Jesse,

Thanks for the speedy reply. If I reverse the wires, port 8 “SONAR (cm)” is still black -1 all the time, but port 9 “SONAR 2nd Port” alternates between 0 and 1 in red. The robot runs into the object.

Jake

Hi Jacob,

Please post your code, and if you could, a screenshot of what the debug window is showing.

Sure, here is the program. It is the sample program with the motors reversed. Each time I try, I start from the sample program. Input wire is in digital port 8. Output wire is in digital port 9.

======================================

#pragma config(Sensor, dgtl8, sonarSensor, sensorSONAR_cm)
#pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop)
#pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

/----------------------------------------------------------------------------------------------------
|* - Forward until Close Proximity - |
|
ROBOTC on VEX 2.0 CORTEX |
|
|
|
This program instructs the robot to drive forward at half speed until the Ultrasonic Sensor |
|
detects an obstruction within 20 inches of it. |
|
There is a two second pause at the beginning of the program. |
|
|
|
ROBOT CONFIGURATION |
|
NOTES: |
|
1) Reversing ‘rightMotor’ (port 2) in the “Motors and Sensors Setup” is needed with the |
|
“Squarebot” mode, but may not be needed for all robot configurations. |
|
2) The Ultrasonic Sensor returns a value of ‘-1’ when it is out of range from the nearest |
|
object. The range is from 0 to 255 inches, so make sure that the robot is within this |
|
range or it may never run. |
|
|
|
MOTORS & SENSORS: |
|
* [Name] [Type] [Description] |
|
Motor - Port 2 rightMotor VEX 3-wire module Right side motor |
|
Motor - Port 3 leftMotor VEX 3-wire module Left side motor |
|
Digital - Port 9,10 sonarSensor VEX Sonar Sensor Front mounted, facing forward |
*-----------------------------------------------------------------------------------------------4246-
/

//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main()
{
wait1Msec(2000); // Robot waits for 2000 milliseconds before executing program

while(SensorValue(sonarSensor) > 20  || SensorValue(sonarSensor) == -1)		// Loop while robot's Ultrasonic sensor is further than 20 inches away from an object
{                                                                         // || (or) it is '-1'.  (-1 is the value returned when nothing is in it's visable range)
	motor[rightMotor] = 63;			// Motor on port2 is run at half (63) power forward
	motor[leftMotor]  = 63;			// Motor on port3 is run at half (63) power forward
}

}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*

I have a attached a copy of the debug status as it is running.
rangefinder -1 status.pdf (160 KB)

Hi Jacob,

Are you pointing the sensor at broad, hard objects such as a wall - this will return the best results. Also, is your robot powered using a battery? Having the Cortex powered only over USB won’t provide enough power to get results.

Do you have another sensor that you can try, to check if this one is broken?

You might also want to try another pair of ports, to see if that behaves differently.

Yes, I have been using a box about a foot wide. I have also used a hand at various distances while the debugger is on continuous refresh, which still has -1.

I am using a batter 3000mAh battery.

I do not have a 2nd rangefinder to compare results with.

I have tried ports 5+6 both ways with the same result.

Thanks,

Jake

Unfortunately, it sounds like your ultrasonic rangefinder may be bad. I’d recommend contacting VEX for a replacement, if possible.

Thanks for looking into this Jesse. I will ask VEX to replace it.

Jake

The replacement part works just fine. Problem solved. Thanks.

Jake