|
chiboy002
Rookie
Joined: Fri Mar 30, 2012 3:15 am Posts: 1
|
 Help with Programming!
Hello Everyone, New Guy here
I am taking PLTW Engineering courses and have come across a small issue. My goal is to have the 'buzze1' blink for 10 seconds, or even light up, once the sensors are triggered, but I can't seem to get the light itself to work properly.
The way it differentiates between a soccer ball and a "human" is through a 5 second window. If the sensor is triggered twice in the five second window, the light is blocked, then the light will not flash because it will assume a goalie has entered the goal and exited. If it does not get triggered twice, then it will assume it was a ball traveling through.
However, the coding for that is not finished yet, so it should still light up.
Using VEX Cortex in Normal Language
Knowns: The light works, not blown The motor shows it as getting '127' value, as it should The program triggers the light for ten seconds, as it should (not programmed to blink just yet, want to fix this issue first)
The set up is very simple, all I have is two light sensors mounted across from two flashlights in a square opening made of VEX.
They work in a Cross pattern to cover more area of the opening.
A third flashlight is used as the buzzlight, i substituted an LED and changed all codes but it still did not work as wanted.
Here it is: #pragma config(Sensor, in1, Sensor1, sensorReflection) #pragma config(Sensor, in2, Sensor2, sensorReflection) #pragma config(Sensor, dgtl1, BuzzeLight, sensorDigitalOut) #pragma config(Motor, port1, Flashlight1, tmotorVexFlashlight, openLoop, reversed) #pragma config(Motor, port2, buzz1, tmotorVexFlashlight, openLoop, reversed) #pragma config(Motor, port10, Flashlight2, tmotorVexFlashlight, openLoop, reversed) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/* Project Title: Smart Goal Team Members: Shayan Ranjbari Date: March 28, 2012 Section:
Task Description: Create a goal control system that will light up when a goal is made. Must differentiate between human and ball.
Pseudocode:
*/
task main() { turnFlashlightOff(buzz1);
turnFlashlightOn(Flashlight1, 127); //Turns Flashlight1 on turnFlashlightOn(Flashlight2, 127); //Turns Flashlight2 on wait(1);
while (1 == 1)
{
if(SensorValue[Sensor2] >= 120) { waitInMilliseconds(5);
ClearTimer(T1);
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5) { waitInMilliseconds(5); turnFlashlightOn(buzz1, 127); wait(10); turnFlashlightOff(buzz1);
; } }
else if(SensorValue[Sensor1] >= 120) { waitInMilliseconds(5);
ClearTimer(T1);
if(SensorValue[Sensor1] <= 120 && SensorValue[Sensor2] <= 120 && time1(T1) <=5) { waitInMilliseconds(5); turnFlashlightOn(buzz1, 127); wait(10); turnFlashlightOff(buzz1);
; } }
else {
}
}
}
Thanks Gentlemen, Shayan
|
|
jbflot
Site Admin
Joined: Tue May 15, 2007 9:02 am Posts: 385
|
 Re: Help with Programming!
Sorry, but since this is potentially school work I won't offer actual code to do what you're trying to do.
A piece of advice, though - try to start smaller. Add the very, very basic functionality to your code first, test it, make sure it works, then add additional complexity. Your pseudocode looks like you've programmed the entire thing at once, rather than making incremental improvements.
|
|
RoboDesigners
Novice
Joined: Sat Jul 10, 2010 3:06 pm Posts: 86 Location: Roanoke, VA
|
 Re: Help with Programming!
Welcome to ROBOTC Forums! I'll try to provide some input without doing (what may be) your homework for you... Can you get buzz1 to light up at all? Meaning, when you write: just by itself (outside of the if/else statements), does the light come on? This will eliminate hardware issues. Now, with the robot plugged in, look at the current debugger values for the sensors you have. Are they reading the values you think they should be reading? EDIT: I'm confused about the purpose of the timer... in line 40, you clear it out. In the if statement in line 42, you check to see if it's reading less than 5 milliseconds. This should always be true, and therefore doesn't really serve a purpose, right? (Another thing to check... time1(T1) returns the value of the timer in milliseconds, not seconds...) //Andrew
_________________Check out my website! www.RoboDesigners.comVRC Team 2190 Twitter: @RoboDesigners
|