View unanswered posts | View active topics It is currently Thu Jun 21, 2018 8:33 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Sonar Sensor
Author Message
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
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 !!*//

{

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?
best regards

Mon May 13, 2013 2:30 am
Novice

Joined: Wed Feb 20, 2013 2:46 am
Posts: 64
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 !!*//

{
// 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
Senior Roboticist

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
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
Novice

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

Mon May 13, 2013 6:15 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning