Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: autopilot  (Read 13843 times)

bomber

  • Hero Member
  • *****
  • Posts: 523
  • newbie
autopilot
« on: April 21, 2015, 02:38:48 pm »

Hi, I'd like to create a simple wingleveler autopilot, but need to be able to enable/disable...

I want to extend the view commands such that I have a duplicate pilot view, but jumping to that view changes a jsbsim property to '1' and not being in that view set the property to '0'

can someone mod the code below so as I can paste it into the .js file..

regards

Simon

Code: [Select]
//Camera positions + ground effect
var camera_z = clamp((this.fdm["gear/unit[0]/compression-ft"]+this.fdm["gear/unit[1]/compression-ft"]+this.fdm["gear/unit[2]/compression-ft"])*this.fdm["gear/unit[0]/compression-ft"]*0.2, -0.05, 0.05);
if(seat_cam===0)
this.set_fps_camera_pos({x:-0.25, y:-0.2, z:0.3-camera_z}); //Front Seat Left
else if(seat_cam===1)
this.set_fps_camera_pos({x: 0.25, y:-0.2, z:0.3-camera_z}); //Front Seat Right
else if(seat_cam===2)
this.set_fps_camera_pos({x:-0.25, y:-1, z:0.2-camera_z}); //Back Seat Left
else if(seat_cam===3)
this.set_fps_camera_pos({x: 0.25, y:-1, z:0.2-camera_z}); //Back Seat Right
else if(seat_cam===4)
this.set_fps_camera_pos({x:0.0,y: 1.0,z: 0.2}); //Nose
else if(seat_cam===5)
this.set_fps_camera_pos({x:-0.6,y:-1.5,z:-0.2}); //Body Left
else if(seat_cam===6)
this.set_fps_camera_pos({x: 0.6,y:-1.5,z:-0.2}); //Body Right
else if(seat_cam===7)
this.set_fps_camera_pos({x:-4.2,y:-0.1,z: 0.3}); //Wing Left
else if(seat_cam===8)
this.set_fps_camera_pos({x: 4.2,y:-0.1,z: 0.3}); //Wing Right
else if(seat_cam===9)
this.set_fps_camera_pos({x: 0,y:-5.1,z: 1.2}); //Tail
Logged
"If anyone ever tells you anything about an aeroplane which is so bloody complicated you can't understand it, take it from me - it's all balls" - R J Mitchell

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: autopilot
« Reply #1 on: April 22, 2015, 12:09:05 am »

This should work. Just edit this property, this.fdm["fcs/wing_lvl_ap"]=wing_lvl_ap; to the one you are trying to set.

Regards,
Uriah

Code: [Select]
//Camera position + ground effect + Wing Level AP Switch
var wing_lvl_ap;
this.fdm["fcs/wing_lvl_ap"]=wing_lvl_ap;

var camera_z = clamp((this.fdm["gear/unit[0]/compression-ft"]+this.fdm["gear/unit[1]/compression-ft"]+this.fdm["gear/unit[2]/compression-ft"])*this.fdm["gear/unit[0]/compression-ft"]*0.2, -0.05, 0.05);
if(seat_cam===0)
this.set_fps_camera_pos({x:-0.25, y:-0.2, z:0.3-camera_z}); //Front Seat Left
if(seat_cam===1)
this.set_fps_camera_pos({x:-0.25, y:-0.2, z:0.3-camera_z}); //Front Seat Left

if(seat_cam===0){wing_lvl_ap=0;} //Turn OFF Wing Level Autopilot
if(seat_cam===1){wing_lvl_ap=1;} // Turn ON Wing Level Autopilot
« Last Edit: April 22, 2015, 09:52:41 am by Uriah »
Logged

bomber

  • Hero Member
  • *****
  • Posts: 523
  • newbie
Re: autopilot
« Reply #2 on: April 22, 2015, 09:34:56 am »

Cheers, will look at it and the fuel system...
Logged
"If anyone ever tells you anything about an aeroplane which is so bloody complicated you can't understand it, take it from me - it's all balls" - R J Mitchell

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: autopilot
« Reply #3 on: April 22, 2015, 10:01:10 am »

Whooops. Just noticed a mistake, and realized you'll need another function modified, so instead here is the full script:
http://www.mediafire.com/view/n6o95o2gw3vw2wm/c172.js

I removed all of the camera positions except 0 and 1, so now it works as you requested.

I also added a function to display the state of Wing Level AP in the debug console, (P key).

Code: [Select]
var seat_cam = 0;
function switch_seat(cam){
if(cam===0) seat_cam=0;
else if(cam===1)seat_cam=1;
  else return false;return true;}


Code: [Select]
//Camera position + ground effect + Wing Level AP Switch
var wing_lvl_ap;
this.fdm["fcs/wing_lvl_ap"]=wing_lvl_ap;

var camera_z = clamp((this.fdm["gear/unit[0]/compression-ft"]+this.fdm["gear/unit[1]/compression-ft"]+this.fdm["gear/unit[2]/compression-ft"])*this.fdm["gear/unit[0]/compression-ft"]*0.2, -0.05, 0.05);
if(seat_cam===0)
this.set_fps_camera_pos({x:-0.25, y:-0.2, z:0.3-camera_z}); //Front Seat Left
if(seat_cam===1)
this.set_fps_camera_pos({x:-0.25, y:-0.2, z:0.3-camera_z}); //Front Seat Left

if(seat_cam===0){wing_lvl_ap=0;} //Turn OFF Wing Level Autopilot
if(seat_cam===1){wing_lvl_ap=1;} // Turn ON Wing Level Autopilot
Logged

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: autopilot
« Reply #4 on: April 22, 2015, 10:03:55 am »

P.S. If you are using a newer version of Levi's C172 script with additional functions, e-mail it to me and I'll integrate the changes.
Logged

bomber

  • Hero Member
  • *****
  • Posts: 523
  • newbie
Re: autopilot
« Reply #5 on: April 29, 2015, 12:13:25 pm »

Ok what key do I press for jumping seats ?
Logged
"If anyone ever tells you anything about an aeroplane which is so bloody complicated you can't understand it, take it from me - it's all balls" - R J Mitchell

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: autopilot
« Reply #6 on: April 29, 2015, 12:17:06 pm »

V key.
Logged

bomber

  • Hero Member
  • *****
  • Posts: 523
  • newbie
Re: autopilot
« Reply #7 on: April 29, 2015, 12:17:55 pm »

also the log (P key) is that intended, wouldn't it be better if it only logged everytime the AP was turned on or off.... ie change of state ?
Logged
"If anyone ever tells you anything about an aeroplane which is so bloody complicated you can't understand it, take it from me - it's all balls" - R J Mitchell

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: autopilot
« Reply #8 on: April 29, 2015, 12:22:47 pm »

I just added that so you could see what camera mode you are in. There isn't a way I can think of to log that only at the time when you change seats, as I have to call it from the update section. If you want to remove it, comment out the line at the very bottom of the script. Also, you'll notice that when you hit C key to go to external view, and then return to cockpit view with V key, that the camera mode will return to the default seat_cam = 0; I could write a logic function to keep the prior seat_cam mode so it doesn't default to 0. Of course the extended controls will have a key bind specifically for turning on/off autopilot.

Regards,
Uriah
Logged

bomber

  • Hero Member
  • *****
  • Posts: 523
  • newbie
Re: autopilot
« Reply #9 on: April 29, 2015, 12:25:55 pm »

Oh there's no need to throw good time into this it's just a proof of Auto-pilot concept...

AND IT WORKS :)
Logged
"If anyone ever tells you anything about an aeroplane which is so bloody complicated you can't understand it, take it from me - it's all balls" - R J Mitchell

Uriah

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 569
  • We do these things not because they are easy. -JFK
Re: autopilot
« Reply #10 on: April 29, 2015, 12:26:34 pm »

Nice!!!  8)
Logged

bomber

  • Hero Member
  • *****
  • Posts: 523
  • newbie
Re: autopilot
« Reply #11 on: May 31, 2015, 12:51:46 pm »

"I also added a function to display the state of Wing Level AP in the debug console, (P key)."

Did we lose the debug console in a release ?
Logged
"If anyone ever tells you anything about an aeroplane which is so bloody complicated you can't understand it, take it from me - it's all balls" - R J Mitchell

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: autopilot
« Reply #12 on: May 31, 2015, 01:50:21 pm »

Moved to Alt+L, and Alt+Shift+L opens a separate log window.
Logged

bomber

  • Hero Member
  • *****
  • Posts: 523
  • newbie
Re: autopilot
« Reply #13 on: May 31, 2015, 02:54:29 pm »

Thanks
Logged
"If anyone ever tells you anything about an aeroplane which is so bloody complicated you can't understand it, take it from me - it's all balls" - R J Mitchell