Sign in to follow this  
alphafalcon

Possibilities? - Telemetry over Network

Recommended Posts

As this seems the most appropriate place for coding-related questions ill put this here:

What kind of in-game data can a module access? I\'ve seen the Solar Panels which communicate with batteries somehow, but can a module know about(or even alter) orbital parameters like which body it is orbiting, orbital velocity, eccentricity and so on.

I\'m wondering wether a 'telemetry downlink' module would be possible, which would collect data ingame and serve it on the loopback interface so our favourite orbit calculator can read it and display more detailled orbit stats or even aid in transfer maneuvers.

Hope to hear something encouraging from you code-divers.

alphafalcon out. ;)

Edit: Changed title to reflect discussion

Share this post


Link to post
Share on other sites

Yes all that data is readibly avalible. I almost wish they made the default hud display these values as the are very useful and simply just need to be displayed to the user. Someone could very easily make this data visible to the user through a module.

Share this post


Link to post
Share on other sites

i think any game value can be used, like altitude, fuel left in a fuel tank, engine active or not, coordinates... and i seen than nova is maybe planning a module to control a craft from a command line, so why not telemetry ? But you\'ll have to parameter that orbit calculator to read this telemetry data, and i don\'t see how to do this.

Share this post


Link to post
Share on other sites

Unlimited. It can also destroy your pc if the addon makers wants that.

That is clearly easier than getting orbital data, if KSP doesnt provide it somehow.

But you\'ll have to parameter that orbit calculator to read this telemetry data, and i don\'t see how to do this.

I\'m not quite sure I understand you correctly, but I believe you want to know how to get the data to the orbit calculator:

I\'m thinking of sending it over the loopback network interface.

Share this post


Link to post
Share on other sites

Freaking Kerbin sized flying dinosaur dragons with lazer eyes and nuclear eggs. 8)

Edit:

I want to make some kind of 'targeting' system. So that you can launch missiles on your satellites (or Kerman\'s).

Share this post


Link to post
Share on other sites

Lol, I should be learning C# instead of C++... :-X

Don\'t worry. Once you learn one, picking up the other isn\'t hard.

Share this post


Link to post
Share on other sites

there are no limits on what plugins can do currently ( and i mean this quite literally, you can have addons that destroy your PC if you want ), which is part of the problem why squad is reluctant to give an official green light on the whole ordeal, or that\'s atleast what i think

Share this post


Link to post
Share on other sites

So I decided to break out SharpDevelop and have a look myself... Holy Cow, the possibilities :o

This little bit

	public class TelemetrySensor : Part
{
protected override void onActiveUpdate()
{
base.onActiveUpdate();
print('flight state:');
print(this.vessel.altitude);
print(this.vessel.orbit.eccentricity);
}
}

already spews useful info into the debug log. Now I just need to find all relevant parameters, pipe that into a network socket and the orbit calculator guys can have a go at it. 8)

Share this post


Link to post
Share on other sites

So I decided to break out SharpDevelop and have a look myself... Holy Cow, the possibilities :o

This little bit

	public class TelemetrySensor : Part
{
protected override void onActiveUpdate()
{
base.onActiveUpdate();
print('flight state:');
print(this.vessel.altitude);
print(this.vessel.orbit.eccentricity);
}
}

already spews useful info into the debug log. Now I just need to find all relevant parameters, pipe that into a network socket and the orbit calculator guys can have a go at it. 8)

You can make simple digital gauge by putting a .SetMessage in onPartFixedUpdate()


private VInfoBox _pressure;
_pressure.SetMessage('Pressure : ' + Convert.ToString(this.staticPressureAtm));

I\'m going to see I can get a relative inclination gauge working tonight. :)

Share this post


Link to post
Share on other sites

So I decided to break out SharpDevelop and have a look myself... Holy Cow, the possibilities :o

This little bit

	public class TelemetrySensor : Part
{
protected override void onActiveUpdate()
{
base.onActiveUpdate();
print('flight state:');
print(this.vessel.altitude);
print(this.vessel.orbit.eccentricity);
}
}

already spews useful info into the debug log. Now I just need to find all relevant parameters, pipe that into a network socket and the orbit calculator guys can have a go at it. 8)

I am Warringer and I approve of this message and/or service.

Share this post


Link to post
Share on other sites

Okay, I\'m stuck.

This works, but just once.

If you compile this, put a part on your ship and launch it, you can connect to port 50000 and receive lots of 'hello's.

If you 'End Flight', launch the same ship again, the connect fails. I think i need some kind of cleanup, to close the connection and reinitialize the Listener, but I\'ve got no idea where to put it. Tried OnPartDelete, but didn\'t do the trick...

Suggestions?

Also, I\'m kinda new to C#, so please excuse glaring stupidities, if there are. Someone get me python bindings ;P

using System.Net;
using System.Net.Sockets;



/// <summary>
/// Description of MyClass.
/// </summary>
///
public class TelemetrySensor : Part
{
private TcpListener _listen;
private TcpClient _client;


protected override void onPartUpdate()
{
if (_listen == null) {
_listen = new TcpListener(IPAddress.Parse('127.0.0.1'),50000);
_listen.Start();
}
if (_listen.Pending()) {
_client = _listen.AcceptTcpClient();
}
if (_client.Connected) {
byte[] msg = System.Text.Encoding.ASCII.GetBytes('Hello\r\n');
_client.GetStream().Write(msg,0,msg.Length);
_client.GetStream().Flush();

}

}
}

Share this post


Link to post
Share on other sites

I\'d be tempted to use broadcast UDP for telemetry data, if the C# network APIs allow that. Then you don\'t need to worry about connecting, disconnecting, etc. You just have your 'Groundstation' or whatever open a UDP broadcast socket for listening and it\'ll receive all your telemetry from all active instances of your module... can modules discover what ship they\'re attached to and get the name or a unique ID of some sort?

Share this post


Link to post
Share on other sites

Better use UDP for telemetry. That way you don\'t have to implement any code for the possibility that there is no one listening.

UDP doesn\'t care if someone is listening.

Share this post


Link to post
Share on other sites

Got TCP running, thanks to some help r4m0n.

Now I\'ll have to think about what to send over the line. Warringer, what data would you need for your calculator?

UDP seems more suited to the task, now you mention it. Will have to try that sometime, I\'m not that familiar with UDP.

Quinton, yeah theres a way to semi-reliably identify a ship: this.vessel.vesselName has the Major Drawback that most of my Ships are called 'Untitled Spacecraft' atm.

Share this post


Link to post
Share on other sites

If you are using UDP you need to create your own method to ensure there was no data loss, as well as to ensure the order of the message. Otherwise if you get an old packet but already received a new one and you aren\'t checking the order than your data will be unreliable.

Share this post


Link to post
Share on other sites

For other programs on the same host, unless you\'re completely spamming the network stack, UDP will tend to be both reliable and in-order. Non-congested switched ethernet and wifi are pretty reliable too, but dropped packets can happen.

If you keep one telemetry message per packet and give them a sequence number or timestamp, it\'s not hard for your groundstation to sort them on arrival if necessary.

Last time I used UDP for telemetry was on an autonomous vehicle for the 2005 DARPA Grand Challenge -- entirely too much fun even though we didn\'t put anything in orbit.

alphafalcon: I\'m still getting up to speed on C#, but I suspect that like Java you can get some kind of unique hashcode or ID for an object -- so if you sent both the name and the ID of this.vessel, you\'d be able to disambiguate if necessary.

Share this post


Link to post
Share on other sites

Quinton, yeah theres a way to semi-reliably identify a ship: this.vessel.vesselName has the Major Drawback that most of my Ships are called 'Untitled Spacecraft' atm.

FlightGlobals.vessels is a list of all vessels in the scene.

I\'ve been paging through it with a for loop and saving the index number of the ship I\'m interested in.

So if you wanted the index of the current active vessel...


for (int i = 0; i < FlightGlobals.Vessels.Count; i++){
if (FlightGlobals.Vessels[i] == this.vessel){
selVessel = i;
}
}

Share this post


Link to post
Share on other sites

Got TCP running, thanks to some help r4m0n.

Now I\'ll have to think about what to send over the line. Warringer, what data would you need for your calculator?

UDP seems more suited to the task, now you mention it. Will have to try that sometime, I\'m not that familiar with UDP.

Quinton, yeah theres a way to semi-reliably identify a ship: this.vessel.vesselName has the Major Drawback that most of my Ships are called 'Untitled Spacecraft' atm.

Well... I would try to make a new Telemetry Reader Program anyway.

Best would be to just dump every bit of available information of the craft into the network, as long as its in machine/human readable form. And as long as there is documentation for the available data.

Anyway, I once again note that I\'d prefer UDP. And you can always read up on UDP. :P

If UDP is used to make sure you got the correct package is easy. Include a timestamp. :P

Share this post


Link to post
Share on other sites

And as long as there is documentation for the available data.

So none of it :P

Share this post


Link to post
Share on other sites

The potential for a mobile/multiplayer P2P version of KSP is here in this plugin. MUDs used to do something like this back in the day for cross-system connects.

This is a really rough idea of implementation. Rough.

KSP Multiplayer Module:

A part which when attached to a ship:

1/Second as connection permits, updates the locations and parameters of all vessels and parts.

10/Second updates the status of all parts on the currently focused vessel.

TX behavior might have to be adjusted to keep the connection from being saturated.

If module can remain active even when 'packed', then you only need one. If it does\'t remain active when packed then you need a part for every focuasable ship, along with an 'is_focused' flag. If Alice leaves a focuseable tagged ship, then the M/P updates stop happening, as if Alice went offline. An online/offline message must be transmitted to all connections. All of Bob\'s spawned ships are now on rails. When Alice reconnects, Bob\'s ships are updated/teleport to their current locations.

The code must be smart enough to only transmit one set of updates, no matter how many copies of the part exist in the world.

You would need a local 'receiver' module to update all parts when it RXs updates. The same limitations above apply to the RX behavior as to the TX behavior. There should only be one per player active.

The M/P module must be able to spawn non-existent ships and debris in their locations and orientations. It appends the name of the ship with the name of the player to make 'ownership'. Perhaps a UID would need to be appended to the end of the ship name to prevent collisions. The name would look something like this: {ALICE-'SHIPNAME'-UID} The name would be parsed internally by the plugin and mapped to the appropriate ship.

What stops a player (ALICE) from screwing with another player\'s (BOB) ships? Nothing. Two copies of a ship actually exist, one locally on ALICE, and one on BOB. When a player switches to another ship not owned by her, it can diverge and a new ship is spawned. Possibly colliding with {BOB-'SHIPNAME'-SAMEUID} because the ships are in the same location. Comedy ensues!

What keeps time in step? I don\'t know. ALICE and BOB will definitely use warp. On one level, it really doesn\'t matter. The plugin doesn\'t care. The updates will still happen at the same pace. When ALICE uses warp, it will appear to BOB as if ALICE\'s ships have teleported in. Perhaps the module would need to do bookeeping to force the position to update. Perhaps a 'ALICE_isWARPING' tag must be TX\'d along with 'ALICE_WARPRATE' and 'ALICE_GAMETIME'...

Negative warp-rates may be required to keep in sync due to the significant latency in the connection. This one is a stickler.

Perhaps the module must TX to a local cache which keeps a record of all transactions and interpolates between positions. If Harvester is developing some 'universal' time system, with fast forward and rewind, it might not be hard to implement. He\'d have to essentially do that for every transaction node.

What about security? What security?

Share this post


Link to post
Share on other sites

Currently, r4m0n of MechJeb fame and myself are working on adding a utility that will run on a second PC and connect via TCP/IP over your LAN to the game and display a host of telemetry data like what the plugin currently displays in the game window.

He\'s doing all the heavy lifting. I\'m just creating kerbalish graphics for the screen. Think old school 1960s NASA control panles and output.

Cheers!

Capt\'n Skunky

KSP Community Manager

Share this post


Link to post
Share on other sites

What stops a player (ALICE) from screwing with another player\'s (BOB) ships? Nothing. Two copies of a ship actually exist, one locally on ALICE, and one on BOB. When a player switches to another ship not owned by her, it can diverge and a new ship is spawned. Possibly colliding with {BOB-'SHIPNAME'-SAMEUID} because the ships are in the same location. Comedy ensues!

I\'d be happy even if there were a \'once per day\' broadcast of my mates ships into my own persistence file. Sure - that\'s not realtime and its not really multiplayer but if I logged on daily and the world around me was changing due to the activities of my mates then it would appear to be a living universe. This would be neat and an interesting first step.

I\'d start a new persistence file and put a habitat module on the Mun. I broadcast this to my mate either manually or via automatic intervals and when he gets home and logs on he\'ll see my moonbase \'appear\'. That\'s cool. He can then add to this and broadcast that back to me. I wouldn\'t be able to use or interact with his craft as the next time he broadcasts they will almost definately have moved or been destroyed or added to (ie docking) but the idea of the universe growing whilst I\'m \'offline\' is pretty neat. Careful naming/renaming of ship names would make it easy to know which ships need to be updated during a broadcast.

Share this post


Link to post
Share on other sites

Currently, r4m0n of MechJeb fame and myself are working on adding a utility that will run on a second PC and connect via TCP/IP over your LAN to the game and display a host of telemetry data like what the plugin currently displays in the game window.

He\'s doing all the heavy lifting. I\'m just creating kerbalish graphics for the screen. Think old school 1960s NASA control panles and output.

Cheers!

Capt\'n Skunky

KSP Community Manager

Ohhhhh...

Can\'t wait for it. :D

Even better, make a console version. ;)

Share this post


Link to post
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.

Sign in to follow this