Currently the developers are putting their own money into JC2-MP to keep the servers online.

Please take a few seconds of your time and disable your AdBlock plugin for our website.

Ad revenue is not going to developers, it is used purely for covering our hosting costs.

 

You are also free to donate, which removes all ads from our website!

Patch 0.3 was just released! Full changelog here: https://t.co/4A50m6IKen

2 years ago

Advertisement
October 22, 2019, 10:43:59 am

Author Topic: [Beta] Autopilot  (Read 9311 times)

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
[Beta] Autopilot
« on: March 30, 2015, 04:47:31 pm »
First post, first script. I've been playing JC2MP for quite a while now, but only just started learning how to write JC2MP scripts about a week ago, so bear with me.

I've had this vision of building a flight simulator in JC2, but I don't exactly have the time or resources to do it, so I've decided to release this autopilot script. The basics are done, but there are still some changes to be made, so it's not quite ready for a full release.

Autopilot



What's included: The main autopilot script includes roll, pitch, heading, altitude, speed, and waypoint holds, and a GUI control panel. I've also included a generic HUD script, though this is not required for the autopilot to function.

How it works: When you turn on each autopilot function, your plane is given an input to move towards the targeted value. As the plane approaches the value, the input power is decreased. There are power modifiers that can be adjusted. Press Z while in a plane to open the control panel.

Notes:

  • Autopilot does not work while the player is chatting or alt-tabbed out of the game.
  • The altitude-hold does not account for vertical speed. Unless I change that, it's up to the pilot to make sure the plane has enough velocity, either manually or with the speed-hold.

Summary of changes since posting:

- 30 March
  • Minor bug fixes
  • Pitch-hold now accounts for upside-down flight

- 31 March
  • Altitude-hold now has a positive bias to correct for gravity (semi-permanent fix)
  • Ground and vertical speeds in HUD are now relative to horizontal plane and vertical axis rather than the vehicle's angle

- 02 April

- 05 April
  • Switched from numerical indices to string-based keys for configuration tables
  • Waypoint-hold no longer seeks invisible waypoint
  • Heading-hold 0/360 degrees issue fixed

- 07 April
  • Tweaked some settings and added comments
  • Pitch-hold now accounts for side-ways flight
  • Throttle-hold renamed to speed-hold

- 10 April
  • Converted from text-based control to GUI control. Press Z to toggle the panel

-19 April
  • Optimized GUI code

-23 May
  • Added quickset buttons
  • Optimizations

-30 May
  • Implemented approach-hold system for automated landings
  • Player input no longer overrides autopilot input
  • Minor changes to GUI, settings, and logic

-11 June
  • Implemented target-hold system for coordinating flying.
  • Fixed bug where autopilot functions would deactivate when waypoint or approach holds failed to activate

-24 June
  • Added visual approach-path script
  • Added runway data for all runways
  • Fixed crash on plane despawn
  • Optimized runway detection for approach-hold
  • Target-hold now deactivates if targeted plane loses its driver
  • Simplified debug HUD

-12 July
  • Reorganized some of the code
  • Bug fixes and optimizations
  • Made color scheme configurable
  • Added GUI indicator for Target-Hold
  • Added GUI indicator for Approach-Hold
  • Removed ApproachPath script
  • Approach-Hold now scans for runways

-07 Aug
  • Target-Hold now scans for planes in the same way that Approach-Hold scans for runways
  • Removed degrees functions from the Autopilot class and moved them to _init.lua
  • Changed the autopilot vehicle get functions to the Vehicle class and moved them to _init.lua
  • Fixed bug where Approach-Hold would not turn on the Autopilot main switch
  • Simplified plane-despawn check

-12 Sept
  • Settings (units, gain, max inputs) are now adjustable in-game
  • Added options to display different units
  • Refactored most of the GUI code for better performance

----

Feel free to leave your comments, concerns, suggestions, questions, or constructive criticism! Thanks for your support!

GitHub Link
« Last Edit: December 19, 2015, 05:20:46 pm by SinisterRectus »

LordNoob

  • Sr. Member
  • ****
  • Posts: 349
    • View Profile
Re: Autopilot
« Reply #1 on: March 30, 2015, 11:09:08 pm »
Interesting, does this compensate for the natural roll that most planes seem to have when not paying attention to the controls?

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: Autopilot
« Reply #2 on: March 30, 2015, 11:47:47 pm »
Interesting, does this compensate for the natural roll that most planes seem to have when not paying attention to the controls?
Short answer: Yes.

Long answer:

The roll-hold allows you to select a specific roll angle for the plane to achieve. If you set an angle of 0, the analog nature of Input:SetValue() will have the plane approach 0, but it may not get it exactly at 0. The only way to do that is with Vehicle:SetAngle(), a server-side function, so the heading of some planes will undoubtedly change when using only the roll-hold.

For example: Pells have a left-turn bias for some reason. If you set the roll-hold to 0 degrees and if the Pell is at 0 degrees, there will be no input fired. This will allow the Pell to drift to the left slightly until the angle is large enough to fire PlaneTurnRight with a power that will overcome the Pell's own drift. It's a balancing act, but it won't balance at 0 degrees. It's more like 1 degree in my experience. That's probably better than real-life autopilot systems that have to deal with wind and pressure changes.

Solution: If you want to guarantee a straight path, use the heading-hold or waypoint-hold. These actually use the roll-hold, but continuously update the roll-hold's setting in order to keep an accurate course.
« Last Edit: March 31, 2015, 12:46:40 am by SinisterRectus »

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Beta] Autopilot
« Reply #3 on: April 11, 2015, 02:13:05 pm »
Update:

I got rid of the text-based commands and added a small GUI window. Press Z to open it.
« Last Edit: May 23, 2015, 04:51:43 pm by SinisterRectus »

misterff1

  • Donator
  • Hero Member
  • *****
  • Posts: 582
    • View Profile
Re: [Beta] Autopilot
« Reply #4 on: April 18, 2015, 05:52:56 pm »
Going to test this. very curious to see if it works as I hope it does :)

Edit: wow, that's really really good so far! question: could you add all the stats to the menu as well please? it looks a bit ugly like this :)

Also, it would be AWESOME if you could make planes take off and land from one airport to another! :D
« Last Edit: April 18, 2015, 06:21:04 pm by misterff1 »

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Beta] Autopilot
« Reply #5 on: April 18, 2015, 08:33:40 pm »
wow, that's really really good so far!
Thanks.

Quote
question: could you add all the stats to the menu as well please? it looks a bit ugly like this :)
The text based HUD is mostly for debugging the autopilot. I can move it to a GUI window at some point in the future.

Quote
Also, it would be AWESOME if you could make planes take off and land from one airport to another! :D
Yeah, I would like to make that happen. Auto-landing is on my to-do list, but it's not an easy task, so don't expect it soon.
« Last Edit: April 18, 2015, 10:00:40 pm by SinisterRectus »

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Beta] Autopilot
« Reply #6 on: May 23, 2015, 04:49:43 pm »
Update:

- Added quickset buttons that allow you to:
  • Set pitch or roll to zero degrees
  • Lock altitude or heading to current altitude or heading
  • Set airspeed to plane's neutral cruise speed

- Optimizations
  • Availability check moved from PreTick to LocalPlayerEnterVehicle/LocalPlayerExitVehicle
  • Window element sizes and positions update on window Resize instead of window Render

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Beta] Autopilot
« Reply #7 on: May 30, 2015, 08:58:18 pm »
Update - Automated Landings!

I've made a ton of minor changes, but the big update here is the progress I've made on automated landings in the form of an approach-hold. In the video below, both landings were performed entirely by the autopilot.

Approach-Hold Demo

You must be inside the runway's glideslope (pictured below) and pointed towards the runway for the approach-hold to activate.



So far, there are settings for the PIA runways and Kem Sungai Sejuk. I will add more in due time. There are also individual landing parameters for each plane which seem to work fairly well. Tweaks may be required.

Full list of changes:

- Features
  • Implemented approach-hold system for automated landings
  • Player input no longer overrides autopilot input
  • Heading-hold setting wraps to 1 when incrementing from 360 and to 359 when decrementing from 0

- GUI
  • Removed "hold" from button display names
  • Added Approach and Target buttons and reorganized layout
  • Added orange color for activated buttons

- Settings
  • Added landing parameters for each plane
  • Added runway data for four PIA runways and Kem Sungai Sejuk

- Other
  • Changed method for checking local vehicle status
  • Made minor changes to the way autopilot functions are turned on and off
  • Removed variable argument from vehicle Get functions
  • Added DegreesDifference and OppositeDegrees functions
  • Added YawToHeading and HeadingToYaw functions
  • Added FollowTargetXZ and FollowTargetY functions
  • Rewrote waypoint-hold
  • Added glidescope rendering to "HUD" debug script (commented out by default)
« Last Edit: June 13, 2015, 02:32:59 pm by SinisterRectus »

__init__

  • Donator
  • Newbie
  • *****
  • Posts: 43
    • View Profile
Re: [Beta] Autopilot
« Reply #8 on: May 30, 2015, 10:46:31 pm »
Whoa, this is really cool! Nice job!

ZeMantras

  • Donator
  • Jr. Member
  • *****
  • Posts: 86
    • View Profile
Re: [Beta] Autopilot
« Reply #9 on: May 30, 2015, 11:55:49 pm »
amazing! subscribed t your Youtubechannel,ill be cheking the news ;D

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Beta] Autopilot
« Reply #10 on: May 31, 2015, 12:25:19 am »
I don't really use the channel like a channel. It's just a place for me to throw random videos, most of which are jcmp related, but thanks. :)

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Beta] Autopilot
« Reply #11 on: June 11, 2015, 05:18:53 pm »
Update - Target Hold!

The "Target" button that I previously added is now functional. Press it, and your plane will automatically follow the nearest piloted plane that is in front of yours, assuming one exists. Videos below!

Target-Hold Demo 1

Target-Hold Demo 2

It is currently set to keep your plane at a distance of 100 m. Because of the nature of the autopilot, this will work well for casual flight with gentle turns, but not in situations that require sharp turns, such as dogfighting.

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Beta] Autopilot
« Reply #12 on: June 24, 2015, 08:52:34 pm »
Update! - Visual Approach Paths!

I have added an optional script to the autopilot module that renders approach paths if your plane is inside one and facing a runway.

Other changes:
  • Added runway data for all runways, bringing the total to 32 runways across 13 airports. Adjustments may be required for some locations.
  • Fixed crash on plane despawn
  • Optimized runway detection for approach-hold
  • Target-hold now deactivates if targeted plane loses its driver
  • Simplified debug HUD

__init__

  • Donator
  • Newbie
  • *****
  • Posts: 43
    • View Profile
Re: [Beta] Autopilot
« Reply #13 on: June 24, 2015, 09:19:09 pm »
Wow, this is getting to be a very amazing script! It's interesting to see how it has evolved over time.

Congrats on Betatester, by the way!

SinisterRectus

  • JC2-MP Betatester
  • Sr. Member
  • *****
  • Posts: 451
    • View Profile
Re: [Beta] Autopilot
« Reply #14 on: June 24, 2015, 10:52:16 pm »
Wow, this is getting to be a very amazing script! It's interesting to see how it has evolved over time.

Congrats on Betatester, by the way!
Thank you.