Page 1 of 1

Ultrasonic Exception Error

PostPosted: Sat Oct 15, 2011 1:06 pm
by RobotFan
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

Re: Ultrasonic Exception Error

PostPosted: Mon Oct 17, 2011 4:45 am
by andrew.kirillov
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."

Re: Ultrasonic Exception Error

PostPosted: Mon Oct 17, 2011 11:44 am
by RobotFan
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