Jump to content

[Hardware, Plugin] Arduino based physical display + serial port io+ tutorial (24-11-19)


zitronen

Recommended Posts

If I send both the amount and the in game delta time then it should be fairly easy to calculate it in arduino. So for each resource we need to send the max and current amount as floats, so 8 bytes per resource.

Another alternative is to put all the resource stuff in a separate packet that is sent less frequently. Either way, right now we still have lots of space in the packet so it shouldn't be a huge issue.

Link to comment
Share on other sites

You would have to use the in game MET clock to calculate... not real time. Real time would be very inaccurate as KSP speeds up and slows down according to graphics and memory load. Sometimes 1 in game second can last up to 5 real seconds.

I didn't think about that... Hmmm, when time is no longer constant... Sounds like relativity, except that you are correct in that this cannot be accurately calculated from outside the game.

Anyways, now that we have control groups, I am already really happy with where it is at! Individual resource outputs (just Max and Present of each resource type would be sufficient) would be cool to have rather than the pure percentage. If by "axes" that you are working on, you mean Current ship Axes and not "input axes", then that would be a pretty awesome addition.

Unfortunately, I still think that resource consumption rate is kind of niche, but if you can find out how to do it, it would have its uses (Ex: calculating burn time remaining).

Link to comment
Share on other sites

I still think that resource consumption rate is kind of niche, but if you can find out how to do it, it would have its uses

With fuel consumption thats true, but knowing if your battery is draining or charging is essential and you can't always tell by just looking at a battery level dial as it may be moving very, very slowly (I'm using dials not digital displays). Thats why steam gauges includes charge/drain as well as current power level.

Might be worth looking at their code for hints on how the data is handled.

http://forum.kerbalspaceprogram.com/threads/40730-0-22-SteamGauges-Release-V1-3-1

This mod also tracks consumption - http://forum.kerbalspaceprogram.com/threads/50077-0-23-Fusebox-electric-charge-tracker-and-build-helper-0-9-released-01-03-14

Link to comment
Share on other sites

Chaosratt, you beat me too it. I was just about to post the same question. My son is always nose to the screen trying to read the 'time to next maneuver'.

Random thought on another variable/data to pull down that I do not see on the first page's table. Time and/or distance to the next maneuver node.
Link to comment
Share on other sites

"Weekly" update 7

Added:

Altitude above sea level

LiquidFuelTotal

LiquidFuel

OxidizerTotal

Oxidizer

EChargeTotal

ECharge

MonoPropTotal

MonoProp

IntakeAirTotal

IntakeAir

SolidFuelTotal

SolidFuel

XenonGasTotal

XenonGas

Plugin and updated code:

https://sites.google.com/site/zitronfiles/KSPSerialIO_013_5.zip

https://sites.google.com/site/zitronfiles/KSPIODemo3.zip

Note: the output data structure has changed, you need to update your arduino structure to be compatible. You will also need to compute your own resource percentages, "FuelP" is replaced by "Alt".

Link to comment
Share on other sites

So if I understand correctly analogWrite(PWMPin, round(fuelp*100/255)) no longer works unless I add another bit of code to determine that fuelp=LiquidFuel/LiquidFuelTotalX100

Of course you know what I'm going to say next :D.... what would the code look like for this?

Link to comment
Share on other sites

Just do analogWrite(PWMPin, round(LiquidFuel/LiquidFuelTotal*255))

You will need to check for when LiquidFuelTotal = 0, i.e. when you don't have any liquid fuel tanks, so you don't end up with divide by zero.

So:

if (LiquidFuelTotal != 0)

analogWrite(PWMPin, round(LiquidFuel/LiquidFuelTotal*255));

else

analogWrite(PWMPin, 0);

Link to comment
Share on other sites

Ok, next noob problem.

I've added a definition for my monopropellant pin, and set the pin as an output under void controlsInit

I'm trying to add the following... I've tried putting it under void controls and void indicators with no luck.

if (MonoPropTot != 0)

analogWrite(MONOPIN, round(MonoProp/MonoPropTot*255));

else

analogWrite(MONOPIN, 0);

But I'm just getting errors thrown back that MonoProp is not defined. What am I missing? With the previous version I could just add in the lines for the fuel gauge and it worked... I didn't have to define anything additional.

Link to comment
Share on other sites

great, got the code working... sadly I can't get these gauges to accurately display though. For some reason the needle moves really slowly in the upper part and gets faster the closer it moves towards zero. So 0-50% takes up most of the gauge and 50-100% only takes a few millimeters. I'm sure there is some clever maths I could use to even it out but no idea what!

Link to comment
Share on other sites

I don't think it is a problem with the Arduino. I don't know where the gauges came from, but it is probably that the gauges were not made to be driven by a linear voltage source.

I would suggest just going by trial and error. Try putting different analog tests out to it (just try regular analog outputs from the min to the max) and see where they line up on the gauge. Then either see if there is some sort of a fit line for them (Wolfram Alpha will probably let you put in points and try a line of best fit) or else just set specific ranges to attach to points and do a series of "if .. then, else ..." to set the gauge to specific values.

Link to comment
Share on other sites

Yeah, I wired it up to a voltmeter with a 5k resistor and it works fine, just these gauges. They are from a 1970s car so presumably 12v although 5v gets the needle almost to the top. They only have coils, no resistors. Not sure yet if I will keep fighting them or just replace them with modern 5v gauges (I'll keep the case though)... I may even be able to keep the dial faces which are quite nice.

Link to comment
Share on other sites

So they are current gauges? Maybe try different series resistor values? Have you checked how much current is being drawn? Maybe it's non-linear because you are trying to draw too much current from the pins (20mA max).

Link to comment
Share on other sites

Just picked up so signal meters that I'll wire up with some 5v resistors and sit behind the existing dial faces... mush easier!

Now... what am I doing wrong here?

I have an RCS switch and two leds... the idea is that when the switch is on and there is monopropellant in the tank then the green led is on... if the switch is on but the tank is empty the red led is on instead.

But it doesn't work. It uploads ok without errors, the RCS is turning on correctly, but the lights just don't turn on (I've tested them and they are fine).

if (digitalRead(RCSPIN))

MainControls(RCS, LOW);

else

MainControls(RCS, HIGH);

if ((RCS == HIGH) && (VData.MonoProp <=1))

digitalWrite(RCSWARNLED, HIGH);

else

digitalWrite(RCSWARNLED, LOW);

if ((RCS == HIGH) && (VData.MonoProp >1))

digitalWrite(RCSLED, HIGH);

else

digitalWrite(RCSLED, LOW);

I have defined RCSLED and RCSWARNLED as outputs.

Link to comment
Share on other sites

What is this supposed to do: (RCS == HIGH) ?

"RCS" is defined as 6, in the first tab you should see "#define RCS 6", so if you see "RCS" anywhere in the code just think "6". Since 6 will never equal to HIGH (1) that won't work.

Link to comment
Share on other sites

Hmm... I tried all sorts of other things like...

if ((digitalRead(RCSPIN)) && (VData.MonoProp >1))

or..

if ((RCSPIN == HIGH) && (VData.MonoProp >1))

but nothing is working.

Basically in English the function I want is...

If the RCS system is switched on AND there is monopropellant on the ship

Then turn the green LED on

Else

Turn the green LED off

Link to comment
Share on other sites

(RCSPIN == HIGH) will never work, RCSPIN is just a number you assigned.

does this not work?

if (digitalRead(RCSPIN))

digitalWrite(RCSLED, HIGH);

else

digitalWrite(RCSLED, LOW);

That doesn't do what I want, it would just turn the light on whenever the RCS is turned on...

I want the light to only turn on when the RCS is on AND there is some monopropellant in the tank.

Link to comment
Share on other sites

Never mind, I've cracked it!

I had forgotten about the ON/OFF state of the switch actually being reversed.

So this works perfectly :)

if (digitalRead(RCSPIN))

MainControls(RCS, LOW);

else

MainControls(RCS, HIGH);

if (!(digitalRead(RCSPIN)) && (VData.MonoProp >1))

digitalWrite(RCSLED, HIGH);

else

digitalWrite(RCSLED, LOW);

if (!(digitalRead(RCSPIN)) && (VData.MonoProp <=1))

digitalWrite(RCSWARNLED, HIGH);

else

digitalWrite(RCSWARNLED, LOW);

Now there is always a light on when the RCS is switched on, but it changes from green to red when the monoprop runs out :)

Edited by Mulbin
Link to comment
Share on other sites

"Weekly" update 8: 0.14.1

Axes! Currently Only throttle, will add others later. You will need to go to settings file and set ThrottleEnable to 1, by default throttle is not enabled. Once throttle is enabled you will lose the ability to control it with keyboard. Connect a pot to an analog input pin 0 and that's it (see arduino.cc/en/Tutorial/ReadAnalogVoltage).

Plugin:

https://sites.google.com/site/zitronfiles/KSPSerialIO_014_1.zip

Arduino:

https://sites.google.com/site/zitronfiles/KSPIODemo4.zip

Once this has been tested I will add more axes and update the first post.

Edit: Unfortunately I'm away to Germany next week, will not be able to answer questions.

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...