Hi everyone, I'm using a metal sensor to track the height at which my forklift is at. There will be 4 pieces of metallic tape on a rope (using a winch system), one for each level of the rack and one for the ground. So, when the rope passes through the sensor and the sensor passes a piece of tape, lights will go on on the OI and the motor will stop. If I want to go to the next level I want to just keep holding the joystick for that winch motor. If I want it to stop at the level, the pwm03 value will equal 127 and hopefully if I let go of the joystick really fast, the motor will actually turn off. How do I make it so there is a small pause, enough time for me to let go of the motor before pwm03 value is remapped to the joystick in the next 26ms loop so the motor will stop? I want to see these (relay2) lights to go on when the forklift is going up, and I want to stop the motor from lifting the forklift at each level. I don't think what I have in my code will work though, what can I do to pause at pwm03 = 127 so that it wont continue moving?
Code:
void Default_Routine(void)
{
int count = 0;
int now;
int last;
now = last;
rc_dig_in04 = now;
blah blah blah...map joysticks to pwm..
Code:
/***************
* Sensor Code *
***************/
if((pwm03 < 125) || (pwm03 > 129))
{
if((now == 1) && (last == 0)) //If sensor, which connects to Dig In/Out port 4, goes off...
{
count++; //Number of times tape passes through the sensor.
Switch1_LED = 1; //Switch01 goes on when the tape passes the sensor.
}
else
{
Switch1_LED = 0;
}
switch(count)
{
case 2:
Relay2_green = 1;
Relay2_red = 0;
pwm03 = 127; //Motor stops when it reaches 1st level.
break;
case 3:
Relay2_green = 1;
Relay2_red = 0;
pwm03 = 127; //Motor stops when it reaches 2nd level.
break;
case 4:
Relay2_green = 1;
Relay2_red = 1;
pwm03 = 127; //Motor stops when it reaches top level.
break;
case 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.
break;
case 6:
Relay2_green = 0;
Relay2_red = 1;
pwm03 = 127; //Motor stops when it retreats to 2nd level.
break;
case 7:
Relay2_green = 0;
Relay2_red = 1;
pwm03 = 127; //Motor stops when it retreats to 1st level.
break;
case 8:
Relay2_green = 0;
Relay2_red = 0;
pwm03 = 127; //Motor stops when it retreats to ground level.
count = 0;
break;
//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.
}
}
Any suggestions as to how I can stop the motor at each location?
I'm the only programmer and electrician on my team and my team is made up of 5 people, so any help would be fantastic!