LUA PITCH script (lock Elevators angle / Pitch RCS power)

V8Li

Member
Joined
Apr 9, 2008
Messages
200
Reaction score
0
Points
16
I'm using Orbiter with the stock DG and Shuttle (still a big fan) with my laptop from time to time so I don't always have a joystick available. Since I don't use autopilots and the vsls. -as most of you know- don't have much trim angle I can't do a reentry at high AOAs and have to land very fast not to crush (or keep pressing the keyboard keys).

Having said that, this is a LUA script I wrote, it just keeps the elevator or Pitch RCS locked in place (locking the pitch input). It's not just for atmsph. flight but also for reentries but it needs attention and constant monitoring since the vessel might flip or the AOA might change (remember, this is not an autopilot that keeps a pitch or AOA, it just locks the pitch controls you are using).

-----
Install: create file /Script/DG/v8autopilot.lua with the code embeded below
Run:
1. Open Terminal MFD
2. Input: run('dg/v8autopilot')
3. Input: v8.pitch() - to activate pitch lock
4. Input: v8.pitch() - to deactivate pitch lock
Use any controls you need at any time
------

Code:
-- Set up autopilot structures
v8 = {}
v8.pitch_apID = nil
function setvessel (_v)
    v = _v
    class = _v:get_classname()
    if (class ~= 'DeltaGlider') and (class ~= 'DG-S') then
        term.out('Warning: Autopilot is designed for use with DeltaGlider.')
    end
end
function pitch_ap ()
 local uinput = 0
 while true do
  v:set_adclevel(AIRCTRL.ELEVATOR,uinput)
  if v:get_rcsmode() == 1 then
   if( uinput >= 0 ) then
    v:set_thrustergrouplevel(THGROUP.ATT_PITCHUP,uinput)
   else
    v:set_thrustergrouplevel(THGROUP.ATT_PITCHDOWN,-uinput)
   end
  end
  uinput = v:get_adclevel(AIRCTRL.ELEVATOR)
  proc.skip()
 end
end
-- -----------------------------------------------------------
-- User level entry functions
-- -----------------------------------------------------------
function v8.pitch ()
 if v8.pitch_apID == nil then
  term.out('v8ap: pitch autopilot ON')
  v8.pitch_apID = proc.bg(pitch_ap)
 else
  term.out('v8ap: pitch autopilot disabled')
  proc.kill(v8.pitch_apID)
  v:set_adclevel(AIRCTRL.ELEVATOR,0)
  v:set_thrustergrouplevel(THGROUP.ATT_PITCHUP,0)
  v:set_thrustergrouplevel(THGROUP.ATT_PITCHDOWN,0)
  v8.pitch_apID = nil
 end 
end
-- -----------------------------------------------------------
-- Initialisation code
v = {}
setvessel(vessel.get_focusinterface())
term.out('v8autopilot loaded')

Enjoy!
Note to admins: I wasn't able to find something like this when I wanted it so I just guessed this hasn't been posted already (sorry for duplicating if already posted)
 
This is an update that will get the input value from trim and not from elevator angle:

Code:
-- Set up autopilot structures
v8 = {}
v8.pitch_apID = nil

function setvessel (_v)
    v = _v
    class = _v:get_classname()
    if (class ~= 'Deltaglider') and (class ~= 'DG-S') then
        term.out('Warning: Autopilot is designed for use with DeltaGlider.')
    end
end

function pitch_ap ()
	local uinput = 0
	while true do
		if v:get_adcmode() == 1 then
			v:set_adclevel(AIRCTRL.ELEVATOR,uinput)
		end
		if v:get_adcmode() == 7 then
			v:set_adclevel(AIRCTRL.ELEVATOR,uinput)
		end
		if v:get_rcsmode() == 1 then
			if( uinput >= 0 ) then
				v:set_thrustergrouplevel(THGROUP.ATT_PITCHUP,uinput)
			else
				v:set_thrustergrouplevel(THGROUP.ATT_PITCHDOWN,-uinput)
			end
		end

		uinput = v:get_adclevel(AIRCTRL.ELEVATORTRIM)
		proc.skip()
	end
end

-- -----------------------------------------------------------
-- User level entry functions
-- -----------------------------------------------------------

function v8.pitch ()
	if v8.pitch_apID == nil then
		term.out('v8ap: pitch autopilot ON')
		v8.pitch_apID = proc.bg(pitch_ap)
	else
		term.out('v8ap: pitch autopilot disabled')
		proc.kill(v8.pitch_apID)
		v:set_adclevel(AIRCTRL.ELEVATOR,0)
		v:set_thrustergrouplevel(THGROUP.ATT_PITCHUP,0)
		v:set_thrustergrouplevel(THGROUP.ATT_PITCHDOWN,0)
		v8.pitch_apID = nil
	end	
end

-- -----------------------------------------------------------
-- Initialisation code

v = {}

setvessel(vessel.get_focusinterface())

term.out('v8autopilot loaded')
 
Back
Top