VEX Ultrasonic Sensor

Hi,
I have been trying to use the vex ultrasonic sensor on the FRC robot and have had no success. I think the problem may be in the way i wired the sensor. I have both the wires going into the Digital I/O on the sidecar ports 3,1. I am using the WPILib ultrasonic class and can only manage to read zeros. Also on the driver station, under the diagnostics tab, the error messages box keeps saying assertion failed. Can some one help me get this sensor to read values or should i just order a “FRC” sensor.

Thanks

Please copy and paste the assertion that is failing and the code you wrote. We can’t guess what’s wrong otherwise.

We are having the same problems and error, the sensor is not showing any distance changes but is staying at 0. The error appears on the driver’s station diagnostic tab.
==================ERROR====================
Assertion Failed: “m_downSource!=NULL” in clearDownSource() in c:/windriver/workspace/wpilib/counter.cpp at line 337.

================Source Code=================

#include “WPILib.h”

DriverStationLCD *dsLCD = DriverStationLCD::GetInstance();

class ArmyOfSumRobot : public IterativeRobot
{
/Initialize interaction with Hardware/
RobotDrive *MyRobot; //Robot Drive
DriverStation *Ds; //Driver Station

Ultrasonic *USleft;

public:

ArmyOfSumRobot(void)
{
	Ds = DriverStation::GetInstance();
	
	MyRobot = new RobotDrive(1,2,3,4);// create robot drive base with 4 motors

    USleft = new Ultrasonic(4,5); // create ultra sonic on digital IO 4,5 in inches
}

void AutonomousContinuous(void)
{
	GetWatchdog().Feed();
}
void TeleopContinuous(void)
{
	GetWatchdog().Feed();

	dsLCD->Printf(DriverStationLCD::kUser_Line1, 1, "ultra sonic left: %g", USleft->GetRangeInches());
}

void DisabledPeriodic(void)
{
	GetWatchdog().Feed(); // feed the user watchdog at every period when disabled
}

void TeleopPeriodic(void)
{
	GetWatchdog().Feed(); // feed the user watchdog at every period when in autonomous

}

void DisabledContinuous(void)
{
	GetWatchdog().Feed(); //do nothing
}

void AutonomousPeriodic(void)
{
	GetWatchdog().Feed(); //do nothing
}
/********************************** Init Routines *************************************/
void DisabledInit(void)
{
}

void AutonomousInit(void)
{
}

void TeleopInit(void)
{
}

void RobotInit(void)
{
	
             //initialize ultrasonics
	USleft->SetDistanceUnits(Ultrasonic::kInches);
	USleft->SetAutomaticMode(TRUE);
	
	 
}

};

START_ROBOT_CLASS(ArmyOfSumRobot);

I believe that was fixed in the latest C++ update.

Please try updating and let us know if it works or if the error was just a red herring.

-Joe

I think the assertion is likely a red herring in this case. I see that same message when using the GearTooth class but I am still counting teeth just fine.

On a side note, then, have you updated to the most recent C++ update and you still see this, or are you still running the update from kickoff?

-Joe

Joe,

We had the assert error with the vex sensors in the prior WPILib release, but the current WPILib release no longer asserts. Which is good :slight_smile:

However, for some reason our sensors work inconsistently – most of the time they read 120 or 249 – but if I put my hand right in front of it, then it will read a few inches… maybe out to 5 inches or so before it jumps back to 249. I’m hoping it’s a wiring problem (it worked at first with the previous version, but then it started exhibiting the 120/249 behavior and I couldn’t get it to work correctly), but maybe not.

That type of behavior is usually caused by the sensor not seeing a reflection.