Easy problem...I think
agross
Posts: 5
I am using the propeller in conjunction with the tilt axis accelerometer to control a small R/C toy with tank style steering I have all of the wiring correct and was able to test using some basic outa[noparse][[/noparse]pin] commands. I am now trying to replicate movement of the tank with if and elseif statements based on conditions, an example would be; if the tilt of the x sxis is greater than 300 pulse high on pin 1 and 2 (left and right motor) to go forward. So here is the problem, when I use the conditional if statements I can only get two movements out of the R/C toy. When I try to add any more than that I lose control and all I can do is turn left or right. I think the problem is coming from the else if statement I used after the if statement to stop the movement when the condition is no longer met but I can't seem to wrap my head around where my logic is wrong. below is the segment of code that drives the toy as it is within my code if you see what I can't let me know because it seems like such an easy problem to fix I just can't figure out what's causing it. Also as a side note when I try to use the elseif statement I get an error that says "expected variable or expression" even though there is one there can anyone explain this, I should also add most of my programming background is in JAVA so that could be an issue depending on how the elseif works in the spin editor.
if yaxis > 300
forward
elseif yaxis < 300
FSTOP
if yaxis < -300
reverse
elseif yaxis > -300
RSTOP
if xaxis > 300
right
elseif xaxis < 300
rightStop
if xaxis < -300
left
elseif xaxis > -300
leftStop
PUB forward
outa := 1
outa := 1
PUB reverse
outa := 1
outa[noparse][[/noparse]6] := 1
PUB left
outa := 1
outa := 1
PUB right
outa := 1
outa[noparse][[/noparse]6] := 1
PUB FSTOP
outa := 0
outa := 0
PUB RSTOP
outa := 0
outa[noparse][[/noparse]6] := 0
PUB rightStop
outa := 0
outa[noparse][[/noparse]6] := 0
PUB leftStop
outa := 0
outa := 0
if yaxis > 300
forward
elseif yaxis < 300
FSTOP
if yaxis < -300
reverse
elseif yaxis > -300
RSTOP
if xaxis > 300
right
elseif xaxis < 300
rightStop
if xaxis < -300
left
elseif xaxis > -300
leftStop
PUB forward
outa := 1
outa := 1
PUB reverse
outa := 1
outa[noparse][[/noparse]6] := 1
PUB left
outa := 1
outa := 1
PUB right
outa := 1
outa[noparse][[/noparse]6] := 1
PUB FSTOP
outa := 0
outa := 0
PUB RSTOP
outa := 0
outa[noparse][[/noparse]6] := 0
PUB rightStop
outa := 0
outa[noparse][[/noparse]6] := 0
PUB leftStop
outa := 0
outa := 0
Comments
If the value is exactly 300 or -300, nothing happens.
I suspect that you need to use a better set of boundary tests: essentially each axis seems to have 4 conditions of interest. Use a case statement or different tests in the if statements. Something like:
But, perhaps I misunderstood what you're asking.
Daniel
edit: code fragment not meant to be PropSpin.
edit2: reformatted using PhiPi's formatter.
Post Edited (daniel) : 12/2/2007 12:42:09 AM GMT
-Phil
That's pretty much an if-then-else rather than an operation with hysterisis. You probably want to alter the elseif value to something positive but lower ( eg, 150 ). Likewise with the other threeselectors.