Jump to content

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


zitronen

Recommended Posts

On 4/5/2019 at 5:31 AM, Freshmeat said:

@c4ooo: Thanks for clarifying. I want to have an alarm going off whenever I deviate to much from prograde as my constructions are not always that aerodynamically stable.

Do you think something like this could be used for a stall alarm? I think real planes use pressure sensors in special areas on the wing.

Link to comment
Share on other sites

I'll try and post some photos this weekend I just put up some wallpaper and it looks really cool inside of the capsule, the control panel is still being worked on but it looks really cool IMO. 

Ok so slowing down the update rate of my displays apparently only fixed half of my problem. The other half of my issue I think so far only happens on the first time you load a rocket on the start of a game. I pulled up the error log and looked at it and 2 things stuck out to me the first time it tried COM 3 then takes 14 times trying to connect to COM 4 and then tries COM 3 which I changed the default port to COM 3 in the config file again. Also the log file showed that [ ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index ] I attached that part of the leg file that was the part that had the issue of now loading the stages and not being able to launch or control the craft.

 

 

[LOG 17:13:09.908] [UiApp] Awake: ResourceDisplay
[LOG 17:13:09.994] [AddonLoader]: Instantiating addon 'AeroGUI' from assembly 'KSP'
[LOG 17:13:09.996] [AddonLoader]: Instantiating addon 'KSPSerialPort' from assembly 'KSPSerialIO'
[LOG 17:13:09.997] KSPSerialIO: Version 0.18.7
[LOG 17:13:09.997] KSPSerialIO: Getting serial ports...
[LOG 17:13:09.997] KSPSerialIO: Output packet size: 200/255
[LOG 17:13:10.000] KSPSerialIO: Found 15 serial ports
[LOG 17:13:10.000] KSPSerialIO: trying default port COM3
[LOG 17:13:14.541] KSPSerialIO: KSP Display not found
[LOG 17:13:14.542] KSPSerialIO: trying port \Device\USBSER000 - COM4
[LOG 17:13:14.542] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.542] KSPSerialIO: trying port \Device\USBSER001 - COM4
[LOG 17:13:14.543] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.543] KSPSerialIO: trying port \Device\USBSER002 - COM4
[LOG 17:13:14.543] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.543] KSPSerialIO: trying port \Device\USBSER003 - COM4
[LOG 17:13:14.543] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.543] KSPSerialIO: trying port \Device\USBSER004 - COM4
[LOG 17:13:14.543] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.543] KSPSerialIO: trying port \Device\USBSER005 - COM4
[LOG 17:13:14.543] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.543] KSPSerialIO: trying port \Device\USBSER006 - COM4
[LOG 17:13:14.543] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.543] KSPSerialIO: trying port \Device\USBSER007 - COM4
[LOG 17:13:14.543] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.543] KSPSerialIO: trying port \Device\USBSER008 - COM4
[LOG 17:13:14.544] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.544] KSPSerialIO: trying port \Device\USBSER009 - COM4
[LOG 17:13:14.544] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.544] KSPSerialIO: trying port \Device\USBSER010 - COM4
[LOG 17:13:14.544] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.544] KSPSerialIO: trying port \Device\USBSER011 - COM4
[LOG 17:13:14.544] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.544] KSPSerialIO: trying port \Device\USBSER012 - COM4
[LOG 17:13:14.544] Error opening serial port COM4: CreateFile Failed: 2
[LOG 17:13:14.544] KSPSerialIO: trying port \Device\USBSER013 - COM3
[LOG 17:13:17.647] KSPSerialIO: found KSP Display at COM3

[LOG 17:13:17.647] [AddonLoader]: Instantiating addon 'KSPSerialIO' from assembly 'KSPSerialIO'
[LOG 17:13:17.650] [PlanetariumCamera]: Focus: Kerbin
[LOG 17:13:17.650] [UIMasterController]: HideUI
[LOG 17:13:17.950] [UIMasterController]: HideUI
[LOG 17:13:17.951] ------------------- initializing flight mode... ------------------
[LOG 17:13:17.991] [MessageSystem] Save Messages
[LOG 17:13:17.992] Loading Depletion Nodes
[LOG 17:13:17.992] DepNodeCount:  0
[LOG 17:13:17.992] Loading Biome Nodes
[LOG 17:13:17.992] BiomeNodeCount:  0
[LOG 17:13:17.992] Loading Planet Nodes
[LOG 17:13:17.992] PlanetNodeCount:  0
[LOG 17:13:17.995] [ScenarioDestructibles]: Loading... 0 objects registered
[LOG 17:13:18.077] Loading ship from file: C:/Program Files (x86)/Steam/steamapps/common/Kerbal Space Program/KSP_x64_Data/../saves/default/Ships/VAB/Auto-Saved Ship.craft
[LOG 17:13:18.078] [UIMasterController]: HideUI
[LOG 17:13:18.195] AeroEquus loaded!
[LOG 17:13:20.527] putting ship to ground: 4.398966
[LOG 17:13:20.534] [AeroEquus]: Ready to Launch - waiting to start physics...
[LOG 17:13:20.544] Crewmember Aldin Kerman assigned to Mk1 Command Pod, seat # 0 (crew seat index: 0)
[LOG 17:13:20.545] [FLIGHT GLOBALS]: Switching To Vessel AeroEquus ---------------------- 
[LOG 17:13:20.546] setting new dominant body: Kerbin
FlightGlobals.mainBody: Kerbin
[LOG 17:13:20.547] Reference Frame: Rotating
[LOG 17:13:20.570] Vessel assembly complete!
[LOG 17:13:22.969] all systems started
[LOG 17:13:26.233] FXModuleAnimateThrottle: Could not find animation heatAnimation in part's animation components. Check the animationName and model file
[LOG 17:13:26.234] FXModuleAnimateThrottle: Could not find animation heatAnimation in part's animation components. Check the animationName and model file
[LOG 17:13:26.235] FXModuleAnimateThrottle: Could not find animation heatAnimation in part's animation components. Check the animationName and model file
[LOG 17:13:26.236] FXModuleAnimateThrottle: Could not find animation heatAnimation in part's animation components. Check the animationName and model file
[LOG 17:13:26.580] KSPSerialIO: Handshake received - 314
[LOG 17:13:26.843] [UiApp] Awake: CurrencyWidgetsApp
[LOG 17:13:26.843] [UiApp] Awake: ResourceDisplay
[LOG 17:13:26.843] [UiApp] Awake: KSPedia
[LOG 17:13:26.843] [UiApp] Awake: DeltaVApp
[LOG 17:13:26.843] [ApplicationLauncher] OnSceneLoadedGUIReady: scene FLIGHT ShouldBeVisible() True ShouldBeOnTop() True iIsPositionedAtTop False
[LOG 17:13:26.844] [ApplicationLauncher] SpawnSimpleLayout: VerticalTopDown
[LOG 17:13:26.845] [KnowledgeBase] OnAppLauncherReady 6439
[LOG 17:13:26.875] [UIApp] OnDestroy: Contracts
[LOG 17:13:26.875] [UIApp] OnDestroy: Missions App
[LOG 17:13:26.890] [MessageSystem] Reposition 0.02 6440
[LOG 17:13:26.890] [GenericAppFrame] Reposition 0.02 6440
[LOG 17:13:26.890] [GenericAppFrame] Reposition 0.02 6440
[LOG 17:13:26.925] [FlightIntegrator]: Reloaded drag cube for zeroed cube root part mk1pod.v2 on vessel AeroEquus
[LOG 17:13:26.940] [FlightIntegrator]: Vessel AeroEquus has been unloaded 1.79769313486232E+308, applying analytic temperature 306.668062300704
[EXC 17:13:26.985] ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
    System.Collections.Generic.List`1[KSP.UI.Screens.StageGroup].get_Item (Int32 index)
    KSP.UI.Screens.StageManager.AddHeldIconsToStages (.Part selectedPart, Boolean switchingVessels)
    KSP.UI.Screens.StageManager.SortIconsSequence (.Part p, Boolean switchingVessels)
    KSP.UI.Screens.StageManager+<SortIconsSequence>c__Iterator0.MoveNext ()
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress)

[LOG 17:13:27.217] [PlanetariumCamera]: Focus: AeroEquus
[LOG 17:13:27.246] [UIApp] Adding ResourceDisplay to Application Launcher
[LOG 17:13:27.247] [UIApp] Adding ResourceDisplay to Application Launcher
[LOG 17:13:27.258] [ResourceDisplay] OnAppStarted(): id: -324876
[LOG 17:13:27.259] [GenericAppFrame] Reposition 0.1474556 6444
[LOG 17:13:27.260] [ResourceDisplay] OnAppStarted(): id: 153388
[LOG 17:13:27.260] ResourceDisplay already exist, destroying this instance
[LOG 17:13:27.260] [UIApp] OnDestroy: ResourceDisplay
 

Link to comment
Share on other sites

@Freshmeat Extremely ambitious is a very good way to put it. It's a nice place to work but university isn't cheap so it has its downsides. Incase you are wondering I'm an Aerospace engineering student and this has been an independent study for me to work on. Considering when I started I didn't know anything about electronics this has been quite the learning experience. I really like how your panel looks, deadlines made me make the call to use wood instead of metal and its alright.

Edited by EccentricTea
Link to comment
Share on other sites

  • 1 month later...

helluu again... 

on KSP 1.7 (1)  64bit W7 , the Serial V14 with codebase 0.18.4a  seems broken. The controls are booting, then stop at the vessel and went offline. 
bye bye old IOs...   sorry Zitronen for that first pitty message...   

 

Edited by sec3
Link to comment
Share on other sites

i´ll let ya know.
 

edit: the  019-1  / V017 code bare minimum works stable. only traps were    1. com port  (com02; win7 manual adjustment)  2. throttle (comment out the cpacket.throttle part).   At 3000ms buffer the science! mod made a dropout; the game froze some time, but booted up well. 

 

Edited by sec3
update
Link to comment
Share on other sites

Don't know which arduino board you are using, but if your code is getting complex you can try reducing the update rate in the .cfg file or increase the arduino serial buffer in HardwareSerial.h with the downside of losing some RAM.

Link to comment
Share on other sites

thanx for the tipps again;   

Did they altered something in KSP 1.7, the old code does not "understand" in the serials section? the other Versions worked well.

should i try an external power supply for  a  20x4  i2C  lcd / a short  2812 strip  on 15% brightness; (switches doesn´t matter) ?  
using UNO old 328 p and r3; no difference. 

Link to comment
Share on other sites

On 6/8/2019 at 4:55 PM, sec3 said:

thanx for the tipps again;   

Did they altered something in KSP 1.7, the old code does not "understand" in the serials section? the other Versions worked well.

should i try an external power supply for  a  20x4  i2C  lcd / a short  2812 strip  on 15% brightness; (switches doesn´t matter) ?  
using UNO old 328 p and r3; no difference. 

I just checked, with KSP IO version 0.19.1, arduino Demo 17, everything is working in KSP 1.7.1 with all the expansions (making history, breaking ground). Are you sure you have the right version of the plugin? Can you post the debug log?

Edited by zitronen
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

Hi,

I'm using your code and I'm adapting it to my project.

I would like to be able to read some ship systems state, like RCS.

And do some action if RCS are ON or OFF.

I'm using the following line to check RCS state :

if (getMainControls(RCS) == 0) {

With the following :

byte getMainControls(byte m) {
  return CPacket.MainControls == (1 << m);
}

But I'm really not sure of this. It seems to work. Anyway can you confirm this is the correct and best way to read RCS state ?

Thanks !

Edited by Tabb
Link to comment
Share on other sites

@Tabb

It would definitely tell what your code think the control state is. However, if you change vessels, it might be out of sync.

In the VesselData struct, look for the UInt16 ActionGroups (VData.ActionGroups if you program looks anything like most here), it holds RCS status in second bit. However, the order of ActionGroups is not the same as MainControls, so you need to take care not using the RCS alias. I would go

#define RCSSTATE 15

And your check could be

if (getMainControls(RCSSTATE) == 0) {

With getMainControls defined as below:

byte getMainControls(byte m) {
  return VData.ActionGroups == (1 << m);
}
Edited by Freshmeat
Link to comment
Share on other sites

On 7/28/2019 at 2:41 PM, Freshmeat said:

@Tabb

In the VesselData struct, look for the UInt16 ActionGroups (VData.ActionGroups if you program looks anything like most here), it holds RCS status in second bit. However, the order of ActionGroups is not the same as MainControls, so you need to take care not using the RCS alias. I would go 

Yep this works fine.

Except that if I clic on the RCS ingame button, it turns on of course, but then I can no longer use the arduino button to turn it on/off. And if I clic on it again, it turns off, and then I can use the arduino button again to control it.

I can't explain that.

EDIT Again : I think I found where it comes from. I guess this is because of the following lines (1081). But I have not idea how to remove them from the compiled plugin.

if (KSPSerialPort.VControls.RCS != KSPSerialPort.VControlsOld.RCS)
{
ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.RCS, KSPSerialPort.VControls.RCS);
KSPSerialPort.VControlsOld.RCS = KSPSerialPort.VControls.RCS;
//ScreenMessages.PostScreenMessage("RCS: " + KSPSerialPort.VControls.RCS.ToString(), 10f, KSPIOScreenStyle);
}

 

EDIT : Made a short video to show you what it does :

 

Edited by Tabb
Link to comment
Share on other sites

I'm trying to help Tabb out here, but I forgot how to set Visual Studio up with the proper library references. I'm missing Unity (although installed) and Assembly-CSharp. Anybody on here with a tip for me?

 

EDIT: I copied over my Includes folder, which I was smart enough to save way back when I built my KSPIO fork and added the required files to the references. It builds! Now let's hope it works.

Edited by hugopeeters
Link to comment
Share on other sites

  • 2 weeks later...
On 6/15/2019 at 12:35 PM, zitronen said:

I just checked, with KSP IO version 0.19.1, arduino Demo 17, everything is working in KSP 1.7.1 with all the expansions (making history, breaking ground).

Hey Zitronen, thank you for this mod and for the continued attention to it.

I'm curious, is there a reason why you've decided not to mark is as compatible with newer KSP versions for CKAN?  Is it a matter of not being able to do enough testing to validate that it's actually compatible?

Thanks again!

*edit* I'm very new to hobby electronics, but I loaded up your demo with LEDs and it's worked.

Edited by tsaven
Link to comment
Share on other sites

Awesome mod, I'm grateful you've kept it updated!

I'm currently building a control box based off of Hugo Peter's awesome design (https://www.instructables.com/id/KerbalController-a-Custom-Control-Panel-for-Rocket/), however, I've run into one issue I can't solve.

Whenever there is any input on the joysticks, SAS turns off. It turns back on once there is no longer any input on the joystick , however, it reverts back to mode 1.  I would like SAS to stay on in the mode i have it set for while I input control on the joysticks. Any help is greatly appreciated. Here is the code Hugo included with the instructable:

      if(analogRead(pRX) >= 530){CPacket.Yaw = constrain(map(analogRead(pRX),1023,530,-1000,0),-1000,0);}
      else if(analogRead(pRX) <= 470){CPacket.Yaw = constrain(map(analogRead(pRX),470,0,0,1000),0,1000);}
      else {CPacket.Yaw = 0;}
      if(analogRead(pRY) >= 530){CPacket.Pitch = constrain(map(analogRead(pRY),530,1023,0,1000),0,1000);}
      else if(analogRead(pRY) <= 470){CPacket.Pitch = constrain(map(analogRead(pRY),0,470,-1000,0),-1000,0);}
      else {CPacket.Pitch = 0;}
      if(analogRead(pRZ) >= 565){CPacket.Roll = constrain(map(analogRead(pRZ),530,1023,0,1000),0,1000);}
      else if(analogRead(pRZ) <= 500){CPacket.Roll = constrain(map(analogRead(pRZ),0,470,-1000,0),-1000,0);}
      else {CPacket.Roll = 0;}
      //pRX is the pin for rotation control, x axis
      //pRY is the pin for rotation control, Y axis
      //pRZ is the pin for rotation control, Z axis

 

Link to comment
Share on other sites

On 8/11/2019 at 12:33 AM, tsaven said:

Hey Zitronen, thank you for this mod and for the continued attention to it.

I'm curious, is there a reason why you've decided not to mark is as compatible with newer KSP versions for CKAN?  Is it a matter of not being able to do enough testing to validate that it's actually compatible?

Thanks again!

*edit* I'm very new to hobby electronics, but I loaded up your demo with LEDs and it's worked.

No reason, just lazy and forgot! I think it's working fine with the latest KSP, I use it myself.

4 hours ago, Ray61 said:

Awesome mod, I'm grateful you've kept it updated!

I'm currently building a control box based off of Hugo Peter's awesome design (https://www.instructables.com/id/KerbalController-a-Custom-Control-Panel-for-Rocket/), however, I've run into one issue I can't solve.

Whenever there is any input on the joysticks, SAS turns off. It turns back on once there is no longer any input on the joystick , however, it reverts back to mode 1.  I would like SAS to stay on in the mode i have it set for while I input control on the joysticks. Any help is greatly appreciated. Here is the code Hugo included with the instructable:


      if(analogRead(pRX) >= 530){CPacket.Yaw = constrain(map(analogRead(pRX),1023,530,-1000,0),-1000,0);}
      else if(analogRead(pRX) <= 470){CPacket.Yaw = constrain(map(analogRead(pRX),470,0,0,1000),0,1000);}
      else {CPacket.Yaw = 0;}
      if(analogRead(pRY) >= 530){CPacket.Pitch = constrain(map(analogRead(pRY),530,1023,0,1000),0,1000);}
      else if(analogRead(pRY) <= 470){CPacket.Pitch = constrain(map(analogRead(pRY),0,470,-1000,0),-1000,0);}
      else {CPacket.Pitch = 0;}
      if(analogRead(pRZ) >= 565){CPacket.Roll = constrain(map(analogRead(pRZ),530,1023,0,1000),0,1000);}
      else if(analogRead(pRZ) <= 500){CPacket.Roll = constrain(map(analogRead(pRZ),0,470,-1000,0),-1000,0);}
      else {CPacket.Roll = 0;}
      //pRX is the pin for rotation control, x axis
      //pRY is the pin for rotation control, Y axis
      //pRZ is the pin for rotation control, Z axis

 

Hmm.. The joystick code has not been updated since KSP added SAS modes, might look into changing it in the future, it is kind of outdated. I suggest for now you can use a arduino leo or similar in USB joystick mode (google arduino usb joystick if you've not done it before), and just map your axis in KSP like a normal joystick. Frankly you will have a better experience since USB HID joysticks can have much faster refresh rates than my plugin, and you won't have any SAS problems.

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