Axis Mixing - Solved

Official forum for open source FreePIE discussion and development.
Post Reply
Billhelm
One Eyed Hopeful
Posts: 14
Joined: Fri Oct 11, 2013 7:01 pm

Axis Mixing - Solved

Post by Billhelm »

I'm hoping to create a script that combines axes, such that movement on one physical axis causes two virtual axes to move in the same direction, and movement on another physical axis causes the same two virtual axes to move opposite each other. Both operations would have to work without interfering with one another such that the result is additive (think tank controls). Is this possible, and if so, how might I go about doing it?
Last edited by Billhelm on Fri Aug 28, 2015 11:34 am, edited 1 time in total.
HarvesteR
One Eyed Hopeful
Posts: 19
Joined: Mon Jun 15, 2015 10:30 am

Re: Axis Mixing

Post by HarvesteR »

It certainly is possible, but it is true that multiple writes to a field is a deceptively tricky thing to do.

You said you wanted something like tank controls, an additive combination of both inputs. I assume then you have two outputs that behave like levers on a WWII tank or the pedals on an excavator. Each controls one side of the drive train, so steering is done by differential drive.

This isn't a particularly complicated scenario, say you have the following setup:

Code: Select all

inputX = your physical x axis
inputY = your physical y axis

axisLeft = the virtual output for left side drive
axisRight = well you get the idea...
So, you'd have to do something like this:

Code: Select all

// renaming here is redundant, but makes it easier to understand (hopefully)
diffDrive = inputX
linearDrive = inputY

axisLeft = max(min(linearDrive - diffDrive, 1), -1)
axisRight = max(min(linearDrive + diffDrive, 1) -1)

That's about all there is to it. Note that the result is clamped between -1 and 1. This is important to avoid going into 'overdrive' if both inputs are being applied at the same time. (think full fwd drive while steering). The clamp will cause the side already driving to just keep driving, and the other side will slow down.

Also note that I assumed that values <0 in diffDrive mean you are applying left input. Change those + and - signs as needed.

This is all pseudocode, ofc, but the rest of it depends on your setup, so that's about as much help as I can offer. :)

Hope this helps!

Cheers
Billhelm
One Eyed Hopeful
Posts: 14
Joined: Fri Oct 11, 2013 7:01 pm

Re: Axis Mixing

Post by Billhelm »

Thank you very much! That's exactly it. For anyone else, here is the exact code that I used:

Code: Select all

inputX = joystick[1].x
inputY = joystick[1].y

diffDrive = inputX
linearDrive = inputY

axisLeft = max(min(linearDrive - diffDrive, 1024), -1024)
axisRight = max(min(linearDrive + diffDrive, 1024), -1024)

vJoy[0].x = axisLeft
vJoy[0].y = axisRight
Post Reply

Return to “FreePIE”