Converting X,Y mouse positions to skid seering commands

pygamesteering.py_.txt (4265Bytes)

For quick demonstrations/easy testing of hardware, i am trying to write a pygame interface to a skid steering robot.

I am at the point where i have a control screen with a center, and the x,y position of the cursor relative to that. I can determine whether overall it should be going straight, left, or right, forwards or backwards depending on the mouse position with the vertical axis being "overall forward motion" but i want to use the horizontal axis to determine the left/right split, with the total "forwards motion" available from the verticle axis being split left/right by how far the values of the horizontal axis are from center

I am sure this sort of thing has been done before - does anybody have some pointers?

UPDATE:

Thanks for the help everybody - i seem to have gotten it sorted - i am sure it could be prettier though.The code should be pretty obvious - i made some changes to make it easier to drive the TReX - it now checks for negative values, and sets a flag for that motor to reverse, and then flips the value to positive. this is the sort of data the trex is expecting.

It is hard to do a complete test currently due to the speed of the robot and the length of my USB cable. Next up will be IP connectivity between a pygame/wxwidgets client running on a netbook, connecting to a python server running on the robot's netbook, interfacing with the TReX motor controller and a Polou servo controller. Also, i found a simple bit of c code to allow easy reading of linux's mouse device inputs for X,Y positioning

http://jwr.d2p.com.au/robobot/

If the mouse is left of
If the mouse is left of center, subtract the distance from the left motor. If the mouse is right, subtract from the right motor. That will make it turn according to how far from center the cursor is. The base motor speed for both is of course dependant on the vertical position.

 

Cheers! The ideas i had

Cheers!

 

The ideas i had going through my head were more of a "determine the current left/right ratio and apply that to the throttle value" with some trig thrown in. You laid out a way to do what i need perfectly, thankyou!

I have made the changes, all
I have made the changes, all looks like wat i was after for forwards motion - reverse will require some inverted values but nothing too hard!

Did it…

I have done it with processing but I’m sure your code will be similar.

https://www.robotshop.com/letsmakerobots/node/7044

–Bear in mind that the “X” criss-crossing the control window is just for a visual representation to the user, it has no bearng on the code. As the curser moves away from the center (Center being off, like a joystick) speed is increased on the relavent motor. I can’t remember if I did my X/Y mixing in Processing or in the robot. Final drive on the 'bot is via PWM signals from a picaxe 40x2.

 

Mixing X and Y

Forgot…

Here’s how to mix your X and Y.

https://www.robotshop.com/letsmakerobots/node/5358