# C++ Polar Coordinate Joystick

I’ve attached a new joystick class derived from the standard WPILib Joystick class with additional functionality.

For omni-directional control systems (such as mechanum, etc.), it may be beneficial to receive your input from a joystick as a polar coordinate (radius and angle/direction) as opposed to the standard cartesian coordinate (x and y values). Doing so presents a problem, however, as due to special right triangles, pushing the joystick into any of the corners generates a farther distance from the center than pushing the joystick to any of the sides (since a right triangle with two legs 1 unit long generates a hypotenuse of the square root of 2 units long).

I’ve created a fix for this by writing an algorithm that “normalizes” the distance from the center. The algorithm takes the slope of the line that intersects the origin (the center point of the joystick) and the actual x-y coordinate of the joystick and uses this slope to project the line all the way to the edge of the joystick bounds. The length of this line is divided by the length of the line from the origin to the joystick coordinate.

The end result of all this is that the polar coordinate generated remains at the maximum value while moving the joystick all the way around its bounds.

Also included is a simpler function that gives the angle of the joystick (in degrees) from the center point.

These two functions are used to derive the OmniJoystick class from the standard Joystick class. The OmniJoystick class has the functions GetAngle() and GetR() along with the standard GetX() and GetY() functions.

OmniJoystick.zip (2.11 KB)

OmniJoystick.zip (2.11 KB)

This is awesome! I was just about to write this code myself and then I thought, “You know, this really ought to already be implemented on ChiefDelphi somewhere…” and, lo and behold, it was!

Thanks!
-Matt

That’s super cool. Great thinking!

But you’re required to use the Rover wheels which are non-omni.

This topic is originally from before kickoff.

Ah, but who says this joystick class isn’t applicable to other drive types than those with omni or mecanum wheels? The rover wheels are actually quite suitable for a holonomic setup (wheels are setup parallel to each side, with axles lined up like this: + ) and there are certainly other drive types out there that can use the rover wheels.

I would love to give a specific example of those “other” drive types, but my mechanical team leader would like to keep that a secret for just a few days longer .

What’s funny is that these wheels could probably act as omni. =]

Thanks i was just trying to write this in lapview, thanks for the jumping off point.

On a latter note: I like working in polar coordinates, i just seams simpler then the coorindates we had to work with last year. It also works better if you are tyring to write an accleration program to help you start and stop on a slick surface, with might come in handy, this year…