Posted by Jerry Eckert.

Engineer from Looking for a team in Raleigh, NC sponsored by .

Posted on 3/15/2000 10:13 PM MST

In Reply to: Re: please explain more… - Expanded Response posted by Jerry Eckert on 3/15/2000 9:43 PM MST:

In my previous reply I used two formulas to scale the joystick input: one for forward and one for reverse. This can also be accomplished with a single formula:

p1_yfilt = ((p1_yfilt/n) + (127-(127/n))) min 0 max 254

where ‘n’ is the scale factor (e.g., ‘2’ for 1/2 speed; ‘3’ for 1/3 speed, etc.)

: :

: : : As for losing part of our range, when I attempted to scale down the drive train output to 50% of the joystick value in order to create our ‘turbo boost’ function, using the code shown below:

: : : (for forward)

: : : p1_yfilt = (p1_yfilt)/2 min 128 max 254

: : : (for reverse)

: : : p1_yfilt = (p1_yfilt*3)/2 min 0 max 126

: : : in one direction, i would lose all output unless the ‘turbo’ function was on, and in the other, it would always act as if the turbo was turned on.

: : I don’t have the PBASIC manual handy, but it looks like the problem might be that the precedence of min/max is higher than division. In other words, I suspect PBASIC evaluated your statements as:

: : p1_yfilt = (p1_yfilt)/(2 min 128 max 254), and

: : p1_yfilt = (p1_yfilt*3)/(2 min 0 max 126)

: : Try rewriting them as follows:

: : p1_yfilt = (p1_yfilt/2) min 128 max 254, and

: : p1_yfilt = ((p1_yfilt*3)/2) min 0 max 126

: Let me try this again… (I should know better than to try to do this stuff when I’ve been sitting in front of a computer for 48+ hours. )

: The min/max precedence MAY be the problem; if it isn’t, the scaling formulas are also wrong.

: In forward: (.le. = less than/equal; .ge. = greater than/equal)

: Before scaling, 128 .ge. p1_yfilt .le. 254

: 64 .ge. p1_yfilt/2 .le. 127

: Therefore, regardless of the input value, the scaled p1_yfilt will be forced to 128 (no output) by the MIN.

: Reverse:

: Before scaling: 0 .ge. p1_yfilt .le 126

: 0 .ge. p1_yfilt*3/2 .le. 189

: For reverse you should get some output, but the stick range is going to be heavily biased towards neutral output after the MIN/MAX are applied.

: I’d do something like this (please excuse any syntax errors - it’s been a year since I’ve programmed PBASIC):

: LOOKDOWN p1_yfilt, (lt)[127,128,255],index (’(lt)’ is less than sign)

: BRANCH index,[rev,neutral,fwd]

: REV:

: p1_yfilt = (126-((126-p1_yfilt)/2)) min 0 max 126

: goto common

: NEUTRAL:

: p1_yfilt = 127

: goto common

: FWD:

: p1_yfilt = (128+((p1_yfilt-128)/2)) min 128 max 254

: COMMON:

: If the LOOKUP function will accept formulas in the value list, all of the above starting at the BRANCH can be replaced by:

: LOOKUP index,((126-((126-p1_yfilt)/2)) min 0 max 126), 127, ((128+((p1_yfilt-128)/2)) min 128 max 254)]

: If you want a dead zone around the neutral joystick position, replace the LOOKDOWN with:

: LOOKDOWN p1_yfilt,(lt)[127-dead_size, 128+dead_size, 255]

: : Jerry