Domanda

I am trying to create a simple version of VFH (Vector Field Histogram) on the NXT using NBC (next byte code). To do this I need to accurately measure the distance between the robot and an object. Since the NXT can show the distance in centimeters, I want to program the distance in centimeters in my program? Since there is no default centimeter reading(or is there?), can this be done or do I have to use the default sensor values? If it can, how do I do it? If not, how can I translate the ultrasonic sensor readings into centimeter readings?

Thanks in advance.

È stato utile?

Soluzione

The default output is a byte value giving you centimeters.

task main(){
   int DistanceInCm;

   SetSensorLowspeed(IN_4);
   while(true){
     DistanceInCm = SensorUS(IN_4);
     //do something with the value here.
     Wait(800); //or just wait.
   }
}

It's as simple as that. The sensor reading is a byte (0-255 cm). But the NXC compiler casts it into an into an int on the fly.

Note, though that the sensor is not very accurate! Especially if you read it while moving. So expect a lot of errors and noise in the readings.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top