Jump to content

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


zitronen

Recommended Posts

It should reengage when you centre the stick? Basically if you are moving the stick manually it overrides SAS, but if you let go SAS take control.

I've also experienced the problem that SAS stops working when using manual input through the mod. SAS is still indicated as active but it stops doing anything until you disable it and reenable it. The problem is only when using input through this mod as both using a regular joystick and emulating a joystick with the arduino works fine. You don't have to toggle SAS using keyboard to make it work again, using serial though the mod also works.

Edited by Antipaten
Link to comment
Share on other sites

OK that was annoying... looks like ActiveVessel.Autopilot.SAS.ManualOverride(false); simply does nothing. The supposedly new pre/on/post autopilot update thing to replace the old stuff also doesn't seem to work. Looks like we are not the only one with the same problem.

So the current solution is to turn SAS on and off automatically, please see if this works: https://sites.google.com/site/zitronfiles/KSPSerialIO_017_5.zip

Link to comment
Share on other sites

Hey guys, trying to get this working on my PC, but it's not picking up any of my Arduinos. I've tried an Uno, a Dumeliavore (or however that one's spelt) and a Due, none of them are working, and it's not finding the "display". Logs look like this:

...
[WRN 16:35:24.296] [HighLogic]: =========================== Scene Change : From SPACECENTER to FLIGHT (Async) =====================
[WRN 16:35:26.647] ApplicationLauncher already exist, destroying this instance
[LOG 16:35:26.655] AddonLoader: Instantiating addon 'NavWaypoint' from assembly 'KSP'
[LOG 16:35:26.661] AddonLoader: Instantiating addon 'KSPSerialPort' from assembly 'KSPSerialIO'
[LOG 16:35:26.665] KSPSerialIO: Version 0.17.3
[LOG 16:35:26.667] KSPSerialIO: Getting serial ports...
[LOG 16:35:26.669] KSPSerialIO: Output packet size: 189/255
[LOG 16:35:26.673] KSPSerialIO: Found 4 serial ports
[LOG 16:35:26.674] KSPSerialIO: trying default port COM20
[LOG 16:35:26.736] Error opening serial port COM20: CreateFile Failed: 2
[LOG 16:35:26.739] KSPSerialIO: trying port \Device\Serial0 - COM1
[LOG 16:35:33.274] KSPSerialIO: KSP Display not found
[LOG 16:35:33.276] KSPSerialIO: trying port \Device\VCP0 - COM20
[LOG 16:35:33.278] Error opening serial port COM20: CreateFile Failed: 2
[LOG 16:35:33.280] KSPSerialIO: trying port \Device\USBSER000 - COM23
[LOG 16:35:33.282] Error opening serial port COM23: CreateFile Failed: 2
[LOG 16:35:33.284] AddonLoader: Instantiating addon 'KSPSerialIO' from assembly 'KSPSerialIO'
[LOG 16:35:33.330] ------------------- initializing flight mode... ------------------
...

COM20 and COM23 are both Arduinos, and both of them have the unmodified Arduino example sketch loaded. COM1 is my hardware RS232 port. Any attempt to connect to an Arduino results in a "CreateFile Failed: 2" error, and the port is never opened as neither of the Arduino's reset or receive data. Not sure why it's found 4 COM ports though, there's only 3 and it only tries 3 (well, 4 since it tries the default one twice. Perhaps that's why it reports 4...). Probably not important.

Running Windows 10 64 bit, latest KSP through Steam (also tried launching outside of Stream with Run as Admin, no luck), fresh/unmodded install except for this one.

It seems Windows 10 has some problems with this mod, any suggestions? Since the only port not failing to open is my hardware port, I might try and find an RS232 to TTL adapter, but I would much prefer the USB COM port to work.


EDIT:

I've made progress. using the default port name "\\.\COM23" I was able to get it connecting to COM23 successfully. Don't ask me why that works, it just does somehow. I read somewhere that that's needed to use COM ports higher than 9, and it worked.

Anyhow, I'm now picking this up:

sVeCtub.png

At the top-left is the handshake packet sent by KSP, to which the Arduino promptly replies to in the packet to the right. This was received 5 seconds after the Arduino was reset with the opening of the COM port, as specified in the config file, even though the Arduino finished booting after around 1 second.

The problem is, there are nothing sent after this, and it seems KSP never receives the response handshake. With the output() method uncommented, the Arduino will hopelessly spam the port with new data packets, but KSP doesn't seem to notice. Eventually KSP times out.

TL;DR: it seems KSP can now send Serial, but not receive it. Normally, this wouldn't bother me at all; I can emulate a keyboard/mouse and simply control KSP like that, watching the response in those status packets. The problem, though, is that KSP is refusing to send those status packets entirely, as all Serial communication stops after that one handshake, presumably because it assumes it's not working.

Can someone please make a version that doesn't rely on handshakes and just endlessly sends status packets instead? Someone posted a win10 fix, but the link's broken and I don't know how to compile it from source. I think just removing handshakes *should* do it, though.

Edited by thatdude624
Link to comment
Share on other sites

Hey guys, trying to get this working on my PC, but it's not picking up any of my Arduinos. I've tried an Uno, a Dumeliavore (or however that one's spelt) and a Due, none of them are working, and it's not finding the "display". Logs look like this:

...
[WRN 16:35:24.296] [HighLogic]: =========================== Scene Change : From SPACECENTER to FLIGHT (Async) =====================
[WRN 16:35:26.647] ApplicationLauncher already exist, destroying this instance
[LOG 16:35:26.655] AddonLoader: Instantiating addon 'NavWaypoint' from assembly 'KSP'
[LOG 16:35:26.661] AddonLoader: Instantiating addon 'KSPSerialPort' from assembly 'KSPSerialIO'
[LOG 16:35:26.665] KSPSerialIO: Version 0.17.3
[LOG 16:35:26.667] KSPSerialIO: Getting serial ports...
[LOG 16:35:26.669] KSPSerialIO: Output packet size: 189/255
[LOG 16:35:26.673] KSPSerialIO: Found 4 serial ports
[LOG 16:35:26.674] KSPSerialIO: trying default port COM20
[LOG 16:35:26.736] Error opening serial port COM20: CreateFile Failed: 2
[LOG 16:35:26.739] KSPSerialIO: trying port \Device\Serial0 - COM1
[LOG 16:35:33.274] KSPSerialIO: KSP Display not found
[LOG 16:35:33.276] KSPSerialIO: trying port \Device\VCP0 - COM20
[LOG 16:35:33.278] Error opening serial port COM20: CreateFile Failed: 2
[LOG 16:35:33.280] KSPSerialIO: trying port \Device\USBSER000 - COM23
[LOG 16:35:33.282] Error opening serial port COM23: CreateFile Failed: 2
[LOG 16:35:33.284] AddonLoader: Instantiating addon 'KSPSerialIO' from assembly 'KSPSerialIO'
[LOG 16:35:33.330] ------------------- initializing flight mode... ------------------
...

COM20 and COM23 are both Arduinos, and both of them have the unmodified Arduino example sketch loaded. COM1 is my hardware RS232 port. Any attempt to connect to an Arduino results in a "CreateFile Failed: 2" error, and the port is never opened as neither of the Arduino's reset or receive data. Not sure why it's found 4 COM ports though, there's only 3 and it only tries 3 (well, 4 since it tries the default one twice. Perhaps that's why it reports 4...). Probably not important.

Running Windows 10 64 bit, latest KSP through Steam (also tried launching outside of Stream with Run as Admin, no luck), fresh/unmodded install except for this one.

It seems Windows 10 has some problems with this mod, any suggestions? Since the only port not failing to open is my hardware port, I might try and find an RS232 to TTL adapter, but I would much prefer the USB COM port to work.


EDIT:

I've made progress. using the default port name "\\.\COM23" I was able to get it connecting to COM23 successfully. Don't ask me why that works, it just does somehow. I read somewhere that that's needed to use COM ports higher than 9, and it worked.

Anyhow, I'm now picking this up:

http://i.imgur.com/sVeCtub.png

At the top-left is the handshake packet sent by KSP, to which the Arduino promptly replies to in the packet to the right. This was received 5 seconds after the Arduino was reset with the opening of the COM port, as specified in the config file, even though the Arduino finished booting after around 1 second.

The problem is, there are nothing sent after this, and it seems KSP never receives the response handshake. With the output() method uncommented, the Arduino will hopelessly spam the port with new data packets, but KSP doesn't seem to notice. Eventually KSP times out.

TL;DR: it seems KSP can now send Serial, but not receive it. Normally, this wouldn't bother me at all; I can emulate a keyboard/mouse and simply control KSP like that, watching the response in those status packets. The problem, though, is that KSP is refusing to send those status packets entirely, as all Serial communication stops after that one handshake, presumably because it assumes it's not working.

Can someone please make a version that doesn't rely on handshakes and just endlessly sends status packets instead? Someone posted a win10 fix, but the link's broken and I don't know how to compile it from source. I think just removing handshakes *should* do it, though.

Another option is to simply change your port number from 23 to 8 or something.

Yes there is currently a problem with windows 10, the serial received event is not firing. I have no idea why, I don't think there's a proper fix, people tried polling instead of events, but it has performance problems. It wouldn't be too difficult to add an option for "win 10 mode" which only sends packets, but I don't have win 10 to test.

Link to comment
Share on other sites

Another option is to simply change your port number from 23 to 8 or something.

Yes there is currently a problem with windows 10, the serial received event is not firing. I have no idea why, I don't think there's a proper fix, people tried polling instead of events, but it has performance problems. It wouldn't be too difficult to add an option for "win 10 mode" which only sends packets, but I don't have win 10 to test.

I do, I can help! :D

I downloaded Visual Studio and tried to edit the mod's EventCallDirectly(), which seems to be responsible for Serial receiving. I commented out everything and instead wrote "DisplayFound = true;//assume it worked", so it would succeed opening the first port it finds (the default port, which I know is the right one).

Unfortunately, compiling isn't going so well. Or rather, it compiles, but KSP doesn't like it:

[ERR 20:58:30.438] AssemblyLoader: Exception loading 'KSPSerialIO': System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
at AssemblyLoader.LoadAssemblies () [0x00000] in <filename unknown>:0

Additional information about this exception:

System.TypeLoadException: Could not load type 'KSPSerialIO.KSPSerialPort' from assembly 'KSPSerialIO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

I've never used C# before, much less for Unity mod development, and honestly I'm surprised my attempt got this far. Perhaps it's because of how I tried to link the DLLs...

I've seen a lot of mods use networking to send data in/out of KSP. I know that Serial works in Java, so I could perhaps write a network to COM port app that runs in the background for Windows 10. Though adding networking is probably no simple task.

...Honestly, I'd be happy with just Serial output from KSP for Win10 to work for my project :)

Link to comment
Share on other sites

Got the panels laser cut and painted today. Happy with how they came out, but I will need to cut the upper one again. Parts are interfering on the backside of the panel.

http://i62.tinypic.com/2rrt24z.jpg

Thats awesome! I have a question for you though: Where did you get those white buttons? I wanted those for my project, but I couldn't find them cheap enough! I ended up having to go with toggle switches, but I made it so I can upgrade to those later.

Link to comment
Share on other sites

I've never used C# before, much less for Unity mod development, and honestly I'm surprised my attempt got this far. Perhaps it's because of how I tried to link the DLLs...

Close - that looks like what happens if you're targeting the wrong .NET version. Have a look ata http://wiki.kerbalspaceprogram.com/wiki/Setting_up_Visual_Studio to make sure you've got VS set up for building plugins properly.

You might also like to try the modified plugin I've been maintaining at http://forum.kerbalspaceprogram.com/threads/68642-Arduino-Addon-for-Mac/page9 , which polls the serial port instead of using Unity event handlers. It works for me, but I pretty much stopped testing on Windows 10 when I realised it seems to run better for me in Linux. :/

Link to comment
Share on other sites

Close - that looks like what happens if you're targeting the wrong .NET version. Have a look ata http://wiki.kerbalspaceprogram.com/wiki/Setting_up_Visual_Studio to make sure you've got VS set up for building plugins properly.

You might also like to try the modified plugin I've been maintaining at http://forum.kerbalspaceprogram.com/threads/68642-Arduino-Addon-for-Mac/page9 , which polls the serial port instead of using Unity event handlers. It works for me, but I pretty much stopped testing on Windows 10 when I realised it seems to run better for me in Linux. :/

Couldn't get your one working. COM23 couldn't open "acess denied" and the weird \\.\COM23 trick didn't work, and defaulted to COM1, which made it lag beyond measure on the simplest ship. I can't make it a COM port below 10 because I don't have much of a say in what port numbers Windows decides to allocate. It's the result of using many Arduino's/Serial adaptors on many USB ports.

I've only got Windows 10 on here, unfortunately. I should perhaps try and install Linux Mint alongside windows, but it seems a bit overkill to just use it for KSP.

As for building it myself, it's now complaining that the provided SerialPort.dll is built for version 4.5 for some reason. It compiles without that reference, but now it's throwing an exception with the name "value", seemingly on the line "Port.PortName = PortNumber;". I'm not sure, but I'd guess this is a sort of NullPointerException? At least KSP's loading the mod now.

Link to comment
Share on other sites

Hurrah, I got it working! I modified the library to send messages to a local TCP port to a Java program which is in charge of Serial data handling! Right now, the Java server simply sends all incoming TCP bytes through to the Serial port, but I could easily make it work the other way around. In theory, anyway.

Now the problem is the Arduino code isn't properly parsing the incoming packets, and the packets aren't even the same size. I'll write my own Arduino packet parser later.

With the data going into Java, there's also a possibility of making a second monitor with aircraft instruments that you could never afford to get working with an Arduino, but I'll start with just a custom controller.

Thanks for the help!

Link to comment
Share on other sites

Hurrah, I got it working! I modified the library to send messages to a local TCP port to a Java program which is in charge of Serial data handling! Right now, the Java server simply sends all incoming TCP bytes through to the Serial port, but I could easily make it work the other way around. In theory, anyway.

Now the problem is the Arduino code isn't properly parsing the incoming packets, and the packets aren't even the same size. I'll write my own Arduino packet parser later.

With the data going into Java, there's also a possibility of making a second monitor with aircraft instruments that you could never afford to get working with an Arduino, but I'll start with just a custom controller.

Thanks for the help!

That's not a bad solution!

You might be having structure data packing issues if the packets are the wrong size. In C#, structlayout attribute is needed to pack things properly, I don't no what is the equivalent in Java.

Also has anyone with axes and SAS problems tried the latest plugin update?

Link to comment
Share on other sites

Hi.

I loaded some examples, but I can't get it to work.

I checked the connection-status. And the board only seems to be connected while the scene change from the VAB to the Launchpad.

Someone has an idea?

Would be great.

Link to comment
Share on other sites

Hi.

I loaded some examples, but I can't get it to work.

I checked the connection-status. And the board only seems to be connected while the scene change from the VAB to the Launchpad.

Someone has an idea?

Would be great.

That's how it's supposed to work? It should only connect when you launch.

Link to comment
Share on other sites

Yes.

I think your example code should connect after launch.

But it doesn't. It's only connected during the scene change.

Are you using windows 10 by any chance?

- - - Updated - - -

Hey I had an idea, for people having issues on windows 10, has anyone tried running ksp as admin or tried any of the compatibility modes?

Link to comment
Share on other sites

I'm currently having a problem.

What I'm using doesn't allow you to define something as a byte. So I am using char.

When checking rx_len with structSize for VData, rx_len comes out as 189 while structSize ends up as 192.

So I used your struct for VData except I changed:

char id; //1 TK was byte

...

char SOINumber; //47 SOI Number (decimal format: sun-planet-moon e.g. 130 = kerbin, 131 = mun) TK was byte char MaxOverHeat; //48 Max part overheat (% percent) TK was byte

Do you know why I'm getting a mismatch between rx_len and structSize?

Link to comment
Share on other sites

I'm currently having a problem.

What I'm using doesn't allow you to define something as a byte. So I am using char.

When checking rx_len with structSize for VData, rx_len comes out as 189 while structSize ends up as 192.

So I used your struct for VData except I changed:

char id; //1 TK was byte

...

char SOINumber; //47 SOI Number (decimal format: sun-planet-moon e.g. 130 = kerbin, 131 = mun) TK was byte char MaxOverHeat; //48 Max part overheat (% percent) TK was byte

Do you know why I'm getting a mismatch between rx_len and structSize?

Sounds like a struct packing issue? http://www.catb.org/esr/structure-packing/

Link to comment
Share on other sites

Last week I started working on drawing a navball on a little 5" display to add to my controller. That's coming along nicely, but of course it wouldn't be complete without orbital vectors. Long story short, I picked up some help from this old thread, and am now calculating pitch and heading for orbital prograde, normal and radial vectors. I'll add surface prograde and maneuver nodes soon.

It's still a work in progress, and I'm only mostly certain I've got the right reference frames for everything. But it looks like it's working. The problem is that it will add another ten floats to the VesselData struct. If it's a worthwhile use of 40 bytes then I'll open a PR for it as soon as I get it polished off in the next few days.

My branch with this stuff is at https://github.com/phardy/KSPSerialIO/tree/zitronen-orbitalvectors

The navball I'm building is also in a pretty rough state, but looks awesome:

Link to comment
Share on other sites

Looking absolutely sweet, Stibbons.

My own controller is in a state of parts all over a shelf in my workshop. Got caught up by latex weapons and trying to bash out a helmet of sheet steel for my daughters' LARP'ing, and the weather does not permit soldering with open windows. While trying to figure out why my controller did not react to KSPSerialIO at all I decided to add a trackball to the box, as well as getting a couple of proper joysticks. So right now I wait for the weapons to get done so I can allow myself heat out there again, and bring together a test board for ver 17.5

Link to comment
Share on other sites

Wait is that a teensy? What kind of magic you are using to 3D graphics on it?

I'm happy with adding the the velocity vectors (especially if someone else does all the work :D), but I think since most people are only going to be using them to draw something, I don't think they need to be full 32bit floats, some kind of fix precision thing with 2 bytes should do? I presume you are sending them as three angles or vector components or something?

***

Also since many people are having issues with windows 10, I will try to and a config option to disable the handshake, and have it just simply send out the vessel data.

Link to comment
Share on other sites

That is indeed a teensy. I did have a first iteration running on a Uno, but that struggled to do more than 10fps. I'd be nervous about how well it would handle actually receiving and processing data at the same time. The teensy was flying. I cranked that demo up to 40fps and it didn't seem to be lagging at all. The navball is a 3d model exported from blender, and I adapted this project to run on my display and controller. Pretty simple, really. :)

Only two numbers: relative pitch and yaw from the current vessel attitude. That's all you need to navigate to one of them. It's definitely all I need to rotate the appropriate marker on my navball to the right place. I'll eventually be using fixed-point numbers pretty much everywhere in my arduino code, but would be a little hesitant to send prograde pitch and yaw in a different format to vessel pitch and yaw. But then, I'd be even more hesitant to change existing packet data to match. :) At the end of the day I'm happy to go with what you'd prefer.

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