Jump to content

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


zitronen

Recommended Posts

Glad you guys like it. :-)

The motorised slider is from SparkFun. The motor needs 9V, so I had to put a little bit more effort in to powering the panel, but is very simple to drive.

Quick question about the control packet, am I right in assuming TX TY and TZ are translation controls? I may have just ordered a couple of translation joysticks.

Link to comment
Share on other sites

I'm just putting together a parts list at the moment for my panel :)

Just a quick question for zitronen. I'm not sure how you find out where to get VData from (like att, heading, orb vel, etc) but do you think it would be possible to get velocity vector Data? As in Prograde. The VV is super important when flying and getting that info displayed would really be icing on the cake for me.

Link to comment
Share on other sites

Having a problem with the plugin atm, wondering if I can get a bit of advice...

So, I launch a ship, with a probe stuck on the top, and when the probe seperates, the game focus stays on the previous stage. When I switch vessels, the plugin analogue controls will not respond, or will still drive the other ship!

The selected craft will run, but only on standard keyboard controls.

Once the ships are seperated by over 2.5km, I can switch ships in mapview and the analogue controls are restored, but it's a bit disconcerting!

Obviously my staging sometimes leaves something to be desired, but... what's going on with the plugin controls? O_o

(Very confused!)

Link to comment
Share on other sites

Well, I just spent 3 hours trying to figure out how to get my Teensy version to correct for the structure padding issue on KSPBoardSendData()...All sorts of different variable arrangements, complicated buffers trying to arrange things correctly to get the right checksum, ridiculous bitmath, reading serial data and trying to convert the ACSII output into hex...Many many things that had me pulling my hair out...

Then, the "eureka/you-stupid-...." moment finally came when I remembered that the Teensy has capabilities to do Serial + Joystick + Mouse + Keyboard emulation all at the same time, something I have never used...Less than a minute after this 'discovery', and one short line of code later (literally as simple as: Keyboard.print(" "); ), I launched with a hardware button and felt that all to familiar mix of accomplishment from solving the problem, and embarrassment that I did not think of the obvious sooner...

the arduino leonardo can do that too. though getting the hid joystick to work takes a few modifications to the arduino libraries. i found a tutorial with a simplified example with 4 (8 bit) axes, 2 hats and 32 buttons. i didnt like it so changed the hid descriptor to support 8 (16-bit) axes instead. and it works great.

got me an ads1115 i2c adc breakout as well so i can make use of those large axis ranges. it can do 2 16-bit differential channels or 4 single ended 15-bit channels. it has a prescaler that makes things confusing, it doesnt quite measure across a 5v range like the 10-bit adcs on the arduino. you can set it to ranges of: 256, 515, 1024, 2048, 4096, 6114 (clipped at 5000, because exceeding 5v would kill it) milivolts. so i set it to the 4096mv range, and simply put a resistor on the 5v side of the pot, of 1/4 the resistance across the pot. this lets the pot only output a value between 0 and 4 volts, and the adc is happy with it, mapping it out to the full range.

if you wanted an extra bit of resolution, you have differential mode. it would require a 2v reference on one of the differential inputs, a voltage divider would work fine. the pot would be hooked up in about the same way as single ended mode. the prescaler would need to be set to 2048, since you are measuring in relation to the 2v reference, so +/- 2v. by playing with the reference voltage such as with another pot, you could do trim in hardware.

analog is fun.

You guys going the joystick route have the bear in mind that Unity has a retarded 16 button limit on joysticks. I made my controller using a leonardo clone (pic in my profile), and found out the hard way. Also I as only able to get 7 out of 8 axes working for some reason. That is partly why I made the plugin.

I'm just putting together a parts list at the moment for my panel :)

Just a quick question for zitronen. I'm not sure how you find out where to get VData from (like att, heading, orb vel, etc) but do you think it would be possible to get velocity vector Data? As in Prograde. The VV is super important when flying and getting that info displayed would really be icing on the cake for me.

The VOrbit should be your prograde velocity? I don't see any easy way of using the actual velocity vector which is a vector of 3 values of you velocity relative to the centre of the body in the non-rotating frame?

Having a problem with the plugin atm, wondering if I can get a bit of advice...

So, I launch a ship, with a probe stuck on the top, and when the probe seperates, the game focus stays on the previous stage. When I switch vessels, the plugin analogue controls will not respond, or will still drive the other ship!

The selected craft will run, but only on standard keyboard controls.

Once the ships are seperated by over 2.5km, I can switch ships in mapview and the analogue controls are restored, but it's a bit disconcerting!

Obviously my staging sometimes leaves something to be desired, but... what's going on with the plugin controls? O_o

(Very confused!)

OK seem like something weird is happening with switching vessels. Is this happening with all your rockets or just that one? The plugin is supposed to know which is the current active vessel and only control that one, but there could be bugs with it.

Glad you guys like it. :-)

The motorised slider is from SparkFun. The motor needs 9V, so I had to put a little bit more effort in to powering the panel, but is very simple to drive.

Quick question about the control packet, am I right in assuming TX TY and TZ are translation controls? I may have just ordered a couple of translation joysticks.

Yes the descriptions are in the first post.

Edited by zitronen
Link to comment
Share on other sites

At first I thought it was just one ship, but it seems to be any ship that has multiple controllable stages (I use command probe parts a lot).

As far as I can work out, the flight readouts switch to the new vessel when KSP switches vessel, but the analogue controls stay with the 'main' ship, even if the camera is following another ship.

Also: While the ship is running off the analogue controls, the keyboard controls (WASDQE, IJKLHN, shift/ctrl throttle) will not respond - I vaguely remember that from the notes, but when I switch vessel and the analogue controls are still focussed on the old ship, the keyboard controls become live again for the newly focussed ship.

Not sure if that helps you hunt down the gremlin, but hope the info helps :)

Edited by AmeliaEatyaheart
Link to comment
Share on other sites

OK I think I know what's going on. My code is only checking if the current active vessel is a valid vessel, and attaches an event driven function that updates the controls. So if your rocket is destroyed it will correctly detach the controls from the old one to the new one. However if you stage has multiple valid vessels or if you switch it doesn't remove and re-attach the function to the current one because it's not checking whether the vessels are different, just if they are valid. I have not done nearly enough testing on the axes controls since I don't use it myself...

Edit: I think it should be easy to fix, can you send me your craft file so I can confirm? I'll try to get it fixed before the end of the week.

Edited by zitronen
Link to comment
Share on other sites

You guys going the joystick route have the bear in mind that Unity has a retarded 16 button limit on joysticks. I made my controller using a leonardo clone (pic in my profile), and found out the hard way. Also I as only able to get 7 out of 8 axes working for some reason. That is partly why I made the plugin.

Is the 16-button joystick limit really an issue though when you can also send keyboard keystrokes?

The VOrbit should be your prograde velocity? I don't see any easy way of using the actual velocity vector which is a vector of 3 values of you velocity relative to the centre of the body in the non-rotating frame?

I am not exactly sure what he was asking about, but a prograde/retrograde/etc marker would be a great thing to be able to add...I plan to use a small LCD to simulate the navball in some way, which I should be able to work out using the pitch/roll/heading data...I was not even thinking about additional markers until now. I have no idea how the game or the plugin are actually coded, but I would think that there should be some kind of separate vector data that determines where the markers appear on the navball itself, along with things like normal/anti-normal and the maneuver nodes. If that is what he was talking about, I agree that would be icing on the cake.

Link to comment
Share on other sites

Is the 16-button joystick limit really an issue though when you can also send keyboard keystrokes?.

I don't believe so, at least not for KSP. I'm relying mostly on keystrokes and use the "Joystick" device only for the analogue axis (pitch/roll/yaw/throttle and lateral X/Y).

This weekend I'll finally have time to build the case for my project. Expect some pictures :). Still got a lot of soldering to be done but I still hope I can pull this off before the year runs out.

Link to comment
Share on other sites

This weekend I'll finally have time to build the case for my project. Expect some pictures :). Still got a lot of soldering to be done but I still hope I can pull this off before the year runs out.

I wish that was my timeline...I have a kickstarter 3D printer coming sometime (hopefully) in Feb that I plan on using to make mine...I should have all the electronics done by the time it gets here, but they will just be a taunting jumble of wires and pretty lights for a while yet.

Link to comment
Share on other sites

...can you send me your craft file so I can confirm?

Done :) I had to cut out mod parts (I use a LOT of mod parts), but should work as expected (i.e. not work :P )

As I said, the flight parameters sent to the panel definitely appear to be attached to current vessel, it appears to be just the controls going back into KSP :)

Thankyou!!!!! :D

Link to comment
Share on other sites

I honestly didn't think about using orbital information to develop my own VV by combining vectors :S.

I figured the game might output the VV and other navball markers in a similar way to the attitude, ie pitch, roll, heading.

I guess my primary use would be in flying. Utilising the difference between the VV and attitude to calculate a crude angle of attack for things like best lift to drag ratio, 3 degree glide slope approaches, maintaining level flight a whole lot easier, etc

Link to comment
Share on other sites

I figured the game might output the VV and other navball markers in a similar way to the attitude, ie pitch, roll, heading.

Except KSP doesn't ouput pitch roll or heading. I had to steal code from mechjeb to do some quaternion math to calculate them.

Edit: You can already calculate your glide slope (or lift/drag ratio) using vsurf and VVI, all you need to calculate is your horizontal speed.

Edited by zitronen
Link to comment
Share on other sites

@Zitronen: This has probably been asked a few times already but my search skills fail me today :(.

Are there any plans to send status information for SAS, RCS, Vessel Lights, Brakes, Gear (is there more? can't think of any) from KSP to the Microcontroller? I believe a single bit-mask of uint_8 should suffice to do this. That said I have no idea whether that is planned or even feasible. It'd be nice however if hardware controllers could display status lights for these things that stay in sync with the game.

Link to comment
Share on other sites

Ah okay I was afraid you might say that :D

If I remember correctly RasterPropMonitor and kOS both have figured out a way to get the info though - maybe I find some time one of these days to search through their code.

Link to comment
Share on other sites

Okay I just seized part of my lunch break to do some research.

Aren't you already working with RCS, SAS and the like in KSPIO.cs Start() after the "sync inputs at start" comment?

I checked kOS and they seem to just access the KSPActionGroup suffixes and validate against those.

This is probably too easy, right?

Update: Seems as if RasterProp also isn't doing anything more.

https://github.com/Mihara/RasterPropMonitor/blob/b4618154ed11f96c8be3d9691ba1b154229e8e5d/RasterPropMonitor/Auxiliary%20modules/JSIActionGroupSwitch.cs

Lines 49 following.

Update 2 DAMNIT I just realized that if this is true I need to re-evaluate my controls layout for the box that I was about to put together this weekend :D Oh the irony

Edited by MrOnak
Link to comment
Share on other sites

Update 2 DAMNIT I just realized that if this is true I need to re-evaluate my controls layout for the box that I was about to put together this weekend :D Oh the irony

Good thing I already rewired my control panel for the five buttons / leds yesterday :sticktongue:

Link to comment
Share on other sites

Oh well... guess I need to rearrange things. Again.

BTW this is it, work-in-progress.

oHN3pj5.png

All the blue rectangles are 7-segment displays or bar displays. Their spacing is not 100% spot on yet and I don't like the empty space next to the DSKY info lights. The latter is probably solved in case I need 5 more info lights for SAS, RCS, ... ;)

Link to comment
Share on other sites

Very nice! I think I am going to have to add a lot more controls to mine (though probably not quite as many as you have) before I am done...I just need to wait for my shift registers to get here, since all I had laying around were SIPO...For some reason I had not thought about all the other gameplay related keybindings that I should add to things.

Right now, I am stuck on some hardware serial issues because I am going to need to add a second microcontroller into the mix...The 240x320 LED screens I want to use take WAY too long to update even using a Teensy 3.1...Ends up clogging the serial buffer and causing all sorts of problems so I am going to outsource the problem...If I can ever get the damn things to talk to each other.

Link to comment
Share on other sites

Okay I just seized part of my lunch break to do some research.

Aren't you already working with RCS, SAS and the like in KSPIO.cs Start() after the "sync inputs at start" comment?

I checked kOS and they seem to just access the KSPActionGroup suffixes and validate against those.

This is probably too easy, right?

Update: Seems as if RasterProp also isn't doing anything more.

https://github.com/Mihara/RasterPropMonitor/blob/b4618154ed11f96c8be3d9691ba1b154229e8e5d/RasterPropMonitor/Auxiliary%20modules/JSIActionGroupSwitch.cs

Lines 49 following.

Update 2 DAMNIT I just realized that if this is true I need to re-evaluate my controls layout for the box that I was about to put together this weekend :D Oh the irony

It seems to me that they are not reading the status from KSP, they are just recording the user inputs into an persistence file and using that.

Link to comment
Share on other sites

Hi guys,

I was hoping you guys could help me with a problem I am having with the liquid fuel in the stage. It works - unless I have only side-mounted engines in a stage. Then It says that the remaining and total fuel in the stage is equal to 0. Does anyone have any suggestions for fixing this, or is having similar problems?

Also, I am having trouble with momentary buttons I added to act as action group buttons. When I use the default code, If I tie it for example to toggling the lights, the lights will only stay on for as long as I am holding down the button.

I can try to clarify better if anyone would like to know more.

Thanks! :)

Link to comment
Share on other sites

The plugin uses a recursive resource search thing I stole from somewhere to get the stage fuel, there are unfortunately many ways for it not to work... You can try adding a small fuel tank before the engine and fuel line it to the rest of the fuel?

The control groups are designed to be used with toggle switches, if you want use buttons you need to write some simple arduino code to toggle a variable. You can also just assign one button in VAB to turn something on (e.g. lights) and another to turn it off.

Link to comment
Share on other sites

Thank you Zitronen! I ended up creating a fancy if-statement sequence that would display total fuel remaining if for whatever reason the stage fuel was not showing up. That will probably do for now.

I will go write some code for the buttons, I think I understand how they work now.

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