I am trying to code 2 stepper motors that convert to xy motion with lead screws. The problem I am facing is that I want the xy axis to move the same direction the joystick is pushed no matter what orientation the device is turned. I was thinking about using a compass to sense the direction but I was wondering if anyone had advice on the best way to go about that or how to code it?
So the joystick is not connected to the X/Y gantry? Does the mean you need to detect the orientation of the joystick and the gantry separately? Also, what happens if the joystick is perpendicular to the plane of the gantry?
Yes, I need to detect the two orientations separately but they will always be parallel to each other.
spletcher:
Yes, I need to detect the two orientations separately but they will always be parallel to each other.
I think the easiest way to get an absolute orientation is with a three-axis magnetometer. Convert the X/Y from the joystick to E-W/N-S before sending. At the gantry, convert back to X/Y. Read up about 3D graphics and rotating coordinates.
spletcher:
The problem I am facing is that I want the xy axis to move the same direction the joystick is pushed no matter what orientation the device is turned.
I can't make sense of that. Does the word "device" refer to the joystick of the machine with the XY axes?
And I don't understand how there could be confusion about the orientation?
Please post a simple diagram to show what you are trying to achieve. Simple Image Guide
And tell us what you are actually trying to make.
...R
Robin2:
I can't make sense of that. Does the word "device" refer to the joystick of the machine with the XY axes? And I don't understand how there could be confusion about the orientation?
I think they have an X/Y gantry, possibly mobile, and they have a wired or wireless remote joystick. The gantry and joystick are in (roughly) the same plane (or parallel planes) but can move/rotate relative to each other. The OP apparently wants the X/Y gantry to move in the absolute direction indicated by the joystick: If a joystick axis is oriented north/south and is pushed in the north direction the gantry should move north regardless of its orientation. If the joystick mounting is rotated clockwise the direction of the gantry motion would shift from north to NNE, NE, ENE, east...
johnwasser:
I think they have an X/Y gantry, possibly mobile, and they have a wired or wireless remote joystick. The gantry and joystick are in (roughly) the same plane (or parallel planes) but can move/rotate relative to each other. The OP apparently wants the X/Y gantry to move in the absolute direction indicated by the joystick: If a joystick axis is oriented north/south and is pushed in the north direction the gantry should move north regardless of its orientation. If the joystick mounting is rotated clockwise the direction of the gantry motion would shift from north to NNE, NE, ENE, east...
Let's wait for the facts from the OP.
...R