Ultrasonic sensor

Dec 4, 2009 at 2:58 PM

I'm trying to use your library to control my robot, and everything is working excellently except ultrasonic sensor.

I use

...

robot.SetInputMode(ultrasonicPort, SensorType.LowSpeed9V, SensorMode.Raw);

...

And have a function to read the sensor:

public int sonicRead()
{
return robot.GetInputValues(usonicPort).ScaledValue;
}

But this always returns 1023.

I've tried setting the different SensorMode, as well as reading RawValue, but everything either returns 1023, or 100 (as in 100%).

Is there any way I can get a proper reading from ultrasonic sensor?

Jun 10, 2010 at 4:01 PM

Hi, I do this to read the ultrasonic sensor values.

 

 private void btnUltraSensor_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
              this._nxt.LowSpeedWrite((SensorPort)this.cboBoxUltra.SelectedIndex, new byte[] { 0x02, 0x42 }, 1);
              System.Threading.Thread.Sleep(2000);
              byte[] readValues = this._nxt.LowSpeedRead((SensorPort)this.cboBoxUltra.SelectedIndex);
              this.txtBoxUltra.Text = readValues[0].ToString();
            Cursor.Current = Cursors.Default;
        }

 

It works for the Mobile Devices.

Jun 10, 2010 at 4:51 PM
Thanks for the info. :)

-----Original Message-----
From: chustas [mailto:[email removed]
Sent: Thu 6/10/2010 5:01 PM
To: Goran Narancic
Subject: Re: Ultrasonic sensor [NxtNet:77118]

From: chustas

Hi, I do this to read the ultrasonic sensor values. private void btnUltraSensor_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
this._nxt.LowSpeedWrite((SensorPort)this.cboBoxUltra.SelectedIndex, new byte[] { 0x02, 0x42 }, 1);
System.Threading.Thread.Sleep(2000);
byte[] readValues = this._nxt.LowSpeedRead((SensorPort)this.cboBoxUltra.SelectedIndex);
this.txtBoxUltra.Text = readValues[0].ToString();
Cursor.Current = Cursors.Default;
} It works for the Mobile Devices.