This Easy Piece of code is driving me BONKERS! How do I

Hey guys, the last couple hours Ive been fiddling with this line of code doing some Pulsin reads and I cant seem to figure this out! I need some experts here.

Alright down to business

Rc receiver connected to BotBoard 2 I do a pulsin read when the thing is centered I get 1500 decimal I turn the stick far to the right I get 1912 back I turn the stick far left I get 1088 back.

so

What I have tried was this
Abs(RcInput(0)-1500)-412 … The output is Zero centered and 412 left and 412 right.

I want the opposite 412 centered zero left and zero right

Here is another solution I have, and some fake values were used and I tested this in my Ti89 calc but on the bb2 it does not work

   If RcInput(0) > 1500 then
   InputTimeDelay = (Abs(RcInput(0) - 1500 ) + 412)
   Else
   InputTimeDelay = (Abs(Abs(RcInput(0) - 1500 ) - 412))
   Endif

I just am missing something here! When I run debug on it the values all look right but the value of InputTimeDelay changes not in accordance with the value of my RCPulsin Read…

((Abs(1088)-1500)+412) = 0 — I want this
((Abs(1912)-1500)-412) = 0 — I want this
((Abs(1500)-1500)-412) Or ((Abs(1500)-1500)+412) Both = 412

Why this fails to work in my code is BAFFLING to say the least.

If someone can help me solve my problem another way I’m all ears :slight_smile:

[/code]

If I understand what you want correctly, you might try:
412-abs(rcInput(0)-1500)

is abs an array?
because the syntax for referring to an array is

variable (array reference)

so it might think you are referring to abs as an array (which i am assuming it isn’t)
if you are trying to multiply, you need a * symbol.
if you are using Basic Stamp 2 then also please note that it executes equations from left to right, not using standard Order of Operations that a scientific calculator would use.
also, what does abs stand for? could you please give the purposes, sizes and types of the variables

also, if all you are trying ot do is invert the servo positions, could you do something like

{servo position} = 3000 - {servo position}

alright that’s all i can think of now

I think ABS is “absolute value”.

Are you using the Basic Atom? There’s a little information on the Basic Micro wiki:
basicmicro.wikia.com/wiki/MBasic:_Math_and_Functions#Unary_Functions

If you want to get the absolute value of the final calculated number (the positive 412 you want), then shouldn’t you have the parenthesis set up more like:

Abs(1500-1500-412)
Abs(1500-1500+412)

It’s definitely possible that I’m misunderstanding what you’re trying to do here, so if that’s the case I’m sorry! Hope at least something here helps. :smiley:

It can’t be an array because abs is a reserved word. The IDE will not allow it to be used as a variable.

abs is an unary operator for absolute value…

The parens are used for precedence forcers. That is many operators have a higher priority than other operators, which you may wish to override…

Kurt

Holy smokes a crap ton of replies.

So let me try and re-explain what I would like to do.

This is phoenix code FYI so I’ll use things you can understand if anyone has the Pheonix.

I want to get a number more twords 0 as the stick moves more forward, or more left or more right or more down… but for the sake of this example I’m just looking for code for 1 channel “Left and Right”

So currently as it stands the values I get out of debug are so not even right, I’m guessing some other bug is taking over because When I plop the values in my TI-89 calc they all come out how I want them to come out.

My range on the remote doing a Pulsin read of channel 1 I get
1088 Left
1912 Right
1500 Centered.

the values that are easy to get are subtract 1500 from that pulsin read so you now get

  • 412 Left
    0 Centered
    412 Right

we are getting closer.

What I then do is Add +412 to the Left and find the absolute value of it thus giving me zero and only positive numbers up to 412.

Then I subtract 412 from the right and find the absolute value of it thus giving me zero and the only time I have a 412 number is in the smack dab center position.

What I am trying to do honestly is in this pheonix code set SSCTime delay based on the location of your stick "I understand 412 might be a high ssctime value although I can simply divide this to find what works and what doesn’t IE by 2 which takes my range from 0-206 as an example.

In the pheonix code Zenta had shared with me on the t7C transmitter there is a channel 6 pot which is simply a knob that turns up or down SSCTime… Well… I want to eliminate that and get ssctime value “which i’m guessing is some sorta of ms delay for servo updates” … I want to get ssctime value based on the inverse of the stick positions the stick a little forward the robot moves slow with a slow walk then push the stick forward all the way and its walking faster…

Hope this explains what kinda values I’m getting, the code above I posted works 100% in my calculator but when tossed onto an atom pro it’s like there is other things trying to modify the variable and I’m really not sure why its doing this , it works fine on paper???

that is unless there is a alternative way of doing this?

Do I need to have a line that copies the contents of RCInput(0) and puts it into a variable right after the read input?

Somevariable = RcInput(0)
   
If RcInput(0) > 1500 then
   InputTimeDelay = (Abs(SomeVariable) - 1500 ) + 412)
   Else
   InputTimeDelay = (Abs(Abs(SomeVariable) - 1500 ) - 412))
   Endif 

when I run the code from my top post I move the sticks left and right and I see 1 instance where inputTimeDelay = 0 and the stick isn’t centered or all the way to the left or right…

sorry, i have never used abs so i assumed it was a variable… :blush:

Printerface… No problem here is what it does.

Abs(-412) will return 412
Abs(412) will return 412

Abs is absolute value.

–Aaron

… SO everyone I’m going to go ahead and eat my foot…

It’s acting stupid because at the top of this program

Inputimedelay var byte…

which is 255 Max… HAHAHA I love it, I knew it was something stupid…

–Aaron

lolololololol… ouch.

So… I believe I have solved this problem although… does anyone have any ideas as to how I might solve this a different way possibly using less cpu power?

…frankly this code kinda only applies to the few who have RC phoenix’s which I think is Zenta and I…

But the math behind my problem seems pretty straight forward although is there a more efficient way of doing this?

This is how I accomplished this

[code]If RcInput(0) > 1500 then
ChanVal0 = Abs((abs(RcInput(0)) - 1500) - 412)/3
else
ChanVal0 = Abs((abs(RcInput(0)) - 1500) + 412)/3
Endif

If RcInput(1) > 1500 then
ChanVal1 = Abs((abs(RcInput(1)) - 1500) - 412)/3
else
ChanVal1 = Abs((abs(RcInput(1)) - 1500) + 412)/3
Endif

If RcInput(3) > 1500 then
ChanVal3 = Abs((abs(RcInput(3)) - 1500) - 412)/3
else
ChanVal3 = Abs((abs(RcInput(3)) - 1500) + 412)/3
Endif

InputTimeDelay = ChanVal0 max ChanVal1 Max ChanVal3

;InputTimeDelay = Abs(RcInput(0)-1500) - 412
SSCTime = NomGaitSpeed + InputTimeDelay[/code]

–Aaron

Oh man its one of those days, ignore that post above