Analogue control for your models.

View previous topic View next topic Go down

Analogue control for your models.

Post by T-Bouw on Tue Oct 26, 2010 7:31 pm

Rant
Okay. So you made your best model yet. Slaved hard to tweak it. It looks terrific but handles horrible. It might be because of poor building. Or because you did it on purpose! Real-world modern jets are build like this.
On top of it all, you just started with Rigidchips and can't (yet) make a decent fly-by-wire code to control the thing. (Fine print mode on: Mind you that these are the feelings I had and yours may differ. fine print mode off)

Possible cure for Rant
A short-term solution (but can also help in the long-term) can be to use analogue axis to control your model.
I won't teach you everything about building/programming. There're other tutorials for that but I'll try to make this idiot-proof (no offence). Here's a start:

Mapping
First off you'll need to know what axis, dial or knob does what. You can change the default mapping in RC if you don't use Windows 7. RC crashes if you open the configure controls window.
Map it how you like or stick with default. RC doesn't care.
Default for most joysticks is: analog0 = X axis, analog1 = Y axis

Variables err...Val...huh?
What RC does care about is how you set up the variables. If you made a model yourself you already know this is important.
For computations you don't need any but both script and Lua need this filled out for the model to make any movement in the "real world"
These values should be self-explainatory but there're some important things to ponder on.

Give the Val a name. This name'll be referred to in the script/Lua section.
Also, put this name in the angle-section of the chip you want to move.
default= the starting postion of your chip.
Important! If this value does not match up with what you program in script/Lua, the angle'll go from this to the default you programmed in the very first frame after the model is loaded! Possibly exeeding the structural limit which may result in the chip breaking off or something epic!
min= the minimum angle the chip can rotate. Make sure to add the default value to this. Pay extra attention when it goes negative. Just remember basic schooling!
Good form is to keep this value in-line with the programmed result. Or make it bigger to be safe. Make it smaller to limit the movement. This can come in handy.
max= the maximum angle the chip can rotate. Oddly enough, this doesn't necessarily have to be filled in and has a "virtually unlimited" high value when kept empty.
As with min, streamline this value with the end result. Or not...
step= the degrees per frame the chips need to go back to default. But...
Don't fill this in!! If you do, the analogue computation and step'll fight each other relentlessly resulting in jittering of the chip and again, Epicness!

Programming
It may sound hard but with all things, when you know how, there's nothing to it!
Believe it or not but getting the Vals right is in my opinion harder.
I'll go for an example right away:

angle=_analog(0)

There. That's it!
What does it do? Well the Val "angle" 'll go from 0 to +/-1000 degrees when the stick or anything else mapped to the axis 0 is moved to the extrema. If the Val will allow it.
That's a little much for most applications though, so let's say we want to move it no more than 50 degrees. 1000/50=20. -1000/50=-20 (of course also applies). So type this:

angle=_analog(0)/20

Now we want it to begin at -10 degrees. Demanding aren't we?

angle=-10+_analog(0)/20
angle=_analog(0)/20-10 is "more clean syntax"

Remember to update the Val!
ANGLE(default=-10, min=-60, max=40 ste..NO!)

These examples were for script. For Lua the syntax is like so:
If you have nothing else programmed:

function main()
ANGLE=_ANALOG(0)/20-10
end

See the difference? Pay attention at upper and lower case. This is very important in Lua.
Check the Lua-tutorial for more on this.


Well, that's the basics!
Of course there's more to play around with. The mouse, a hat, mixers.
I might extend this tutorial for that but for now, my hands are sore from typing!
Eventually you can/could encorporate this with a fly-by-wire system and fly/drive/float like a lot of modern machines fly/drive/float!
But this should be enough to help you on your way and enjoy your models with possibly more control then with buttons alone.

Here's a very simple example, coded in both script and Lua.
It also provides basic info on the joystick/mouse axes, hats and some buttons.
Use it how you like.
Code:
// [RCD]
Val
{
   GREEN(default=0, min=-90, max=90)
   RED(default=-90, min=-180, max=90)
}
Key
{
}
Body
{
   Core() {
      N:Cowl(angle=red, color=#FF0000) { }
      E:Cowl(angle=green, color=#00FF00) {
         W:Cowl(color=#808080) { }
      }
   }
}
Script
{print 0, "axis 0:  ", _analog(0)
print 1, "axis 1:  ", _analog(1)
print 2, "axis 2:  ", _analog(2)
print 3, "axis 3:  ", _analog(3)
print 4, "axis 4:  ", _analog(4)
print 5, "axis 5:  ", _analog(5)
print 7, "hat:      ", _hat(0)
print 9, "mouse x:  ", _mx()
print 10, "mouse y:  " ,_my()
print 11, "mouse L:  " ,_ml()
print 12, "mouse M: " ,_mm()
print 13, "mouse R:  " ,_mr()

green=_analog(0)/11
red=_analog(1)/11-90}
Lua
{function main()

   out(0, "axis 0:  ", _ANALOG(0))
   out(1, "axis 1:  ", _ANALOG(1))
   out( 2, "axis 2:  ", _ANALOG(2))
   out(3, "axis 3:  ", _ANALOG(3))
   out(4, "axis 4:  ", _ANALOG(4))
   out(5, "axis 5:  ", _ANALOG(5))
   out(7, "hat:      ", _HAT(0))
   out(9, "mouse x:  ", _MX())
   out(10, "mouse y:  ", _MY())
   out(11, "mouse L:  " ,_ML())
   out(12, "mouse M: " ,_MM())
   out(13, "mouse R:  " ,_MR())

   GREEN=_ANALOG(0)/11
   RED=_ANALOG(1)/11-90

end}
Happy designing!

T-Bouw
Car
Car

Posts: 22
Join date: 2010-07-22
Age: 31
Location: The Netherlands

View user profile

Back to top Go down

Re: Analogue control for your models.

Post by lamborghini boi on Tue Oct 26, 2010 10:07 pm

thank you! iv been needing this for a long time now

lamborghini boi
Car
Car

Posts: 10
Join date: 2010-10-14
Age: 19
Location: United States

View user profile

Back to top Go down

Re: Analogue control for your models.

Post by JHaskly on Wed Oct 27, 2010 6:30 am

VAL's aren't anywhere near as fiddly when you use Lua, thankfully.

Good tutorial though!

_________________
Previously (and currently) known as Juz.

Please do not write "LUA", beause it's "Lua". It's Moon in Portuguese, not a Limited User Account, Last Universal Ancestor, or the Lukla Airport in Nepal.

JHaskly
Admin

Posts: 235
Join date: 2010-07-16
Age: 18
Location: Brisbane

View user profile

Back to top Go down

Re: Analogue control for your models.

Post by RA2lover on Fri Dec 03, 2010 12:56 am

i couldn't find my gamepad's right stick Y axis, even when spamming it by using a for lua function like

Code:
function spamanalogcontrols()
for i=1,32 do
out(i-1,_ANALOG(i-1))
end
.

also, is there a way to map boolean controls(aka buttons)?

RA2lover
Walker
Walker

Posts: 378
Join date: 2010-10-12
Age: 19
Location: Brazil

View user profile

Back to top Go down

Re: Analogue control for your models.

Post by T-Bouw on Fri Dec 03, 2010 8:36 am

Okay, I gave your code a test.
However, there are only a maximum of 6 axi, axises (whatever) to use in RC. So "for i=1, 6 do" 'll be fine.
We don't want to waste CPU-power.

I never thought of outputting the axis like that. But it works for me!
Hooked up an Xbox 360 controller. I confirmed again that the pheripheral doesn't work when you plug it in while RigidChips is running. Just restart RC in that case.

You can map the gamepad buttons to the RC keyboard commands.
But there are no dedicated buttons for a gamepad scripting-wise like for the buttons on the mouse.

T-Bouw
Car
Car

Posts: 22
Join date: 2010-07-22
Age: 31
Location: The Netherlands

View user profile

Back to top Go down

Re: Analogue control for your models.

Post by freek4ever on Fri Dec 02, 2011 8:54 pm

there must be an update for windows 7 and an update for more butons on your gampad


freek4ever
Tank
Tank

Posts: 97
Join date: 2011-08-26
Age: 17
Location: nederland holand

View user profile

Back to top Go down

Re: Analogue control for your models.

Post by T-Bouw on Fri Dec 09, 2011 10:37 am

I haven't posted for millenia, but this is a good reason as any to start again!

You mean an update for Rigidchips?
We're waiting for that for ages, but the project has been abandonned by it's programmer for several years now. So no chance of that happening anytime soon I'm afraid.

Not being able to configure the controls in Windows 7 for Rigidchips, means having to leave them as default.

To find out what axis/button/hat does what in default, you can use my program posted above for example (only copy the part of the code of the version you want to use, Script or Lua).
Then write down what you see and use that info. to program your controls in your model.

If not all buttons of your gamepad are detected by RC, you can use a program to convert those gamepadbuttons to keyboardbuttons.
I use JoyToKey for that.
It's a very simple program that gets the job done.


T-Bouw
Car
Car

Posts: 22
Join date: 2010-07-22
Age: 31
Location: The Netherlands

View user profile

Back to top Go down

Re: Analogue control for your models.

Post by freek4ever on Sun Dec 11, 2011 9:36 pm

That program must be great so I can shoot and fly at the same time

freek4ever
Tank
Tank

Posts: 97
Join date: 2011-08-26
Age: 17
Location: nederland holand

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum