We have a telescoping arm that extends buy pushing a plastic E-chain up its center with a globe motor
to tell when we are at the limits we put white paint on both ends of the black plastic chain, and use a banner sensor to see the white spots.
We have a variable that we use to remember whether we were going up or down the last time the chain was moved, so when we see the paint we know whether to restrict it from going up or down.
it all works fine except for one thing - we initialize that variable on powerup to say we were going down - and we power up the bot with the chain down, so the sensor is on
but after powerup the SW thinks the arm is all the way up instead - it wont let it go up, only down
if we power the bot up with the chain between the white spots, everything works fine. (this is what we have been doing)
I totally stumped by this one, and so are the SW students on our team - we cant see anything wrong with the code
is it possible the RC puts out invalid OI signals on powerup? on the first few loops of the SW could it be getting active switch inputs for OI switches that are open? Thats the only thing I can think of that would throw our code off and make it think it was going up after power on?
the code is below - if you draw a flowchart its easier to understand:
/*578 telescope control */
/*banner sensor is on rc_dig_in04 - 0=end of chain*/
pwm04=127; /*default to off*/
if(p4_sw_aux1) /*if up switch is on*/
{
if (rc_dig_in04) /*if not end of chain*/
{
pwm04= 150; /*move up 1/4 speed*/
teleDirection = 1; /*last direction is up*/
}
else if (teleDirection==0) pwm04= 150; /*was going down, ok to move up*/
}
if(p4_sw_aux2) /*if down switch is on*/
{
if (rc_dig_in04) /*if not end of chain*/
{
pwm04= 104; /*move down 1/4 speed*/
teleDirection = 0; /*last direction is down*/
}
else if (teleDirection==1) pwm04= 104; /*was going up, ok to move down*/
}
teleDirection is initialzed to 0 = down and the only way it could get to be 1 is if the inputs read that the up switch is on and the banner sensor is off - neither of which are true when the bot is powered up with the chain all the way down.
Im totally stumped by this one! :ahh:
BTW- the chain does not move on power up, no glitches or anything, and we can use it the way it is by pulling the arm slightly off the paint spot
but it bugs me that its not doing what it should be - the code is doing something we dont understand or its doing something unpredictable, which leaves you with a sick feeling that something is not right with the system.