View unanswered posts | View active topics It is currently Sat May 18, 2013 8:47 pm

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Using a while loop with Sonar Sensor (before 21/10/2011)
Author Message
Rookie

Joined: Tue Mar 01, 2011 6:16 pm
Posts: 21
Using a while loop with Sonar Sensor (before 21/10/2011)
Hy, thats the code i want the robot to do.
 Code:#pragma config(Sensor, S2,     LightSensor,         sensorLightActive)#pragma config(Sensor, S3,     sonarSensor,         sensorSONAR)#pragma config(Motor,  motorA,          a,             tmotorNormal, PIDControl, encoder)#pragma config(Motor,  motorB,          b,             tmotorNormal, PIDControl, encoder)#pragma config(Motor,  motorC,          c,             tmotorNormal, PIDControl, encoder)//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//task main(){  motor[a]= 0;  motor[b]= 30;  motor[c]= 40;  wait10Msec(810);   while(true)   {      if(SensorValue(LightSensor) > 33)      {motor[a]= 0;motor[b]= 10;motor[c]= 15;      }      else      {motor[a]= 0;motor[b]= -15;motor[c]= -10;wait10Msec(190);  motor[a]= 80;  motor[b]= 0;  motor[c]= 0;  wait10Msec(450);   motor[a]= 0;  motor[b]= 10;  motor[c]= 15;  wait10Msec(100);    motor[a]= -80;  motor[b]= 0;  motor[c]= 0;  wait10Msec(450);      }   }}

But that code its a loop so when it begans it doesn't stop. What i want to know, is the code for make the robot stop or go backwards, when it reaches a distance of 10 cm from the wall. Please i need that answer before friday 21/10/2011! thanks.

Wed Oct 19, 2011 2:03 pm

Joined: Wed Jan 24, 2007 10:44 am
Posts: 421
Location: Pittsburgh, PA
Re: Using a while loop with Sonar Sensor (before 21/10/2011)
If you want the condition to check for a distance away from the wall, you want to use the "sonarSensor" in the condition.

So change this:
 Code:if(SensorValue(LightSensor) > 33)

To this:
 Code:if(SensorValue(sonarSensor) > 10)

Notice that I changed 33 to 10. You specified you wanted to set a distance of 10cm away from the wall.

_________________
Vu Nguyen
Software Training Development Team | Webmaster
Need more support? Use the ROBOTC Ticketing system

Robotc.net| Robomatter Store | Robotics Academy

Thu Oct 20, 2011 9:13 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 2 posts ]

#### Who is online

Users browsing this forum: No registered users and 8 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 Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions    Robotics Merit Badge Robotics Discussions    General Discussions    Project Discussions International Forums    Spanish Forums       ROBOTC for MINDSTORMS       ROBOTC for VEX    French Forums       ROBOTC pour Mindstorms       ROBOTC pour IFI VEX    Japanese Forums （日本語のフォーラム） 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

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