Jump to content

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


zitronen

Recommended Posts

1 hour ago, zitronen said:

Wait your inputs (switches, throttle) are also working or are you only using output from the plugin?

Yes, switches work, I haven't added the throttle yet, waiting on my slide pot to arrive tomorrow and will report back, but I have no doubts it will work.

What is strange to me is that my Uno doesn't work, but the Mega does....

Link to comment
Share on other sites

12 hours ago, zitronen said:

What? I don't even...

Maybe it's something to do with the usb-serial driver? I can't test anything because I don't have windows 10, so annoying.

EDIT: Yes, throttle does work!

I believe it is the windows usb-serial driver. I built a small winforms app that uses System.IO.Ports, it simply sends the handshake packet, the Mega responds, the Uno doesn't; so it has the exact behavior as the.wrapper you are using. I've verified that my Uno does work on Win7, so that really points towards the windows driver as well; however it seems really odd that the Arduino IDE is able to work with the Uno on Win 10 if it is the driver tho.

I know you've put alot of time and effort into this project already, I'm not asking you to dive back in and attempt to fix this; just passing along what I thought might be useful.

Thank you for sharing your work.

Edited by KingLuxor
Added words, & magic
Link to comment
Share on other sites

OK well I don't know what's going on. Both the uno and mega use the same chip (16u2) for usb-serial, so should use the same driver. If anyone else can confirm the mega is working that would be great.

I'm pretty sure the official .net serial stuff work just fine on win 10. If it wasn't there would be a huge number of people complaining. The .net code itself might be old but the lower level drivers probably all changed.

Edited by zitronen
Link to comment
Share on other sites

6 hours ago, Freshmeat said:

Are the Uno and Mega originals? I seem to recall that some of the copies used another IC for USB or something like that?

Both of mine are knock offs, the Uno is using an Atmel Mega8u2 (Arduino driver) , the Mega is using a WH 340G (driver from wch.com)

Edited by KingLuxor
words
Link to comment
Share on other sites

I'm curious how much will have to be done to get The Serial IO plugin working under 1.1 and the Unity 5 engine?
Of course, today is the first day 1.1 has been publicly released to the general public, in beta form. Tried it. Had no crashes, so that's good.

Link to comment
Share on other sites

Has anyone tried to see if the plugin works? I don't have KSP on steam (easier to to work on things without steam being annoying) so I can't get 1.1 yet. However, looking at the info they posted, since we don't have much UI stuff, there maybe issues but I hope it shouldn't be too bad.

Link to comment
Share on other sites

The way that I read sarbian's plugin conversion guide, it'll at least need to be rebuilt to include references that are now in a different DLL. But after that, I think you're right and any changes that are required will be fairly minor. I do have steam, but doubt I'll have time to spend looking in to it until the weekend.

 

Link to comment
Share on other sites

Hey all!

I decided to jump back into KSP after a long hiatus!

RE: 1.1 --
tl;dr - No dice [Goes for both x32 and x64 versions]

In steam, I enrolled into the 'beta' program, and was able to download and launch the pre release of 1.1

I still have a version of the plugin installed that was working without issues.
Soon as I load a vehicle (stock satellite) onto the pad, I get the usual blinking / communications with the Arduino (even flashing lights / displays) -- however, no data is being sent or received once the vessel and pad have loaded. From a cursory glance at Sarbian's post (link provided by Stibbons) it does look like they've changed a lot of the classes / how to access or reference certain things. I'm trying to hunt for an API - but haven't found anything yet - to try work out if I could make the changes, recompile it all, and potentially merge with the existing github repo...

Zitronen: Did you have an API document for 1.0.5 (and earlier) when you were doing development?

Edit:
Rolling back to the non-beta version (to check the plugin), Arduino starts up and communicates ok; get's some preliminary data, then stalls. After a minute or two, we're back in action.
I was pretty sure the version I compiled on the Arduino board had the increased serial packet size. So some more testing / investigating to do at this end.

I copied the game folder out of the Steam directory, and once ship is loaded on the pad, it's communicating with Arduino straight away -- very odd!
But I have noticed that our 'parachute safe' work doesn't seem to be working anymore. I suspect that this could've been due to changes brought in with version 1.0.5.

Edited by Sputnix
Link to comment
Share on other sites

10 minutes ago, Sputnix said:

Soon as I load a vehicle (stock satellite) onto the pad, I get the usual blinking / communications with the Arduino (even flashing lights / displays) -- however, no data is being sent or received once the vessel and pad have loaded.

So the handshaking finishes successfully? That's a good start!

I spent some time getting 1.1 running on my system this morning, expecting to at least get a feel for how much work porting KSPSerialIO this weekend. 

The community generated API docs I use are at http://anatid.github.io/XML-Documentation-for-the-KSP-API/ and should still be 1.0.5. I think the only source for 1.1 changes is the thread I've already linked. 

Also, welcome back! 

Link to comment
Share on other sites

15 minutes ago, stibbons said:

So the handshaking finishes successfully? That's a good start!

--

Also, welcome back! 

Thanks! It's nice to be back :)

Yeah, I suspect so. So (I think) that means the serial communications stuff that Zitronen has setup should be fine; So it does look like it's just communication to and from the ship with the updated references is all that's needed.

 

Quote

From http://anatid.github.io/XML-Documentation-for-the-KSP-API/

What to do when the documentation is incomplete

  1. Look at the source code of a mod that does something similar to what you are trying to do.
  2. Look through Assembly-CSharp.xml in the object browser and see if you can find any classes with likely-sounding names. Then try them out. This is how this documentation was put together in the first place.
  3. Once you learn how to use a class or member that's not documented here, you should contribute your new-found knowledge to make the documentation better. See the instructions for how to to help here.

You would think that the dev team have some kind of API reference documentation -- just stupid that it's not released / accessible to the modders :(

 

Link to comment
Share on other sites

Thanks for the testing! Do you get any errors in the log?

I'm still waiting on them to release it on KSP website, since if I get it on steam I can't get the direct download version any more. By the number of bugs people are finding, it might take them awhile. I am actually thinking about getting a pirated version...

Link to comment
Share on other sites

What do you mean about the direct download? I wasn't aware that was possible if you bought through steam...

This is all I can find in the KSP.log:

Quote

[LOG 06:35:21.190] AddonLoader: Instantiating addon 'SettingsNStuff' from assembly 'KSPSerialIO'
[LOG 06:35:21.192] KSPSerialIO: Loading settings...
[LOG 06:35:21.215] Parsing double
[LOG 06:35:21.215] Parsing string
[LOG 06:35:21.215] Parsing int
[LOG 06:35:21.215] Parsing int
[LOG 06:35:21.216] Parsing int
[LOG 06:35:21.216] Parsing int
[LOG 06:35:21.217] Parsing int
[LOG 06:35:21.217] Parsing int
[LOG 06:35:21.217] Parsing int
[LOG 06:35:21.218] Parsing int
[LOG 06:35:21.218] Parsing int
[LOG 06:35:21.218] Parsing int
[LOG 06:35:21.218] Parsing int
[LOG 06:35:21.219] Parsing double
[LOG 06:35:21.219] KSPSerialIO: Default Port = COM3
[LOG 06:35:21.219] KSPSerialIO: Refreshrate = 0.3
[LOG 06:35:21.220] KSPSerialIO: BaudRate = 115200
[LOG 06:35:21.220] KSPSerialIO: Handshake Delay = 2500
[LOG 06:35:21.221] KSPSerialIO: Pitch Enable = 2
[LOG 06:35:21.221] KSPSerialIO: Roll Enable = 2
[LOG 06:35:21.221] KSPSerialIO: Yaw Enable = 2
[LOG 06:35:21.222] KSPSerialIO: Translate X Enable = 2
[LOG 06:35:21.222] KSPSerialIO: Translate Y Enable = 2
[LOG 06:35:21.222] KSPSerialIO: Translate Z Enable = 2
[LOG 06:35:21.223] KSPSerialIO: Wheel Steering Enable = 2
[LOG 06:35:21.223] KSPSerialIO: Throttle Enable = 1
[LOG 06:35:21.223] KSPSerialIO: Wheel Throttle Enable = 2
[LOG 06:35:21.224] KSPSerialIO: SAS Tol = 0.1

--

[LOG 06:37:13.271] AddonLoader: Instantiating addon 'KSPSerialPort' from assembly 'KSPSerialIO'
[LOG 06:37:13.272] KSPSerialIO: Version 0.17.4
[LOG 06:37:13.273] KSPSerialIO: Getting serial ports...
[LOG 06:37:13.273] KSPSerialIO: Output packet size: 191/255
[LOG 06:37:13.275] KSPSerialIO: Found 3 serial ports
[LOG 06:37:13.275] KSPSerialIO: trying default port COM3
[LOG 06:37:13.287] Error opening serial port COM3: CreateFile Failed: 2
[LOG 06:37:13.288] KSPSerialIO: trying port \Device\Serial0 - COM1
[LOG 06:37:17.297] KSPSerialIO: KSP Display not found
[LOG 06:37:17.299] KSPSerialIO: trying port \Device\USBSER000 - COM7
[LOG 06:37:21.309] KSPSerialIO: found KSP Display at COM7
[LOG 06:37:21.311] AddonLoader: Instantiating addon 'KSPSerialIO' from assembly 'KSPSerialIO'

---

[LOG 06:37:25.844] KSPSerialIO: Handshake received - 314

 

 

Edited by Sputnix
Link to comment
Share on other sites

On 4/2/2016 at 1:01 PM, Sputnix said:

Soon as I load a vehicle (stock satellite) onto the pad, I get the usual blinking / communications with the Arduino (even flashing lights / displays) -- however, no data is being sent or received once the vessel and pad have loaded.

Turns out this was because of a weird null reference exception that I'm surprised doesn't happen in 1.0.5. https://github.com/zitron-git/KSPSerialIO/pull/11 should fix it.

The 1.1 build still doesn't include the serial assemblies, sadly. I'll create a feedback issue on the bugtracker requesting it, but am not holding my breath. I haven't yet been able to properly test if the serial callbacks work properly on Windows 10 and other OS, mostly because the included serial library doesn't seem to play nicely on my Linux machine at all.

The plugin doesn't log any errors, but I've started doing what I can to validate that everything it outputs makes sense. I'll keep adding any problems I find as new issues in https://github.com/zitron-git/KSPSerialIO/issues , before seeing what I can do to fix them.

Link to comment
Share on other sites

55 minutes ago, stibbons said:

Turns out this was because of a weird null reference exception that I'm surprised doesn't happen in 1.0.5. https://github.com/zitron-git/KSPSerialIO/pull/11 should fix it.

The version of the plugin I'm currently using was a 'customised' one that Zitro and I were testing to determine the 'parachute safe' stuff and the heat warning levels.

But it does work ok in 1.0.5; so I'm not sure of what this bug you reference is (or where it sits).

RE: GitHub -- I think I've got a login for that somewhere; do I just request to join the KSPSerialIO team?

Link to comment
Share on other sites

10 hours ago, stibbons said:

Turns out this was because of a weird null reference exception that I'm surprised doesn't happen in 1.0.5. https://github.com/zitron-git/KSPSerialIO/pull/11 should fix it.

The 1.1 build still doesn't include the serial assemblies, sadly. I'll create a feedback issue on the bugtracker requesting it, but am not holding my breath. I haven't yet been able to properly test if the serial callbacks work properly on Windows 10 and other OS, mostly because the included serial library doesn't seem to play nicely on my Linux machine at all.

The plugin doesn't log any errors, but I've started doing what I can to validate that everything it outputs makes sense. I'll keep adding any problems I find as new issues in https://github.com/zitron-git/KSPSerialIO/issues , before seeing what I can do to fix them.

Interesting... I didn't think it would cause any issues since it is assigned to ActiveVessel = FlightGlobals.ActiveVessel; in void Start(). Good job finding the bug.

Does this mean you got it working in 1.1 then?

9 hours ago, Sputnix said:

The version of the plugin I'm currently using was a 'customised' one that Zitro and I were testing to determine the 'parachute safe' stuff and the heat warning levels.

But it does work ok in 1.0.5; so I'm not sure of what this bug you reference is (or where it sits).

RE: GitHub -- I think I've got a login for that somewhere; do I just request to join the KSPSerialIO team?

Wait I have a team?

e4ee58cdcd8b15a672141d779b490b12.jpg

The most recent version for the plugin is 0.17.6, and use demo13 arduino code with it. (For 1.0.5)

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

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

Link to comment
Share on other sites

2 hours ago, zitronen said:

Wait I have a team?

e4ee58cdcd8b15a672141d779b490b12.jpg

Well, I thought you did :cool:

But I don't know if I'm cool enough to be apart of it :sticktongue:

2 hours ago, zitronen said:

The most recent version for the plugin is 0.17.6, and use demo13 arduino code with it. (For 1.0.5)

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

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

I wish there was version numbers somewhere on the plugins...
I'll have a go with this tonight -- all I know about the version I'm running is that it was created/modified on the 26/7/2015.

(though, moving files around sometimes does weird things with their date-stamps).

Link to comment
Share on other sites

8 hours ago, zitronen said:

Interesting... I didn't think it would cause any issues since it is assigned to ActiveVessel = FlightGlobals.ActiveVessel; in void Start(). Good job finding the bug.

Oh, so it is. I didn't even think to look at what was happening in Start(). I guess it's reasonable that plugin initialisation is now happening before the active vessel is loaded. Slightly annoying though. :)

8 hours ago, zitronen said:

Does this mean you got it working in 1.1 then?

Well... kinda.

I've got the plugin writing values to the log files, and they almost all look like sane values (there's two or three that are definitely wrong, and some that I'm not sure how to properly confirm). I have not yet had a chance to test talking to a serial connection, or inbound traffic. That's because at home I run OS X, Linux, and Windows 10, none of which work properly. :)

So my plan right now is to:

  1. Update KSP on my Windows 10 install and test sending data with handshaking disabled.
  2. Test the cross-platform fork and make sure it's OK.
  3. Muck around again with testing the serial callback, possibly replacing serialnet with Psimax's serial class again.
Link to comment
Share on other sites

Dear zitronen,

I finally found the time to continue my project - which would be impossible without your work, so thank you very much for everything you have provided for us.

I will probably never finish my mechjeb compatible version of your plugin, so you can delete that reference from your first post.

Second, if I may ask, I have a personal request for the next version of your plugin. I would like to read back the actual throttle of my vehicle. This would not be the input command, but the value from FlightCtrlState.

http://wiki.kerbalspaceprogram.com/wiki/API:FlightCtrlState

I considered modifying your source code (which is feasible for me) but if you could be so kind to add this call in your source code I could avoid a fork. Code would be something like

#region outputs
.
.
KSPSerialPort.VData.Throttle = (float)FlightCtrlState.mainThrottle;

Of course this would require adding Throttle to the struct in both C# for KSP and C for Arduino.

I have this wonderful 0-100% analog dial I want to use to display the current throttle, independent from the control mode. Pictures will follow very soon!

Thanks in advance

cm2227

Edit: And if I happen to motivate you on changing your code, you might consider my even wilder personal request to add  the total mass of the current vessel to the VData packet from ActiveVessel.GetTotalMass(). :kiss:

Edited by cm2227
Link to comment
Share on other sites

I can add more things to the packet, but we should have a discussion of what to include, there is limited space left. Stibbons is working on adding a bunch of orbital vector stuff as well.

If you are using a controller with throttle, couldn't you connect your dial to it directly?

Link to comment
Share on other sites

It might not be reasonable for a current build of the software, but I wonder if a future build could feature packet sets... Have alternate packets that have different data sets. Stuff that's incredibly important can be shared across packet types, but data that changes less frequently, wouldn't need to be sent with every frame. Switch the packet identity bits and send different data sets for a frame, then return to sending normal frames.

I have to imagine it would allow a lot of data to be freed up. I imagine it might be more suited to a future build too. Not sure how difficult something like that would be. As long as the Arduino knows what's going on, it'll be able to direct the data based on the packet's identity bits. An SoI change is not very frequent, so IDing what SoI you are in would be a good candidate for an alt packet, just as one example.

Edited by richfiles
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...