Page 1 of 1

BricxCC Ultrasonic Sensor Problem

Posted: 30 Jan 2011, 23:16
by pesso
I am using code (diagram 1.0) for solving a maze. Here is a PDL of what I'm doing:

1) Check US Sensor
2) Move Motor
3) Check US Sensor
4) Move Motor
5) Check US Sensor
6) Move Motor Back To Starting Position
7) Display Values

The motor move fine, but on the NXT's screen, it says "0", "0", and "0"; :!: :?:

The US Sensor is connected correctly into port 4.

Code: Select all

task main(){
      int distance1;
      int distance2;
      int distance3;
      bool object_forward;
      bool object_left;
      bool object_right;
      distance1=SensorUS(S4); // Forward
      RotateMotor(OUT_A, 75, 90);
      distance2=SensorUS(S4); // Right
      RotateMotor(OUT_A, -75, 180);
      distance3=SensorUS(S4); // Left
      RotateMotor(OUT_A, 75, 90);
      TextOut(0, 0, NumToStr(distance1));
      TextOut(0, 8, NumToStr(distance2));
      TextOut(0, 16, NumToStr(distance3));
  
       //More Stuff....

}
Above: diagram 1.0

Please Reply With What I Am Doing Wrong.

-- Clen, Pesso, Tanf, Whatever You Want To Call Me

Re: BricxCC Ultrasonic Sensor Problem

Posted: 30 Jan 2011, 23:24
by gloomyandy
I'm not and NXC expert but I think you will need to initialise the sensor port and tell it what type of sensor you have attached to it...

Andy

Re: BricxCC Ultrasonic Sensor Problem

Posted: 30 Jan 2011, 23:40
by mattallen37
Indeed. Try adding the following line to the beginning of the program.

SetSensorLowspeed(S4);

Re: BricxCC Ultrasonic Sensor Problem

Posted: 30 Jan 2011, 23:44
by pesso
Thanks!

It Works Now.

--Clen