AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Ultrasonic Exception Error

The forum is to discuss topics related to robotics, like building robot, controlling it, its software and hardware, etc.

Ultrasonic Exception Error

Postby RobotFan » Sat Oct 15, 2011 1:06 pm

Hello,
I am new to Aforge, and I have been trying to read the ultrasonic sensor value, connected on port 1 of my Lego NXT, but the 1st time I call the method GetUltrasonicSensorValue, an Application Exception is fired with error code 221, but if I call the method again, a good value is obtained from the sensor. What does error code 221 mean? I am thinking of looping this method call until a successful result is obtained in order to tackle this problem. Is this the correct way to go about it?

Thank you for your time,

RobotFan
RobotFan
 
Posts: 3
Joined: Sat Oct 15, 2011 12:33 pm

Re: Ultrasonic Exception Error

Postby andrew.kirillov » Mon Oct 17, 2011 4:45 am

Hello,

Did you do this (from docs):
"Before using this method it is required to use SetSensorMode() method to set sensor's type to Lowspeed9V mode. It should be done once after NXT brick is powered on. If sensor's type is not set properly, the method will generate an exception. Also after setting sensor's type application may need to wait a bit to give device some time to initialize."
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3429
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Ultrasonic Exception Error

Postby RobotFan » Mon Oct 17, 2011 11:44 am

Yes I am setting the sensor each time I connect to the NXT as follows:

nxt.SetSensorMode(NXTBrick.Sensor.First,
NXTBrick.SensorType.Lowspeed9V,
NXTBrick.SensorMode.Raw);

I tried waiting various amounts of times for the bus to initialise, from 30seconds to over a minute, but to no avail. However if I disconnect and reconnect to the robot (hence this would be the second call of GetUltrasonicSensorValue) the method seems to work fine, even though 30seconds 'wait time' have not passed from my initial connection. I also noticed that the same error has occured once during execution well after the connection was established and the method was returning good values until the exception was fired.

Thanks,

RobotFan
RobotFan
 
Posts: 3
Joined: Sat Oct 15, 2011 12:33 pm




Return to Robotics