Double pendulum as modulation in Kontakt KSP
Hi, I'm trying to use a double pendulum to modulate parameters within KSP
I've given it a go but my code is not giving me results. I was hoping to see some sort of wavy modulation
See code attached, any help would be gratefully appreciated, thanks in advance.
on init
declare ui_knob $Volume (0,1000000,1000000)
declare ~L1
~L1 := 100.00
declare ~L2
~L2 := 100.00
declare ~M1
~M1 := 40.00
declare ~M2
~M2 := 40.00
declare ~A1
~A1 := 90.00
declare ~A2
~A2 := 0.00
declare ~A1V
declare ~A2V
declare ~A1A
declare ~A2A
~A1V := ~A1A
~A2V := ~A2A
~A1 := ~A1V
~A2 := ~A2V
declare ~G
~G := 9.81
declare ~num1
declare ~num2
declare ~num3
declare ~num4
declare ~den
declare $test_int
end on
function pendulum
~A1V := ~A1A
~A2V := ~A2A
~A1 := ~A1V
~A2 := ~A2V
~num1 := -~G * (2.0 * ~M1 + ~M2) * sin(~A1)
~num2 := -~M2 * ~G * sin(~A1 - 2.0 * ~A2)
~num3 := -2.0 * sin(~A1 - ~A2) * ~M2
~num4 := ~A2V * ~A2V * ~L2 + ~A1V * ~A1V * ~L1 * cos(~A1 - ~A2)
~den := ~L1 * (2.0 * ~M1 + ~M2 - ~M2 * cos(2.0 * ~A1 - 2.0 * ~A2))
~A1A := (~num1 + ~num2 + ~num3 * ~num4) / ~den
~num1 := 2.0 * sin(~A1 - ~A2)
~num2 := ~A1V * ~A1V * ~L1 * (~M1 + ~M2)
~num3 := ~G * (~M1 + ~M2) * cos(~A1)
~num4 := ~A2V * ~A2V * ~L2 * ~M2 * cos(~A1 - ~A2)
~den := ~L2 * (2.0 * ~M1 + ~M2 - ~M2 * cos(2.0 * ~A1 - 2.0 * ~A2))
~A2A := (~num1 * (~num2 + ~num3 + ~num4)) / ~den
$test_int := real_to_int(~A2A)
message($test_int)
{~A1V := abs(~A1V)}
end function
on ui_control ($Volume)
set_engine_par($ENGINE_PAR_VOLUME,$test_int,-1,-1,-1)
end on
Comments
-
Well written code! Here are a few tips:
- you need to set a listener in order to trigger somehow the movement
- you need to call the pendulum function within the LCB
- you should increment (time steps) the values which take care of the pendulum motion (velocity and angle) so it happens automatically (ie
~A1V := ~A1V + ~A1A * 0.1
and~A1 := ~A1 + ~A1V * 0.1)
- AFAIK trigonometric functions should utilize radians and not degrees. It'd be better to use NI_MATH_PI and convert to radians:
declare ~A1 := 90.0 * NI_MATH_PI / 180.0
0 -
Thats great thank you! Ill give all that a shot.
0 -
Hi theodorech
Thanks for your help
I Have given what you suggested a go and Ive made progress but I still not able to get the parameter to modulate. It just returns the value to 0.
I think it may be to do with the time steps you suggested, I'm not fully understanding what to do.
Could you please provide further help.
Thank you again.
See my update code bellow:
on init
make_perfview
set_script_title("Pendulum")
set_ui_height_px(125)
declare ui_button $Button
$Button := 0
set_listener($NI_SIGNAL_TIMER_MS,100000)
declare ~L1
~L1 := 100.00
declare ~L2
~L2 := 100.00
declare ~M1
~M1 := 40.00
declare ~M2
~M2 := 40.00
declare ~A1
~A1 := 90.0 * ~NI_MATH_PI / 180.0
declare ~A2
~A2 := 90.0 * ~NI_MATH_PI / 180.0
declare ~A1V
declare ~A2V
declare ~A1A
declare ~A2A
~A1V := ~A1A
~A2V := ~A2A
~A1 := ~A1V
~A2 := ~A2V
declare ~G
~G := 9.81
declare ~num1
declare ~num2
declare ~num3
declare ~num4
declare ~dendeclare $test_int
end on
function func_pendulum
~A1V := ~A1A
~A2V := ~A2A
~A1 := ~A1V
~A2 := ~A2V
~num1 := -~G * (2.0 * ~M1 + ~M2) * sin(~A1)
~num2 := -~M2 * ~G * sin(~A1 - 2.0 * ~A2)
~num3 := -2.0 * sin(~A1 - ~A2) * ~M2
~num4 := ~A2V * ~A2V * ~L2 + ~A1V * ~A1V * ~L1 * cos(~A1 - ~A2)
~den := ~L1 * (2.0 * ~M1 + ~M2 - ~M2 * cos(2.0 * ~A1 - 2.0 * ~A2))
~A1A := (~num1 + ~num2 + ~num3 * ~num4) / ~den
~num1 := 2.0 * sin(~A1 - ~A2)
~num2 := ~A1V * ~A1V * ~L1 * (~M1 + ~M2)
~num3 := ~G * (~M1 + ~M2) * cos(~A1)
~num4 := ~A2V * ~A2V * ~L2 * ~M2 * cos(~A1 - ~A2)
~den := ~L2 * (2.0 * ~M1 + ~M2 - ~M2 * cos(2.0 * ~A1 - 2.0 * ~A2))
~A2A := (~num1 * (~num2 + ~num3 + ~num4)) / ~den
~A1V := ~A1V + ~A1A * 0.1
~A1 := ~A1 + ~A1V * 0.1
$test_int := real_to_int(~A2A)
{~A1V := abs(~A1V)}end function
on listener
if ($NI_SIGNAL_TYPE = $NI_SIGNAL_TIMER_MS)call func_pendulum
end if
end on
on ui_control ($Button)
if ($Button = 1)set_engine_par($ENGINE_PAR_VOLUME,$test_int,-1,-1,-1)
end if
end on0
Categories
- All Categories
- 19 Welcome
- 1.5K Hangout
- 62 NI News
- 785 Tech Talks
- 4.1K Native Access
- 16.5K Komplete
- 2K Komplete General
- 4.3K Komplete Kontrol
- 5.7K Kontakt
- 1.6K Reaktor
- 379 Battery 4
- 845 Guitar Rig & FX
- 429 Massive X & Synths
- 1.3K Other Software & Hardware
- 5.8K Maschine
- 7.3K Traktor
- 7.3K Traktor Software & Hardware
- Check out everything you can do
- Create an account
- See member benefits
- Answer questions
- Ask the community
- See product news
- Connect with creators