View unanswered posts | View active topics It is currently Sat Dec 27, 2014 10:47 pm






Reply to topic  [ 4 posts ] 
Sonar Sensor 
Author Message
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Post Sonar Sensor
Dear,
i want to use the sonar sensor
i wrote a program to detect an obstacle and go backward but the program not working

#pragma config(Sensor, S4, sonarSensor, sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{

int distance_in_cm = 5; // Create variable 'distance_in_cm' and initialize it to 5(cm).
{
// While the Sonar Sensor readings are greater
// than the specified, 'distance_in_cm':
while(SensorValue[sonarSensor] > distance_in_cm)
// go forward
motor[motorA] = 12;
motor[motorC] = 12;
}
{
// go backward
motor[motorA] = -12;
motor[motorC] = -12;
}
}

how to solve the problem?
thanks in advance
best regards


Mon May 13, 2013 2:30 am
Profile
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Post Re: Sonar Sensor
i found the problem, i use this code and working
#pragma config(Sensor, S4, sonarSensor, sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
// Move forward until 7 cm from the wall.
while (SensorValue(sonarSensor) > 7)
{
motor[motorA] = 10;
motor[motorC] = 10;

}

// go backward
motor[motorA] = -6;
motor[motorC] = -6;
wait1Msec(5000);
}

if i try to use the sonar sensor in 5 cm not working, 6 cm or greater working
can i use sonar sensor for value smaller than 5 cm?


Mon May 13, 2013 2:46 am
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Sonar Sensor
Generally, the accuracy of the LEGO distance sensor is... only fair, at best. Normally when you get to really small distances like 5cm it fails to read that.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Mon May 13, 2013 10:24 am
Profile WWW
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
Post Re: Sonar Sensor
thanks bro


Mon May 13, 2013 6:15 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.