|
amullen98
Rookie
Joined: Sun Mar 11, 2012 11:15 pm Posts: 3
|
 Finding a Candle
Hey,
I am working on a project and I am used ROBOTC to program my NXT robot.
For this program I need to use the light senor to locate and go to the candle but I am having trouble getting it to work.
What I need for it to do is check for light and if it finds a strong enough light source to go to the source and just quit the entire program if it does not find a strong enough light source it needs to break out and back into the main function so it can continue on to the next room.
I have the light sensor attached to the robot almost like an arm pointing straight out infront.
If you have any ideas please let me know thanks!!
#pragma config(Sensor, S1, light, sensorLightInactive) #pragma config(Sensor, S4, Sonar, sensorSONAR) #pragma config(Motor, motorB, RightWheel, tmotorNormal, PIDControl, encoder) #pragma config(Motor, motorC, LeftWheel, tmotorNormal, PIDControl, encoder) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
void checkLight();
task main () { nMotorPIDSpeedCtrl[motorC] = mtrSpeedReg; nMotorPIDSpeedCtrl[motorB] = mtrSpeedReg;
motor[motorC] = 100; motor[motorB] = 100; wait1Msec(1000); checkLight(); motor[motorC] = 100; motor[motorB] = 100; wait1Msec(5000); }
void checkLight() { if (SensorValue(light) > 60) { while (SensorValue(Sonar) > 15 ) { motor[motorC] = 25; motor[motorB] = 25; } }
else motor[motorC] = -25; motor[motorB] = 50; return; }
|