Jump to content

Kerbal Cockpit Simulator


Kotagi

Recommended Posts

30 minutes ago, Kotagi said:

It definitely feels good :D

Anyone who has ever stepped into this world knows that feeling of exhilaration! Great work! 

Do you mind sharing some of the technical steps so that we can keep a record / document for anyone that's having issues? :)

Link to comment
Share on other sites

I can definitely try to do a better job than I have been. My phone broke so I wont be able to take pics for a couple weeks while it gets fixed. 

I bought the sunfounder kit that had all the basic components plus the code that went with it. Ive been using the gpio extension board, and a breadboard to play around with different circuits without having to do any permanent wiring. As for krpc, follow the instruction on the getting started page(make sure to copy all the files from the krpc zip). Once the server is started, on whatever machine you want to connect, you need to download the libraries for krpc(Also on the getting started page. Windows and Linux have different methods). You need to know the ip address of the host computer(running ksp). Then you can use IDLE for Python 2.7 to connect to the server.

import krpc
conn = krpc.connect(address='host.ip.address' , name='Connection_Name')
vessel = conn.space_center.active_vessel
print(vessel.name)

If you get the name of your vessel back than you did everything right. That is where I am right now. I will update more as I figure everything out

 

Edited by Kotagi
Link to comment
Share on other sites

Man I wish my phone wasnt broken..So I got my launch button working and its so sweet. I really thought this part would take alot longer. Im sure my code isnt the cleanest it can be since I basically Frankensteined it together, but when I press my emergency stop button in says launch on the pi console and it turns on autopilot, sets a heading, throttles up, and stages. All from 1 button press. This seriously has endless potential. The pi can be extended to have over 900 pwm outputs with breakout boards from what I read. That means I can literally make every switch in the op. It will def take awhile but I now know it can be done. I still need to build a center console for the main buttons. And I still need 5 screens before I go any further on cosmetic work. But its definitely making progress

 

Link to comment
Share on other sites

Ok so I got the meter running with the fuel on the game. I need to add a cap to stabilize the voltage. Its a little shaky on max but working good enough for right now.. I do have a question though. So I was hoping fuel would be displayed as a percentage of capacity but I havent been able to find that yet. It displays in units. My problem is that I am using the duty cycle of the pwm as the variable I set to the fuel units. The variable has to be between 0-100. Fuel can be 1000's of units or just a couple so I need a piece of code that will scale any number to a 1-100 scale setting the initial input number as 100%. Probably do this by making it a decimal. Any thoughts? Anyone else on here use Krpc?

Link to comment
Share on other sites

13 minutes ago, Kotagi said:

 The variable has to be between 0-100. Fuel can be 1000's of units or just a couple so I need a piece of code that will scale any number to a 1-100 scale setting the initial input number as 100%. Probably do this by making it a decimal. Any thoughts? Anyone else on here use Krpc?

Can you do the mathematical conversion so that you're dealing with 0-100%, with that value then being translated to a PWM level?

 

Link to comment
Share on other sites

What size cap would you use to equalize voltage and make it less jumpy?  Also I got it all working. I wish I had a camera to show you. It responds very well to the fuel consumption in game. Then when I stage, It shoots back up to full for every stage. 

Would you guys be interested if I posted the code as I go so you can see how it evolves? Im not a pro so I only assume my code will be far from perfect..But if you guys want me to do that I will. Let me know. :D

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import krpc

LedPin = 16
conn = krpc.connect(address='u.dont.need.to.know' , name='meter')         # Connects So Kerbal Server
vessel = conn.space_center.active_vessel                        # Creates Object Representing Vessel
totalLF = conn.add_stream(vessel.resources.amount , 'LiquidFuel')
maxLF = conn.add_stream(vessel.resources.max , 'LiquidFuel')
tankPer = 0
def setup():
	global p
	GPIO.setmode(GPIO.BOARD)                                        # Numbers GPIOs by physical location
	GPIO.setup(LedPin, GPIO.OUT)                                    # Set LedPin's mode is output
	GPIO.output(LedPin, GPIO.LOW)                                   # Set LedPin to low(0V)
	p = GPIO.PWM(LedPin, 1000)                                      # set Frequece to 1KHz
	p.start(0)                                                      # Duty Cycle = 0

def add():
                global totalLF
                global maxLF
                global tankPer
                tankCap = (totalLF() / maxLF()) # Converts Capacity Into Decimal
                tankPer = int(tankCap * 100)    # Turns Decimal Into Percentage
                
                
                #print('Current: ' , totalLF())
                #print('Total: ' , maxLF())
                print ('Tank: %{}'.format(tankPer))

                
def loop():
              
	while True:
                global tankPer
                add()
		for dc in range(0, tankPer , 1):   # Increase duty cycle: 0~100
			p.ChangeDutyCycle(dc)     # Change duty cycle
			
def destroy():
	p.stop()
	GPIO.output(LedPin, GPIO.HIGH)    # turn off all leds
	GPIO.cleanup()

if __name__ == '__main__':     # Program start from here
	setup()
	try:
		loop()
	except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.
		destroy()

This is what I used to get the meter to display the fuel readout. 

Edited by Kotagi
Link to comment
Share on other sites

7 hours ago, Kotagi said:

What size cap would you use to equalize voltage and make it less jumpy?  Also I got it all working. I wish I had a camera to show you. It responds very well to the fuel consumption in game. Then when I stage, It shoots back up to full for every stage. 

Would you guys be interested if I posted the code as I go so you can see how it evolves? Im not a pro so I only assume my code will be far from perfect..But if you guys want me to do that I will. Let me know. :D

 

Is it because it's showing stage fuel (instead of total fuel)? If so, then it's doing what it's meant to :P:wink: 
If not, and it's jumping to 100%, then jumping back down to the 'correct' amount, that could be an issue with the cycling (ie. between information output, it's getting a false reading of 100%).

I suspect it is doing stage-by-stage by default (since you don't seem to be declaring it specifically; check out this -- 

 

As for the code - yes please! :D  

Link to comment
Share on other sites

21 minutes ago, Sputnix said:

Is it because it's showing stage fuel (instead of total fuel)? If so, then it's doing what it's meant to :P:wink: 
If not, and it's jumping to 100%, then jumping back down to the 'correct' amount, that could be an issue with the cycling (ie. between information output, it's getting a false reading of 100%).

The needle just wobbles. I believe someone suggested using a capacitor to help stabilize the voltage. I have a 10 nf and 100 nf. I guess I could try both and see what happens..lol

Edited by Kotagi
Link to comment
Share on other sites

3 minutes ago, Kotagi said:

The needle just wobbles. I believe someone suggested using a capacitor to help stabilize the voltage. I have a 10 uf and 100 uf. I guess I could try both and see what happens..lol

I think that would've been @richfiles. He's the resident electronics guru. I would believe anything he says. He's got street-cred! :cool: Check it out here: 

 

Link to comment
Share on other sites

2 minutes ago, Sputnix said:

I think that would've been @richfiles. He's the resident electronics guru. I would believe anything he says. He's got street-cred! :cool: Check it out here: 

 

Lol I guess I could have just read back. Thanks. I knew he suggested it, but I didnt see that he even suggested what size. Nice. Thank you @richfiles

Link to comment
Share on other sites

Too big of a capacitor, and the needle will become sluggish. Basically, too big a cap and it'll slowly move to 100% when you send a signal for 100%, and it'll drop slowly when reducing the PWM signal, which if you're burning fuel faster than the drop rate, would give you a false reading. the 10µf is probably okay to try. It's already probably at the very top end of sizes that'll be suitable. Now, if it's the type with a polarity marking, make sure that you match it up with he polarity going into the meter. 10µf is probably pretty big to be anything other than an electrolytic capacitor. They usually have a stripe or (-) marking that denotes the negative polarity lead.

Here is a pic of what you most likely have on hand:
Polarity-wet-Al-Elcaps.jpg

And just because the somebeaches have GOT to mess with ya...
Here's the markings for SOLID electrolyte caps (just incase this is what you have instead), cause the manufacturers just GOTTA be contrary! :rolleyes:
Polarity-rectangular-chips.jpg

Ornery backwards confusing manufacturers... Pick a standard! :huh:

standards.png

Edited by richfiles
Link to comment
Share on other sites

I was using that tool ALL wrong... I actually gave up, not realizing that it doesn't fill in the empty RC value... I see now that you have to play with it. So plugging in 66k and 10µf results in a rise time that doesn't level off till nearly 3 seconds in... That's an impressive delay. a 2.2µf cap will do full rise time in 0.6 seconds, with minimal ripple. 4.7µf will take 1.5 seconds to rise most of the way, and fully settle a bit before 2 seconds. Trying it with a 1µf cap gives a <0.2 second rise time, with just a tiny trace of ripple, that isn't really gonna show up at all.

I'd say, if you wanna experiment, and you either don't have a parts shop near by or you don't wanna wait for parts online, go and find yourself any random old bit of electronics, even a thrift shop gadget, and rip out a 1µf to 4.7µf capacitor. 4.7µf is probably at the absolute top end of what you could use. It's slower, but not ridiculous. 1µf to 2.2µf is probably ideal, and many, many small gadgets ought to have something you can scavenge.

If you find ceramic caps, then 105 and 225 are the number codes that refer to 1µf and 2.1µf. Those numbers will be printed don once side of the capacitor. A ceramic capacitor can be installed in any polarity. There is no negative or positive. The following are all ceramic capacitors. You'll most likely run into 1-2 and 4-8 (left to right) in old electronics (1980s/90s vintage). 
Ceramic_capacitors.jpg

Polyester caps (they look like bigger versions of 2, 4, and 11) are also without polarity, and will work just fine. They may use the number code like ceramics, or have printed values. Probably the number code though. That's all, if you feel like scavenging from old junk. I rather enjoy tearing things apart, but then, maybe that's just me. :sticktongue:

Edited by richfiles
Link to comment
Share on other sites

6 minutes ago, richfiles said:

I was using that tool ALL wrong... I actually gave up, not realizing that it doesn't fill in the empty RC value... I see now that you have to play with it. So plugging in 66k and 10µf results in a rise time that doesn't level off till nearly 3 seconds in... That's an impressive delay. a 2.2µf cap will do full rise time in 0.6 seconds, with minimal ripple. 4.7µf will take 1.5 seconds to rise most of the way, and fully settle a bit before 2 seconds. Trying it with a 1µf cap gives a <0.2 second rise time, with just a tiny trace of ripple, that isn't really gonna show up at all.

I'd say, if you wanna experiment, and you either don't have a parts shop near by or you don't wanna wait for parts online, go and find yourself any random old bit of electronics, even a thrift shop gadget, and rip out a 1µf to 4.7µf capacitor. 4.7µf is probably at the absolute top end of what you could use. It's slower, but not ridiculous. 1µf to 2.2µf is probably ideal, and many, many small gadgets ought to have something you can scavenge.

If you find ceramic caps, then 105 and 225 are the number codes that refer to 1µf and 2.1µf. Those numbers will be printed don once side of the capacitor. A ceramic capacitor can be installed in any polarity. There is no negative or positive. The following are all ceramic capacitors. You'll most likely run into 1-2 and 4-8 (left to right) in old electronics (1980s/90s vintage). 
Ceramic_capacitors.jpg

Polyester caps (they look like bigger versions of 2, 4, and 11) are also without polarity, and will work just fine. They may use the number code like ceramics, or have printed values. Probably the number code though. That's all, if you feel like scavenging from old junk. I rather enjoy tearing things apart, but then, maybe that's just me. :sticktongue:

Your awesome man. Thank you

Link to comment
Share on other sites

So 

13 hours ago, Sputnix said:

Is it because it's showing stage fuel (instead of total fuel)? If so, then it's doing what it's meant to :P:wink: 
If not, and it's jumping to 100%, then jumping back down to the 'correct' amount, that could be an issue with the cycling (ie. between information output, it's getting a false reading of 100%).

I suspect it is doing stage-by-stage by default (since you don't seem to be declaring it specifically; check out this -- 

 

So you were right, I was calculating total fuel instead of stage fuel. I think stage fuel is better as of right now. My reasoning being, it will tell me when to go to the next stage. Although as Im typing this I'm thinking, since I have so many meters to find a use for, to set 2 for total oxidizer and fuel and 2 for stage oxidizer and fuel.  Or something to that regard. I updated the code to reflect these changes and my problem now is this..The way that I calculate the percentage is (stagefuelcurrent / stagefuelmax) * 100 = fuel% = pwmlevel. But when the vessel loads, or I go to a stage with no fuel, I get an error because stagefuelmax becomes zero and you cannot divide by zero. So I'm thinking I need to put some sort of trigger that only calculates the percentage if stagefuelmax > 0. Anyone have a better solution? I can post the code later so that you have a visual of what Im talking about. I wont be able to work on it till a little later so I figured I would ask if anyone had any advice..

Link to comment
Share on other sites

Fantastic idea, enjoyed getting caught up on this thread.

A recommendation, if I may? I only say this because you mention seperate meters for total vessel LF/OX, and yet another set for current stage LF/OX. Sounds amazing, but lacks ambiguity. My suggestion: see if you can reference current fuel being used, no matter the type. This way, should you be playing with modded fuel types, or some oversized ion engine or something, your covered. 

Also, this has reminded me of this gem: http://m.imgur.com/a/sW3Tz

Edited by DrunkenKerbalnaut
Link to comment
Share on other sites

21 minutes ago, DrunkenKerbalnaut said:

Fantastic idea, enjoyed getting caught up on this thread.

A recommendation, if I may? I only say this because you mention seperate meters for total vessel LF/OX, and yet another set for current stage LF/OX. Sounds amazing, but lacks ambiguity. My suggestion: see if you can reference current fuel being used, no matter the type. This way, should you be playing with modded fuel types, or some oversized ion engine or something, your covered. 

Also, this has reminded me of this gem: http://m.imgur.com/a/sW3Tz

To my knowledge you have to call the name of whatever fuel your using. For example vessel.resources.max 'LiquidFuel'. And it would need to be told how to handle multiple fuel sources. I was thinking about getting little led screens, very tiny like a calculator, and using them to label the fuel gauges. I could try to have it detect the fuel types and display them on the screens. Maybe. I have 1 screen I can play around with and try. That way the screens would be statically assigned, instead of dynamically. It would be a little harder to program, but it would save me time trying to set the names of the fuels for each mission.

Also, I wish I knew more people in the seattle/tacoma area that played. Working in a group like that is on my to-do list. I havent lived here long, but  I thought about joining the astronomical society in tacoma. Im bound to meet a few people who play or would be interested.  That looks like a blast. And I love how they used the glass and dry erase. :D Thats awesome. Thanks for sharing

Link to comment
Share on other sites

I belive @DrunkenKerbalnaut is referring to making the markings of the physical meter generic (Resource % or Fuel %). You would then have a switch or button selector that displays the fuel of choice, and an LED maybe that lights up to indicate what type of fuel is currently displayed. With 2 or more meters, you could still do this, but have a selection of resources to display. Since most rockets use Liquid Fuel and Oxidizer as a pair, there's little reason to show both, but you could show, say Liquid Fuel and Solid Fuel on two meters, then in orbit, maybe you switch to using an Ion drive, so then you select the first meter to show Xenon and the second to show Electric Charge.

It'd also give you some meter versatility if you have a toggle switch to select stage vs total (and have the software apply the correct value, where applicable, to the meter). 

Link to comment
Share on other sites

6 hours ago, richfiles said:

-snip-

Actually, THAT would be amazing. And more robust. Maybe a rheostat paired to each gauge, for switching between fuel (EDIT: resource) types? Anyways,  @Kotagi, see what kind of organizations there are at nearby colleges. Bound to be some Kerbals there. 

Edited by DrunkenKerbalnaut
Link to comment
Share on other sites

13 hours ago, Kotagi said:

The way that I calculate the percentage is (stagefuelcurrent / stagefuelmax) * 100 = fuel% = pwmlevel. But when the vessel loads, or I go to a stage with no fuel, I get an error because stagefuelmax becomes zero and you cannot divide by zero. So I'm thinking I need to put some sort of trigger that only calculates the percentage if stagefuelmax > 0. Anyone have a better solution?

I'd probably do a conditional test to see if stageFuelMax == 0. If it is, then don't run the code.

if (stageFuelMax != 0) {
(stagefuelcurrent / stagefuelmax) * 100 = fuel% = pwmlevel;
}
else {
pwmLevel = 0;
}

Or something to that effect :P

I suppose you could do it as a while loop too;

while (stageFuelMax != 0){
// code here
}

This should then only be evaluated when there's stage fuel;

Link to comment
Share on other sites

6 hours ago, Sputnix said:

I'd probably do a conditional test to see if stageFuelMax == 0. If it is, then don't run the code.


if (stageFuelMax != 0) {
(stagefuelcurrent / stagefuelmax) * 100 = fuel% = pwmlevel;
}
else {
pwmLevel = 0;
}

Or something to that effect :P

I suppose you could do it as a while loop too;


while (stageFuelMax != 0){
// code here
}

This should then only be evaluated when there's stage fuel;

Thank you for the examples.. I will try them out here in the next day or 2. Check this out. I built a little testing station to give my buttons stability while I play around with everything. I built it in a couple hours. Im going to paint the outside white. I can add modules to it as I go to test different components before I install everything permanently. I also soldered all the connections and labels everything for ease of use. If I was going to use this permanently I think my only change would be using plexi for the panel so I could make it light up. And yes I know the stickers look like crap..I finished at like 4 in the morning and I was tired.. I am going to redo them.

AM24Gg7.jpg

T11H9la.jpg

Edited by Kotagi
Link to comment
Share on other sites

Just now, Kotagi said:

And yes I know the stickers look like crap..I finished at like 4 in the morning and I was tired.. I am going to redo them.

They don't look crap! They're functional, thus can't be considered as such! :D 
The stickers on my controller (v1) were only meant to be temporary... but then, a lot of people commented that it looked very kerbalish, and I agreed that it worked well with it :) Saved me the pain of trying to do decal transfer (on brushed aluminium no less - I had no idea how I was going to achieve that! ).

Looking very cool for a temporary / 'test bed' solution! :) 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...