Processing pot data to determine cartesian quadrant

I'm building an ROV as a capstone project for a mechanical engineering technology program and I wanted to posit this question to the community about how to interpret the pot data from our PS3 controller. We're trying to figure out how to control the thrusters but we're not sure how to go about the math. The pot returns data in cartesian coordinates (x = 0 -> 255, y = 0 -> 255) and we can plot that point anywhere within a circle. We would like to control forward and backward, and left and right strafe (for now). What follows this intro is what I've thought of so far; if there is a better way to go please do feel free to tell me to look at other directions. So anyway...

The controller transmits pot data to our Uno and ranges from 0 - 255 with 127 as the neutral point in the middle. Imagine the total range of the pots as a circle (scribed by the cartesian resultant of the x & y pot data) with the point (127,127) as the centre coordinate. I would like to be able to tell which quadrant of the circle the resultant point from the pot coordinates is in. My original thought was a check something like this:

if (x < 127){
qx = -1}
else {
qx = 1}

if (y < 127){
qu = -1
}

else {
qy = 1
}

Then check to see what quadrant the pot coordinates are in by referencing:

Quadrant x y
Q1       1  1
Q2       -1  1
Q3       -1  -1 
Q4       1  -1

Knowing what quadrant we're in will make the code range the two vectored thrusters that affect rotation away from 45 degrees much easier to figure out. For example, if we're going 45 degrees forward and to the right, the 2/4 thruster pair (T2 & T4) is running full bore (or at least whatever the intensity of the resultant vector of the pot coordinates) and whatever deviation from exactly 45 degrees the pot picks up the program will interpret as adding forward or reverse thrust from the other thruster pair (T1 & T3).

That's all I have for now, but I'm going to have more to work with tomorrow when I present this thought to my group. Any and all help is appreciated to get this idea either fleshed out or flushed down the toilet. I can clarify anything that I didn't explain well enough but it's the end of a long day and right now all I want is some dinner and a beer :smiley:

Cheers friends

Hi,

Welcome to the forum.

I like the simple quick solution, if you understand it and it works, go with it.
You just need to do 4 tests and you have your quadrant.
You might need to put a dead band at the origin to stop jitter from quadrant to quadrant when the stick is at centre.

Others may have other solutions but you are the ones working with it.

Tom..... :slight_smile:
Good luck with your Capstone Project, keep us updated

Hi Tom, thanks for the encouragement! Definitely a good idea to add a dead zone around the origin. We've found already that the thumbsticks tend to wander a bit if they aren't brand new (a frustrating feature that has walked me out of cover in many a videogame).

I'll propose the idea of the quadrant check, but I am a bit worried about doing if-statement checks. If the state changes while the program is doing the quadrant check that could really mess things up. I did some research to see if I could find how quickly the Uno/Mega board can crunch those if statements and it seems to be slightly variable, but we've encountered jitter before and I want this program to be very responsive. Chalk it up to unfamiliarity with the hardware's capabilities.

Assuming I go ahead with the if statements to determine 1/-1 for the x and y coordinate quadrants, is there a way to match the state of those variables to the Quadrant table in my first post that can happen very quickly/algebraically instead of with if statements?

Thanks.

Hi,
Do your code for the quadrant check and see how quick it is.

You will be doing a lot of individual blocks of code as you get each feature working on their own before combining your working blocks.

Hint, keep doing backups with each failure and success, name your code with version numbers on the end of the filename and include it in a comment line at the start of your code.

Use the serial/monitor facility of the IDE to monitor variables etc, and get it to output to the monitor the version of the program it is running.

Check this link to suggestions on various program processes.

http://forum.arduino.cc/index.php?topic=384198.0

Tom.... :slight_smile: