|
Page 1 of 1
|
[ 4 posts ] |
|
Author |
Message |
Korndog
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 !!*//
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); } 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 |
|
 |
mightor
Site Admin
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 |
|
 |
Korndog
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 |
|
 |
MHTS
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".
|
Tue Apr 14, 2015 3:44 am |
|
|
|
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 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
|
|