View unanswered posts | View active topics It is currently Thu Aug 13, 2020 2:04 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Skipping a sensor
Author Message
Rookie

Joined: Fri Apr 26, 2013 11:05 am
Posts: 39
Skipping a sensor
Can someone help me understand why this student's code is skipping the very first sensor, sonar and moving on to the second command set.

Thank you.

#pragma config(Sensor, S1, touch, sensorTouch)
#pragma config(Sensor, S2, touch, sensorTouch)
#pragma config(Sensor, S3, lightsensor, sensorLightActive)
#pragma config(Sensor, S4, sonar, sensorSoundDB)
#pragma config(Motor, motorB, rightMotor, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, motorC, leftMotor, tmotorNXT, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

{
while(true)
{
while(SensorValue(sonar)> 25)

{
motor[motorB] = 30; // go forward until the distance is less than 25 cm
motor[motorC] = 30;
}

motor[motorB] = 20; // turn right
motor[motorC] = 40;
wait1Msec(1500);
}
while(SensorValue(touch) == 0)

{

if(SensorValue(lightsensor)< 50)

{
motor[motorB] = 60; //if the light value is more than 50 you turn left
motor[motorC] = 0;

}

else

{
motor[motorB] = 0; //if the light value is less than 50 you turn right
motor[motorC] = 60;

}

}
motor[motorB] = 0; //when the touch sensor is pushed the robot stops
motor[motorC] = 0;
}

Mon Apr 13, 2015 10:19 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Skipping a sensor
You can't have both sensors named "touch". Rename them to "touch1" and "touch2" and all will be well. Make sure to modify the code, too, of course.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Mon Apr 13, 2015 10:52 am
Rookie

Joined: Fri Apr 26, 2013 11:05 am
Posts: 39
Re: Skipping a sensor
I did this and nothing changed. The sonic sensor was still skipped over. So, I traded out the sensors, the cables and even ran the program on a different computer, without any success. Then for some odd reason, the program ran as expected on the robot. The students made a change on their distance for the ultrasonic sensor and it would not run. It's as if there is some glitch in the hardware and it pokes its ugly head out when it wants to!

Mon Apr 13, 2015 2:44 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Re: Skipping a sensor
I don't know what you meant by "skipping the sonar sensor over", but if you format the code with proper indentation, you will notice that it has a forever while-loop. It means the second while-loop with the touch and light sensors is "unreachable".
 Code:task main(){    while(true)    {        while(SensorValue(sonar)> 25)        {            motor[motorB] = 30; // go forward until the distance is less than 25 cm            motor[motorC] = 30;        }        motor[motorB] = 20; // turn right        motor[motorC] = 40;        wait1Msec(1500);    }    //    // The following code will never be executed.    //    while(SensorValue(touch) == 0)    {        if(SensorValue(lightsensor)< 50)        {            motor[motorB] = 60; //if the light value is more than 50 you turn left            motor[motorC] = 0;        }        else        {            motor[motorB] = 0; //if the light value is less than 50 you turn right            motor[motorC] = 60;        }    }    motor[motorB] = 0; //when the touch sensor is pushed the robot stops    motor[motorC] = 0;}

Tue Apr 14, 2015 3:44 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 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