Giter Club home page Giter Club logo

kuby's Introduction

Kuby

Build Status

Crash your Kerbals using Ruby!

Kuby is a Ruby wrapper for the game Kerbal Space Program. This gem exposes a simple DSL with which you can control your rockets.

Installation

Install the gem:

$ gem install kuby

Make sure you have a recent version of KSP and also install the Telemachus plugin.

Usage

Basic example

Create a ruby file with the following contents (simple_launch.rb for example):

require 'rubygems'
require 'kuby'

# Optional parameters :host, :port, otherwise defaults will be used (127.0.0.1:8085)
link = Kuby::Link.new

# Connect to KSP
link.connect!

# Initiate first stage
link.stage!

# Set to full throttle
link.throttle_full

# Activate SAS
link.toggle_sas

Now create a new rocket in KSP or load an existing one. Be sure to add one of the Telemachus antennas to it, otherwise your rocket won't be able to communicate. Now go to the launchpad and when the ship is loaded and you are ready for launch, execute the following command in a terminal:

$ ruby simple_launch.rb

Kuby will connect to your rocket and issue the commands in the order you specified in the file, your rocket will activate the first stage, go to full throttle and enable SAS. After that, the script ends but your rocket will keep flying.

Advanced example

This example will fly your rocket to ± 150 meters and then keeps it floating there by changing the throttle using an implementation of a PID controller

require 'rubygems'
require 'kuby'

# Optional parameters :host, :port, otherwise defaults will be used (127.0.0.1:8085)
link = Kuby::Link.new

# Connect to KSP
link.connect!

# Initiate first stage
link.stage!

# Set to full throttle
link.throttle_full

# Activate SAS
link.toggle_sas

# Wait untill we're at 150 meters
while link.altitude < 150 do
	sleep 0.2
end

target = 0.0
previous = 0.0
error = 0.0
integral = 0.0
derivative = 0.0
time = link.mission_time

loop do
	dt = link.mission_time - time
	time = link.mission_time
	error = target - link.vertical_speed
	integral = integral + error * dt
	derivative = (error - previous)/dt
	
	new_throttle = (error/10 + integral/15 + derivative/30)
	
	if new_throttle > 1.0
		new_throttle = 1.0
	elsif new_throttle < 0.0
		new_throttle = 0.0
	end
	
	link.set_throttle new_throttle
	
	previous = error
	
	sleep 0.2
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

kuby's People

Contributors

rrooding avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.