Hello everybody. I'm programming a "metal detector" on my robot so it can sense a small piece of aluminum tape that will be on a rope. The rope will go up and down (our version of an arm) and there will be (we haven't decided yet) appx. 4 pieces of tape on the rope. So, when the tape passes the sensor, I want the program to keep track so when it reaches a certain height it will automatically stop, so we dont have to manually stop the arm. So from the first four passes of the tape through the sensor, the rope will be moving up, and the next four (five to eight) will let us know that the rope is going down. Will this work? And is where in the code I'm placing this correct (in user_routines_fast.c Process_Data_From_Local_IO)? (I want to use the relay2 lights so I can see whether I'm going UP or going DOWN. at full up they are both on and at full down they are both off. red is going down and green is going up.)
Code:
void Process_Data_From_Local_IO(void)
{
int count = 0;
if(digital_io_04 == 1) //If sensor, which connects to Dig In/Out port 4, goes on...
{
count++; //Number of times tape passes through the sensor.
Switch01_LED = 1; //Switch01 goes on when the tape passes the sensor.
}
else
{
Switch01_LED = 0;
}
if(count == 8)
{
Relay2_green = 0;
Relay2_red = 0;
pwm03 = 127; //Motor stops when it retreats to ground level.
//pwm03 = p3_y; //re-maps pwm03 to joystick
count = 0;
}
else if(count == 7)
{
Relay2_green = 0;
Relay2_red = 1;
pwm03 = 127; //Motor stops when it retreats to 1st level.
//pwm03 = p3_y; //re-maps pwm03 to joystick
}
else if(count == 6)
{
Relay2_green = 0;
Relay2_red = 1;
pwm03 = 127; //Motor stops when it retreats to 2nd level.
//pwm03 = p3_y; //re-maps pwm03 to joystick
}
else if(count == 5)
{
Relay2_green = 0;
Relay2_red = 1;
//pwm03 does not equal 127 because it must pass the tape in order to go beneath the top level.
}
else if(count == 4)
{
Relay2_green = 1;
Relay2_red = 1;
pwm03 = 127; //Motor stops when it reaches top level.
//pwm03 = p3_y; //re-maps pwm03 to joystick
}
else if(count == 3)
{
Relay2_green = 1;
Relay2_red = 0;
pwm03 = 127; //Motor stops when it reaches 2nd level.
//pwm03 = p3_y; //re-maps pwm03 to joystick
}
else if(count == 2)
{
Relay2_green = 1;
Relay2_red = 0;
pwm03 = 127; //Motor stops when it reaches 1st level.
//pwm03 = p3_y; //re-maps pwm03 to joystick
}
//if count == 1 then that just means that it passed through the first piece of tape which will be used to show that it is in full DOWN position.
/* Add code here that you want to be executed every program loop. */
}
So, First of all, if you noticed I put "//pwm03 = p3_y" in comments. This is because I'm not sure if I give pwm03 a number (127), if it will permenantly make it that number? So would I have to re-map it to the joystick? or would it do that automatically in the Default_Routine()? Also, does the first line of code with the sensor make sense? And I'm not sure if I put this code in the correct spot in the program. I'm sort of new to programming, just started late last year. Thanks in advance for your help!