PDA

View Full Version : Can PBP understand negative numbers?



Tom Gonser
- 6th June 2005, 01:13
I have a routine that is incrementing or decrementing 1 time each pass. It reads a milibar value(dec_mb) every second. Then it compares this to the last reading(last_mb) to see if it is going up or down. The value inc_mb then holds a cumulative value, but it can be negative.... After 10 loops it trys to tell me what the trend is - it does not work, and my Inc_mb which should be a value of -10 to 10 shows '255' which must mean a negative number breaks PBP??

So I can see an average move over 10 seconds, I wrote the following:


if Dec_mb > last_mb then
inc_mb=inc_mb+1
endif
if Dec_mb < last_mb then
inc_mb=inc_mb-1
endif
mb_count = mb_count+1

if mb_count > 10 then

if inc_mb >= 6 then
LCDout " R+",#inc_mb
endif

if inc_mb > 2 and inc_mb < 6 then
LCDout " R ",#inc_mb
endif

if inc_mb > -2 and inc_mb <= 2 then
LCDout " S ",#inc_mb
endif

if inc_mb <= -2 and inc_mb >= -6 then
LCDout " F ",#inc_mb
endif

if inc_mb < -6 then
LCDout " F+",#inc_mb
endif


It always tells me it is 'F+', even when the value is '0'.. it should be telling me 'S' there..

Arggghhh..

mister_e
- 6th June 2005, 03:59
PBP don't handle +/- results directly as VB or else PC language. You have to refer to the CARRY or Z flag of the STATUS register. OR

If NewResult>OldResult then Sign=Negative

there's a ton of different way to do this task... One idea here why not using a range of 20. If between 0-10 => negative 10-20 Positive

jetpr
- 6th June 2005, 04:11
PumpMath = (Throttle - ThrottleMin) * 100 / RadioScalefactor

if (PumpMath > 101) or (PumpMath < 0) then
PumpMath=0
endif

if (CurrentStep + 1 < PumpMath) and (PumpMath < 100) Then
IF (CurrentStep < PumpMath) Then
CurrentStep = CurrentStep + 1
EndIF

IF (CurrentStep > PumpMath) Then
CurrentStep = CurrentStep - 1
EndIF
endif

if (CurrentStep - 1 > PumpMath) and (PumpMath >0) Then
IF (CurrentStep < PumpMath) Then
CurrentStep = CurrentStep + 1
EndIF

IF (CurrentStep > PumpMath) Then
CurrentStep = CurrentStep - 1
EndIF
endif

Tom Gonser
- 13th June 2005, 00:23
THANKS! I think I figured it out!