Jump to content

PeteWasEre

Members
  • Posts

    40
  • Joined

  • Last visited

Everything posted by PeteWasEre

  1. Sure, would be happy too. I have no experience with GitHub though so give me a few days to figure it out as i have been meaning to set this up for a while. Will let you know when its done. The python code I have is probably pretty bad, but it works. The C code for the Arduino should be better as C was always my favourite language!
  2. Thanks, that worked perfectly. On performance issues I do like @dewin 's idea on stream events. This would be great for things like landing gear state, I only care when it changes. However I was also reading the conversation on Issue #311 In particular I was drawn to the comment (comment #4) from @djungelorm talking about a general concept of telling the server how to handle some data before streaming it. As an example take heat. I am currently streaming temps from every part to find max(temp/max_temp) and use this to trigger an alert. Given I check skin temp and core temp that's 2 x <number of parts> streams but I only want one number. If I could send a code statement to the server and ask it to stream the result it would make this amazingly efficient! I also had another thought, would it be possible to group data to send to the server? For example each iteration of my code I set at least 9 items in Vessel.Control (3 x rotation, 3 x translation, throttle, wheel throttle, wheel steering) from my analogue inputs. That's 9 lots of overhead. I was wondering if there was a way I could bundle that to make it one send to the server, then it would dramatically reduce the number of comms. Hypothetically I tell it an object and give it [(attribute,value)] if you know what I mean. I thought of this based on the earlier description that streams package data together into one send, and thought it would be neat to be able to do that for inputs too. If it was grouped at the object level it would be fine, e.g. I send one batch of control inputs and a separate batch of autopilot inputs etc. It would still cut RPCs from dozens to a handful. I will leave it to you wiser folk to determine if this is feasible as I realise my technical knowledge of how this all works is 0 and I may be talking out my engine bell I also realise each time I come here I seem to create work for you, thank you again for you patience and efforts! Cheers Pete
  3. So after some more testing I am starting to understand the performance issues a bit more. Firstly, streams are AWESOME. After rewriting a lot of my output indicator code to use streams the performance is much better, and with about 65 active streams I see no performance impact in the game. 3k stream RPC/s and it seems happy. Also, the streams don't break if a part is lost. I blew away parts with whack-a-kerbal and the temperature streams for those parts just stopped updating which is very nice. I just reset all my streams on a stage event (and have to think about un-docking too!). I also rewrote a lot of input code to avoid spamming RPCs. Basically I had a lot of vessel.control.<something> = switch and by moving to an edge detection on the switch the RPCs came right down. The main driver of RPCs is now the mapping in of analogue flight controls which I cant avoid. I wish there was an input stream (but realise that's pretty out there....) So now my entire code (back end, its a separate process to the GUI) is running < 60ms which is a big improvement. The performance though is still occasionally variable with a long delay at an RPC request. These delays are often of the order of 50-60ms! I think this might be a synch issue where my code sometimes spans two frames in the game. I tried playing with the blocking time limit with mixed results, increasing this seemed to reduce the frequency but the delay was longer. So if I can find a way to look up LandingGearState in the library rather than an RPC and move gear states to streams that will help again. And finally I will change my Python / Arduino interaction model to be parallel as they are currently serial and python has to wait for the Arduino which is 12-20ms delay with data transfer time. If I can be consistently sub 50ms I would be happy. @djungelorm you can probably then ignore most of my previous question on performance issues, but if you can help me understand how to properly reference things like LandingGearState I would be much appreciative! All this though is on a small 20 part test ship..... I might have to load my old Duna base of 400 parts..... that would be 1200 streams for heat alone! That will be fun
  4. Hey @djungelorm, thanks for the reply. Regarding the camera i like the last option. I am already doing the second option in my code by setting a timer on change. If this was in the back end though it would be confusing, especially as my camera control is a rotary switch so it skips through various modes and having to wait would make it hard to know what's going on. A cached solution would be best i think, at least in my application. Looking forward to what you find on EVA I have some other questions for you, as I am struggling with performance in my python code. I have found my coding approach executes FAAARRRR to many RPCs... that's my bad coding. For example: part_list = vessel.parts.all for p in part_list: if (p.temperature / p.max_temperature) > 0.5 or (p.skin_temperature / p.max_skin_temperature) > 0.5: output_buffer[2] |= 1 << 1 if (p.temperature / p.max_temperature) > 0.3 or (p.skin_temperature / p.max_skin_temperature) > 0.3: output_buffer[2] |= 1 << 3 This is taking on average 35-40ms to execute! My intention is to move this to a list approach of: part_temp_list = [(p.temperature, p.max_temperature, p.skin_temperature, p.max_skin_temperature) for p in vessel.parts.all] and then do the calcs on that list. This reduces the RPCs for my small vessel by 50% but its still taking 30 ms. I think the answer here is to use streams, would I be thinking right? That's going to be a LOT of streams.... and i guess that i will need to manage those streams each time i decouple, break off a part, remove something with KAS etc. Is there any thing i am missing here, another way to do this? And finally I have to end with a silly question... and i know this is my lack of understanding so sorry in advance. I am struggling to understand how to directly reference some items like LangingGearState. For example: gear_list = vessel.parts.landing_gear + vessel.parts.landing_legs for gear in gear_list: if gear.state == gear.state.retracted: I am checking the gear state against gear.state.retracted, which is an RPC itself and it doesnt make sense to me to query the server to get a defined type to compare against. Its like saying 'is X = TRUE' but looking up True each time on the web. However (in my naive mind) I would have though I can reference this from the imported krpc library. Is that possible or am i doing this the right way? Thanks again! Pete
  5. @Freshmeat - thank you for the kind words! The graphics were painfully drawn in Open Office Draw and printed on self adhesive paper in a standard ink jet. This limited me to less that A4 so the main panel has some joins but they are not too visible. Its then covered with self adhesive clear A4 sheets that i will use to print the light box labels onto. It prints nicely in an inkjet as long as you are careful to let it dry which takes a while. All this stuff came from Ebay. I originally was going to use 2mm perspex to cover the graphics but the buttons were a PITA and then it started to crack so i binned it. I wish i could have used Front Panel Express who have a free design program which i used for the initial layouts. You can then upload it to them and they will machine it out for you including infills, slots etc. The cost is not cheap (the program calculates it for you on the fly) but reasonable, but postage to Australia and our great Fx rate killed that idea fast.
  6. Hi @djungelorm I will apologise in advance, because I have a few issues now that I am debugging my controller code and I am sure at least some of them will be dumb errors on my part! 1. Camera distance doesn't seem to take effect for about 2 seconds after a camera mode change. I am setting the camera mode (which changes in the game immediately) and then setting camera.distance = camera.default_distance, this wasn't having any effect. So I forced this to set repeatedly and found that despite setting the distance each time on the next run through the code the distance was the original, and only after about 2s it changed. Is there some limitation here with the camera? I can reproduce it with the following snippet (and the cam starting off default zoom) where the last line does nothing, but change the previous sleep to 3s or higher and it works! import krpc import time conn = krpc.connect(name='Game Controller') vessel = conn.space_center.active_vessel cam = conn.space_center.camera time.sleep(2) cam.mode = cam.mode.locked time.sleep(5) cam.mode = cam.mode.free time.sleep(2) cam.distance = cam.default_distance 2. I get an error when checking gear state after launch (or revert to launch) of an aircraft from the SPH. Once the gear is toggled (raised or lowered) the gear.state works fine, but until that first toggle i see the following. It is reproducible direct from the console by querying any gear state. Does it require some kind of initialisation i am missing? if gear.state == gear.state.retracted: File "<string>", line 1, in <lambda> File "C:\Users\petern\AppData\Local\Programs\Python\Python35-32\lib\site-packages\krpc\client.py", line 87, in _invoke raise RPCError(response.error) krpc.error.RPCError: Operation is not valid due to the current state of the object and it relates to this code: gear_list = vessel.parts.landing_gear gear_up = 0 gear_down = 0 for gear in gear_list: if gear.state == gear.state.retracted: gear_up += 1 3. When a kerbal is EVA they still exist as a vessel, but vessel.control doesn't seem to have any effect. I am assuming that the game manages an EVA kerbal differently to a vessel, so this probably isn't supported. Is this assumption correct and is it something that could be included? Note though that issue #148 would probably achieve the same end by allowing controls to be mapped to key presses, and would allow things that are key driven like KAS/KIS also. Anyway I think that is enough pestering for one night, so I shall leave it at that. Thank you again for all your help and the mod! Cheers Pete
  7. Hi All Just wanted to share my progress on my custom controller. It all started when i found i had some useful HW laying around and found the wonderful KRPC mod by @djungelorm. Being and ex flight sim developer who is relegated to management these days I miss this stuff so I thought 'this will be easy and fun'! Turns out i was 50% right In true Kerbal fashion it got out of hand quickly... I realised i had gone full Kerbal when i took the complete key binding list and tried to make a switch for everything..... Reality did dawn and a few got dropped, but not many! At this point i have to say a massive thank you to @djungelorm for answering my many questions and actively taking on my requests for more features in KRPC. So here she is (p.s. can anyone tell me how to rotate images on imgur???): Physical Layout: The body is wood and designed to sit over the laptop with the screen still visible, and space on the right to still use the mouse. The panels are 4mm aluminium plate (yes, i know, but cheap trumps overkill) with stick on graphics and a clear stick on cover. Actually the 4mm was a pain as many switches wouldn't reach the depth and I had to machine out trenches in the back. I purposely am not going to describe my workshop practices as there may be children reading and blood was involved.... The light boxes on the side are hand made out of little bits of Perspex glued together with LED strips in the back... PITA x 10^343427436 The wiring did start to get a bit out of hand at the end, but given I was trying to use whatever I had its reasonable. The space on the lower left is for a later Autopilot and perhaps KAS/KIS area... lets get this finished first! Architecture: The is an Arduino Mega in the back talking over USB serial to a Python program on the PC. As even a Mega doesnt have anywhere near the pinouts to do this there are also a bunch of MCP23017 extenders which proved to be so super easy to use. The Mega runs the side panel and the analogue inputs (joysticks and throttles) whilst the extenders run the main panel off. This approach really minimised the wiring to this panel. The lights are driven of ULN28003 arrays and also PWM dimmed. The fan is PWM speed controlled (at max freq to stop whine) off a temperature sensor near the Arduino. (Originally it was mean to be an Arduino talking to a PI that ran a 10inch touch-screen taking to the PC. Then i dropped the touch-screen and moved to this approach which I think is a lot better anyway. Destruction leads to better design as Jeb likes to say!) The code on the Arduino runs at a fixed 100Hz, and at the start of each frame checks for data from the Python module that drives the lights. If it receives data it will return data at the end of the frame, and if not it runs anyway but just doesn't send. This avoided a lot of timing issues and the need to synch the two programs. If the Python module pauses for some reason, the Arduino doesnt care. Where am I at: Most of the panel now works except the vessel and map focus switching, though there is a list of bugs to solve in the code and one nasty design oops in the HW that will require the extension board to come out and get modded with some diodes. I need to replace some of the rotary switches too as i mistakenly got 2x6 instead of 1x12. Also i cant yet control EVA Kerbals. The arduino code is all done and just needs a final tidy. The Python code is still at 'just make it work' and needs a massive restructure and clean up. I will do this when I have the functionality sorted. The last part will then be the graphic outputs. The idea is to use my two other monitors as info screens showing game data based on a mode selection on the panel. This is still in the conceptual design phase. I have learnt a huge amount doing this and am happy to share my knowledge to anyone else who is crazy... err keen enough to take something like this on. I do plan at some point to document this all up too. Its very worth it, and after flying with sticks and switches i cannot go back! Happy crashing! Pete
  8. I would definitely use it! Not just for this, but I can imagine creating a reference frame on a part, say a cockpit or docking port, as opposed to the vessel CoM. Once its created you don't need to worry about the offset or rotation anymore, just do everything in your new reference frame. Also, while I am busy creating ideas the draw line is great and if it is possible to extend it I would be a happy camper! Line thickness as a simple example but is it possible to draw shapes, planes? Or even be able to draw on the nav ball! now I am getting carried away I know. I know this mod is not meant to be KSPaint but I am seeing lots of opportunity for guidance, targeting etc There are many pushes in real aviation for 3D goggles to overlay information onto real life, well this could provide the same.
  9. This wont work simply because the vector in the runway reference frame is calculated offline (excel) and then a transformation is done from the vessel to the body reference frame. To do this the test rig aircraft must be the active vessel on the runway. However I could calculate and store multiple vectors as hard code and switch, which would work but is coding heresy. @djungelorm is it possible to create a reference frame dynamically? i.e a function that takes a point in another reference frame, and 3 direction vectors and returns a new reference frame. Then I could define a reference frame at the threshold and all this would get a lot easier and more dynamic. You can even have the flight path adjust based on your position and guide you right onto finals!
  10. So i made some progress on landing guidance. if anyone else would like it here it is. It sets up lines either side of the runway at 4 (red), 5 (white) and 6 (yellow) deg slope for 20km from runway 09 threshold. 3.5 degrees, as per an airliner, did not seem kerbal enough so i went for a military 5. A shuttle 21 deg approach could be interesting too for an unpowered craft. The only shame is that it is hard coded. I cant find a way to calculate them directly, which would be nice so you can tune slope / distance. I used a test rig comprising a Mk1 cockpit on the front of a T frame of girders with some more girders for legs so i know the rig will sit as flat and straight as possible. This was important as it lets me use the vessels reference frame as a runway reference frame. I could then define the start and end position for each line in the 'runway reference frame'. The starts are simply (+/-30,0,0) and the ends are (+/-30, -length, -tan(slope)*length). Each of these points (2 start, 6 end) are transformed into the kerbin reference frame using space_center.transform_position() and pasted into the code. To get the other end you just need to rinse/repeat with a vessel at the other threshold, but make sure it sits dead flat (pitch and roll). import krpc conn = krpc.connect(name='blah') vessel = conn.space_center.active_vessel conn.space_center.clear_drawing() v1_start = (158095.3939033646, -478.99761794020907, -578869.7132278137) v2_start = (158094.96184479096, -538.996063121335, -578869.7134211722) v1l_end = (139184.84695719907, -342.79930986318584, -585527.6834731719) v1m_end = (139278.06869656406, -343.45641409607947, -585866.255670956) v1h_end = (139371.60232570115, -344.14248819162003, -586205.9386240399) v2l_end = (139184.35853335817, -402.79511157271287, -585527.523517651) v2m_end = (139277.66372229127, -403.45750069248425, -585866.328863767) v2h_end = (139371.1656752824, -404.1432818151327, -586205.927123417) l_col = (255,0,0) m_col = (255,255,255) h_col = (255,255,0) conn.space_center.draw_line(v1_start, v1l_end, vessel.orbit.body.reference_frame, l_col) conn.space_center.draw_line(v1_start, v1m_end, vessel.orbit.body.reference_frame, m_col) conn.space_center.draw_line(v1_start, v1h_end, vessel.orbit.body.reference_frame, h_col) conn.space_center.draw_line(v2_start, v2l_end, vessel.orbit.body.reference_frame, l_col) conn.space_center.draw_line(v2_start, v2m_end, vessel.orbit.body.reference_frame, m_col) conn.space_center.draw_line(v2_start, v2h_end, vessel.orbit.body.reference_frame, h_col)
  11. @djungelorm thanks for the info on vessels, that's a sweet solution, and also on the add ons! Will keep an eye on github for progress.
  12. Ok, take a breath, calm down... i think i have just stumbled onto the greatest thing ever.... well, in KSP anyway, which is everything important right? space_center.draw_line() and by placing a vessel at the threshold of the runway i get its coordinates for the start. Now if i can work out the position of the end of a vector that is 10km long at 3 deg slope heading west... i have LANDING GUIDANCE!!! This could be a couple of lines either side of the runway, or even 4 lines forming a rectangular tube to fly down. And putting one at the other end is just a matter of coordinates. Now if only i remembered enough maths to add my 10km vector in the celestial body reference frame to the start point! At 11pm that aint happening.. but tomorrow i will certainly give it a go! If i manage to get the vectors calculated out i will share them of course! This is so going on my control panel. Runway select to 09, landing guidance to ON... ooooooo, aaahhhhh
  13. Yep that's not to hard to do. Moving my 0 point will do trim and scaling the maximum will do fine controls. It wont be linear anyway as it will need a dead band. However the game does have this built in, trims are MOD + WASDQE and to reset trim is MOD X. Ah yes.. there is a pro tip... read the documentation carefully! it does say this property is read and write However when in flight, does conn.space_center.vessels consider physics range? I was hoping to replicate the '[' and ']' key functions that only operate on nearby vessels. Or does it list all vessels, so matching the list in the tracking center? I will do some experiments on this one. EVA controls are a different key binding so this wont work. Same for KAS. They must be actions defined in the EVA kerbal vessel modules though, so I will have a play and see if I can see any of them via the part and module options. I see the issue now of the pause, its a game stop rather than a time rate of 0, so this one is out. If I can get quicksave at some point though it would do, as I can save when I get yelled at and reload when I get released In the web documentation at http://krpc.github.io/krpc/extending.html under further examples there is a link to https://github.com/krpc/krpc/tree/latest-version/src/kRPCSpaceCenter/Services which gives the 404. Note I cant check the PDF as I am at work and they get narky, but I think its the same.
  14. Hi! First and foremost, a big thank you and well done on the mod! Your hard work is very much appreciated. I am hoping for a little help with a project where i am planning to build a control panel. In my usual style i have gone totally overboard... a few buttons just wont cut it. The idea is is a complete panel that removes all keyboard input, everything will be switches and indicators around a 10" display to show flight data. I have done proof of concept of the display (streams are awesome!) and of digital and analogue inputs from an arduino. The next step was to map out all the controls i want and find the corresponding interface in KRPC.... and that's where i got stuck on a few items: 1. Trim controls and fine control mode 2. Map view, map focus, cycle active ship, IVA view, camera modes 3. EVA controls in general (use part, board, headlamps etc) and KAS/KIS controls to grap/attach/equip. 4. Game controls like quicksave, or pause (for when my wife yells 'get off that damn game already!') I am not too worried about the first one as i can offset/scale my analogues to do this, but i am a but stuck on ideas for the rest. Is it possible to control these things via KRPC? I noted the service API and the potential to extend, however my tech knowledge wasn't good enough to follow without more example (my coding days are long ago when classes weren't a thing yet) and the link in the docs more detailed examples throws a 404. So this looks like it might be my way forward but i cant tell for sure. Thanks in advance for any help!
×
×
  • Create New...