My team is using RobotC Graphical. We are trying to use a distance sensor to move the robot to the center of the field to better line up to dump balls into the tower. The sample program for Detect Wall shows a wait until getDistanceValue(distanceMM) to set the distance value. However, that is not recognized by RobotC when we try to use it, giving us an error. We have tried the plain getDistanceValue with both inches and mm and the robot just keeps driving, it doesn’t stop when it gets to the correct distance. Our plan is to drive to the middle of the field and then back up, but we though the distance sensor would help us line up more consistently. Any advice?
Firstly check that your distance sensor is working properly - On the Brain, press X to access settings and then go to device info. Scroll through using the arrow buttons until you find your distance sensor. Use something flat (book/piece of card etc) to see if the distance changes and gives a realistic reading. Also, keep in mind that the distance sensor has a maximum reading which I think is 1000mm. A better soloution might be to use the colour sensor in greayscale mode - face it down at the floor and detect the black line to stop on.
Calvc01, did you mean grayscale?
This could be the sample snippet for distance sensor.
// Simple Proximity Sensor using Infrared
// Description: Measure the distance to an obstacle using infrared light emitted by IR LED and
// read the value with a IR photodiode. The accuracy is not perfect, but works great
// with minor projects.
// Author: Ricardo Ouvina
// Date: 01/10/2012
// Version: 1.0
int IRpin = A0; // IR photodiode on analog pin A0
int IRemitter = 2; // IR emitter LED on digital pin 2
int ambientIR; // variable to store the IR coming from the ambient
int obstacleIR; // variable to store the IR coming from the object
int value[10]; // variable to store the IR values
int distance; // variable that will tell if there is an obstacle or not
void setup(){
Serial.begin(9600); // initializing Serial monitor
pinMode(IRemitter,OUTPUT); // IR emitter LED on digital pin 2
digitalWrite(IRemitter,LOW);// setup IR LED as off
pinMode(11,OUTPUT); // buzzer in digital pin 11
}
void loop(){
distance = readIR(5); // calling the function that will read the distance and passing the “accuracy” to it
Serial.println(distance); // writing the read value on Serial monitor
// buzzer(); // uncomment to activate the buzzer function
}
Apple Laptop Repair in Bangalore
Dell Laptop Repair in Bangalore
Thanks a lot for the Information …about Distance Sensor Programming