Exponenets and floats

I’m working on doing some different things to help and increase the amout of control that we have over the robotwhile driving. What We’re setting up is a expodential curve istead of the linear one setup by default. what we’re looking at is something like this:

p1_y = 73 * ((1.06526 ^ p1_y - 1) / 100)

This will basically give me a persentage of 73. Can I do this, or is not possible(with the decimal numbers) or does pBasic allow this? Also, is there a default command for doing exponents? Thanks a lot

The secret is to think of the joystick as a graph, and define what you want the output to be depending on the number. I did this, and now our controls vary with the square. But be forewarned. Doing this can cause very weird and hard to squash bugs. When I first did it I bumped the joystick and the robot attacked a few nearby 55 gallon drums(edit: I forgot to mention now it works). You will end up using four if then statements. (hint one for each quadrant).

There are several things wrong here.

First of all is your formula. 1.0625^254 is 10222. Taking into account the rest of your formula, you are still nowhere near a range of 0 to 254.

Second, even if your formula did work mathematically, it uses floating point numbers, which the basic stamp doesn’t support. It also uses an exponent, which you would have write code to support, because the stamp doesn’t.

It is much easier (and probably faster) to figure out your algorithm (and test it using excel or another tool), and then implement it in a lookup table then to try to convert your algorithm to valid pbasic code.

PS, I like the choice of your scaling constant :wink:

Thoanks for the tips, I’ve ended up using a square. Just to let you know what I wa working on for the exponents thing, it was this:

SELECT p1_y
CASE 127 to 200 ’ 73 unit range
p1_y = p1_y - 127
p1_y = 73 * ((1.06526 ^ p1_y - 1) / 100) 'gives a percentage of 73
’ this is done for all sections giving it a smoother movement
CASE 200 to 254

ENDSELECT

I’ve done nearly exactly what you’re suggesting in PBASIC before. I just plugged some joystick values into my TI-89 (and 83 would be more than sufficient, however) in one list, the expected output into another list, and did a regression. Just put the regression curve into the code and you’re all set. Make sure both your domain and range are [0, 254].