BricxCC Ultrasonic Sensor Problem

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
pesso
Posts: 8
Joined: 29 Sep 2010, 23:51
Location: Under your Bed

BricxCC Ultrasonic Sensor Problem

Post 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
51st Member Of MindBOARDS! (well, that's that the member's list says)
gloomyandy
Posts: 323
Joined: 29 Sep 2010, 05:03

Re: BricxCC Ultrasonic Sensor Problem

Post 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
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: BricxCC Ultrasonic Sensor Problem

Post by mattallen37 »

Indeed. Try adding the following line to the beginning of the program.

SetSensorLowspeed(S4);
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
pesso
Posts: 8
Joined: 29 Sep 2010, 23:51
Location: Under your Bed

Re: BricxCC Ultrasonic Sensor Problem

Post by pesso »

Thanks!

It Works Now.

--Clen
51st Member Of MindBOARDS! (well, that's that the member's list says)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests