Jump to content

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


zitronen

Recommended Posts

16 hours ago, zitronen said:

Unfortunately not right now. I think we talked about it back in the days. Getting more info in the controlpacket is easy, but getting things working with other mods will be annoying, you have to worry about which version of KSPSerialIO supports which version of AGE, for which version of KSP. When KSP updates you have to make sure both mods are updated. Then also you have to make sure things don't break for people who don't use AGE...

An easier work around is just to use an Arduino Leo in keyboard emulation mode and bind the keys to AG(R)E.

I understand. Thank you.

Now I'm testing a board from a cheap usb keyboard, to use it for adding more buttons to my controller without using Arduino pins.
May be I can do something with it.

I will share my experience when I get something that works.

Thanks again. See you in space

Link to comment
Share on other sites

  • 1 month later...

Had a question for anyone that's tinkered with the protocol of this mod. Has anyone modding the code to get multiple Arduinos to connect at once that they have code to browse? I'm thinking of splitting the workload across devices (each with specific data) and wanted to check if anyone had done something similar before I continue with my Frankenstein of a project.

Before anyone  says "I don't need multiple devices", please know that I've already extended the existing protocol to run most of the RPM variable set through KSPSerialIO. This is done through 412 bytes (so far) split across 3 different update protocols that update at different speeds. Only 174 bytes are updating at the fastest speeds. As I'm running a Teensy 3.6, I've yet to hit a speed limit that overflows the buffer, but I'm watching like a hawk with monitoring and timing checks.

Stress tests shows it works fine with 115200 baud and 50ms refresh, but I'm planning for longer term expansion plans. I figure it might be prudent to allow a compartmentalisation of the communication to give more throughput across multiple devices (using only one process in KSP) for when I need it.

Edited by cyberKerb
Link to comment
Share on other sites

On 7/6/2020 at 3:11 AM, cyberKerb said:

multiple Arduinos

- How to run multiple threads on Arduino?
- Use multiple Arduinos

 As for me, Stm32 + FreeRTOS looks more reasonable for this purpose.

Link to comment
Share on other sites

18 hours ago, Manul said:

Stm32 + FreeRTOS looks more reasonable for this purpose.

Thanks for the suggestion. I had a look and it seems to be a bit overkill for what I was after. It wasn't multi-threading arduinos that I was looking for, but rather a way for the process that runs in the mod DLL to talk to multiple arduinos so not all traffic is going to a single micro-controller.

I've still got to do some more testing, but so far I've changed the code and added a second SerialPort object called 'Port2' (existing object is SerialPort Port). I also changed some of the subroutines (sendPacket, Port_ReceivedEvent, etc...) so each part runs it's own code or I parameterise the code to pass which serial port to use, rather than assuming it's always the default port to process an instruction. Fingers crossed I can get it to work.

Link to comment
Share on other sites

I managed to answer my own question. After a rather late night of testing (2am here and going to bed now), I've found that it isn't too hard to just add another SerialPort object into the DLL code and so long as you are careful about the making sure the routines all work for the separated ports, it's certainly viable. It also lets me know that if I ever hit any limit of what I can push to my existing micro-controller or it gets too busy with whatever I'll be demanding of it, I can always bang on another connection to a separate micro-controller and pipe data to it as well.

Edited by cyberKerb
Link to comment
Share on other sites

15 hours ago, zitronen said:

Jesus.. When I started this I thought surely 255 bytes should be enough for everybody...

Well, I'd say for the vast majority, that will be fine for those whole don't want to code up some custom monstrosity. A KSP cockpit has so much data to display and the potential for sci-fi blinky-lights all around me was far too appealing. I'm regularly browsing aircraft cockpit builder forums looking for tips and tricks in both software and hardware.

Link to comment
Share on other sites

As i now know that usb-joy encoders exist ;-), i would never ever use the SerialIO for Keys/switches as inputs ... only for display. also reached out for a 3d-printer. awesome...

btw:  does the mod work for 1.10 ?   the party goes on. most of my 81 mods useless

Edited by sec3
Link to comment
Share on other sites

  • 2 weeks later...
On 7/16/2020 at 7:50 PM, sec3 said:

As i now know that usb-joy encoders exist ;-), i would never ever use the SerialIO for Keys/switches as inputs ... only for display. also reached out for a 3d-printer. awesome...

btw:  does the mod work for 1.10 ?   the party goes on. most of my 81 mods useless

Working fine for me so far, but I don't using everything available on my setup. Let me know if you have problems.

 

Edit: updated SpaceDock/CKAN

Edited by zitronen
Link to comment
Share on other sites

  • 5 weeks later...
On 10/21/2019 at 2:04 PM, zitronen said:

OK you do not want to put anything in "loop()", the loop needs to run very fast without being slowed down by slow LCD stuff. Put your LCD code in "input()" under the KSP receive data if statement like this:

 


if (KSPBoardReceiveData()){
    deadtimeOld = now;
    returnValue = id;
    switch(id) {
    case 0: //Handshake packet
      Handshake();
      break;
    case 1:
      Indicators();

      //LCD CODE HERE **************
      lcd.setCursor(0,0);
      lcd.print((long)VData.AP);
      lcd.setCursor(0,1);
      lcd.print((long)VData.PE);

      break;
    }

    //We got some data, turn the green led on
    digitalWrite(GLED,HIGH);
    Connected = true;
  }

 

Thanks for this answer. Solved the same problem for me!

Link to comment
Share on other sites

  • 2 weeks later...

Hi, I'm working on building my own Kerbal Controller (the physical side of it is nearly finished) and was trying to test this plugin on another Arduino using the light demo. Unfortunately, I haven't been able to get it to work. The first LED lights during the loading screen, but then my game briefly freezes (not responding) and the light goes off. It then stays off for the rest of the flight until I'm in the loading screen before launch again, after which the whole cycle repeats. I'm using the demo code exactly as is, running on Windows 10 with the latest KSP version. I do have a few mods installed (mod list below) through CKAN, however I installed KerbalSerialIO manually. Is there something I'm missing? Thanks for your help.

Mod list:
B9 Part Switch (B9PartSwitch v2.17.0)
Breaking Ground (BreakingGround-DLC 1.5.1)
Community Tech Tree (CommunityTechTree 1:3.4.2)
Kerbal Engineer Redux (KerbalEngineerRedux 1.1.7.2)
Kerbal Joint Reinforcement Continued (KerbalJointReinforcementContinued v3.5.1)
Making History (MakingHistory-DLC 1.10.1)
MechJeb 2 (MechJeb2 2.10.0.0)
Module Manager (ModuleManager 4.1.4)
Near Future IVA Props (NearFutureProps 1:0.6.3)
Stockalike Mining Extension (StockalikeMiningExtension 1.1.6)
Stockalike Station Parts Expansion Redux (StationPartsExpansionRedux 1.3.6)

Link to comment
Share on other sites

On 9/2/2020 at 4:22 PM, CommanderMAM said:

Nevermind, I had the wrong Arduino code. Apparently the code for demo 4 has a link to download v16, whereas the link below the plugin download is v17 that works.

Oops, I change the first post now.

Link to comment
Share on other sites

On 9/14/2020 at 5:12 PM, CommanderMAM said:

Hey, its me again, I was wondering if it was at all possible to control whether the keyboard controls for throttle are enabled via a switch? For example, if no input/low input, then throttle enable = 0, but if there's a high input then throttle enable = 1.

In the config file:

Enable value settings for axes:

0: The internal value (supplied by KSP) is always used.

1: The external value (read from serial packet) is always used.

2: If the internal value is not zero use it, otherwise use the external value. (Now default!!!)

3: If the external value is not zero use it, otherwise use the internal value.

 

So if you set ThrottleEnable to 3, then the plugin will use your arduino throttle when it's not 0. You could for example have a switch to only send 0 when it's off and send analog input when it's on.

Link to comment
Share on other sites

8 hours ago, requiembob said:

Hi there! Is anyone able to send packets through relating to Pitch, Roll, Yaw, TX, TY, or TZ?

I can't seem to get anything to input properly. It detects that something has been sent (and disables the SAS for the duration) however it does not actually send the packets!

Cheers,

K

Are you talking about controlling pitch yaw roll?
Maybe the axis config is set wrong to where KSP receives the data but ignores it? (See above)

Edited by c4ooo
Link to comment
Share on other sites

On 9/16/2020 at 6:41 AM, zitronen said:

In the config file:

Enable value settings for axes:

0: The internal value (supplied by KSP) is always used.

1: The external value (read from serial packet) is always used.

2: If the internal value is not zero use it, otherwise use the external value. (Now default!!!)

3: If the external value is not zero use it, otherwise use the internal value.

 

So if you set ThrottleEnable to 3, then the plugin will use your arduino throttle when it's not 0. You could for example have a switch to only send 0 when it's off and send analog input when it's on.

Thanks for the help, I did get it to where the throttle could be manually disabled via a switch. I then went on to do the same thing for the axis controls as well using the same switch, which (after almost posting an issue here only to realize my ground wire had come unplugged) is now working perfectly. Here's the code I'm using:

//throttle slide pot
    int THROTTLE = map(1018-analogRead(THROTTLEPIN),0,1018,0,1000);
    //switch
    if (!digitalRead(MASTERSWITCH)){
      CPacket.Throttle = constrain(THROTTLE,0,1000); 
      //joysticks rotational
      if(analogRead(pRX) >= 530){CPacket.Yaw = constrain(map(analogRead(pRX),660,530,-1000,0),-1000,0);} //calibrated
      else if(analogRead(pRX) <= 490){CPacket.Yaw = constrain(map(analogRead(pRX),490,360,0,1000),0,1000);} //calibrated
      else {CPacket.Yaw = 0;}
      if(analogRead(pRY) >= 530){CPacket.Pitch = constrain(map(analogRead(pRY),530,660,0,1000),0,1000);} //calibrated
      else if(analogRead(pRY) <= 490){CPacket.Pitch = constrain(map(analogRead(pRY),360,490,-1000,0),-1000,0);} //calibrated
      else {CPacket.Pitch = 0;}
      if(analogRead(pRZ) <= 490){CPacket.Roll = constrain(map(analogRead(pRZ),300,490,-1000,0),-1000,0);} //calibrated
      else if(analogRead(pRZ) >= 510){CPacket.Roll = constrain(map(analogRead(pRZ),510,700,0,1000),0,1000);} //calibrated
      else {CPacket.Roll = 0;}
      //joysticks translational
      if(analogRead(pTX) >= 530){CPacket.TX = constrain(map(analogRead(pTX),530,660,0,1000),0,1000);} //calibrated
      else if(analogRead(pTX) <= 490){CPacket.TX = constrain(map(analogRead(pTX),360,490,-1000,0),-1000,0);} //calibrated
      else {CPacket.TX = 0;}
      if(analogRead(pTY) >= 530){CPacket.TY = constrain(map(analogRead(pTY),660,530,-1000,0),-1000,0);} //calibrated
      else if(analogRead(pTY) <= 490){CPacket.TY = constrain(map(analogRead(pTY),490,360,0,1000),0,1000);} //calibrated
      else {CPacket.TY = 0;}
      if(analogRead(pTZ) <= 490){CPacket.TZ = constrain(map(analogRead(pTZ),300,490,-1000,0),-1000,0);} //calibrated
      else if(analogRead(pTZ) >= 510){CPacket.TZ = constrain(map(analogRead(pTZ),510,700,0,1000),0,1000);} //calibrated
      else {CPacket.TZ = 0;}

 

Now all that's left is the abort and stage arm toggle switches, some specific action group buttons (gear, comms, solar, brakes, etc), a numpad (for action groups in general plus time warp if it gets added), joystick buttons (for SAS states), LCD and its accompanying control switches, and the LED bar graphs (to show fuel levels and for the gods to torture me with). Will post pics/vids of it when I'm done coding and have made a proper case for it (right now its a nice clear laser-engraved acrylic faceplate balanced on a cardboard box). Thanks again for the help!

Link to comment
Share on other sites

  • 4 weeks later...

@zitronen Hey, What exactly was the point of the turn-off-sas when joystick-was-used code? I was trying to improve joystick input a little and noticed that sas was turned off with joystick input. Seems like this was introduced in 18.3. 

Edited by c4ooo
Link to comment
Share on other sites

yXXzVIu.png

Hmm, looks like your post disappeared :P 

Anyways, I removed the disable-sas code in my own plugin, and it seems to work fine. I based a lot of my TCP plugin on yours, so I think it may be worth a shot in your plugin too. Maybe the internals of how input is handled got changed sometime after you added joystick input? 

The reason I brought this up is becouse I was looking through Advanced Fly By Wire  and noticed that it doesn't disable SAS on joystick input. https://github.com/linuxgurugamer/ksp-advanced-flybywire/tree/master/AFBW

Edited by c4ooo
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

I'm new to KSP, and just got a Teensy 3.0 working with Windows 10. This plugin is AWESOME!!!!  Thank you!

 

I am working on replicating some of the UI in hardware, and on the Advanced Orbital Info tab, there is the LAN and ARG PE values, which I do not see in the VesselData. Is this available somewhere, and is it used often? I am reliably getting to orbit, and have managed to orbit Mun, but I'd like to get a cockpit going before I get too far in the game, so I'm not sure how much I will need that data to match orbits / orbit another body / docking.

 

Also, what is VesselData.VVI?

 

Thank you,

Bryan.

Link to comment
Share on other sites

Welcome around, and gratulations on the Mun orbit.

VVI is IIRC vertical velocity.

There is a lot of info unavailable in VesselData, including orbital parameters. But unless you are a college level physics student, you will find little use for the things omitted, if any at all. That being said, if you want to make your own autopilot, you will need it, and are probably better served with kRPC, or a combined KSPSerialIO/kRPC control panel.

Link to comment
Share on other sites

Update 0.19.3b:

Changes:

  • Ok so not sure when this happened, but it seems you no longer have to disable SAS to update vessel controls, so the annoy issue of having to disable SAS to move an axis is gone (the whole business with SASTol no longer an issue, it now doesn't do anything). Now the axis control behaves like normal joystick input. I didn't do anything apart from remove the check and doing some testing. Please let me know if this is actually fixed, that would be great! Thanks to @c4ooo for letting me know.
  • Also recompiled against 1.10.1

Plugin download link:

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

Arduino code dowload (same as before):

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

17 hours ago, gt3073b said:

I'm new to KSP, and just got a Teensy 3.0 working with Windows 10. This plugin is AWESOME!!!!  Thank you!

 

I am working on replicating some of the UI in hardware, and on the Advanced Orbital Info tab, there is the LAN and ARG PE values, which I do not see in the VesselData. Is this available somewhere, and is it used often? I am reliably getting to orbit, and have managed to orbit Mun, but I'd like to get a cockpit going before I get too far in the game, so I'm not sure how much I will need that data to match orbits / orbit another body / docking.

 

Also, what is VesselData.VVI?

 

Thank you,

Bryan.

Basically what @Freshmeat said. Because we use the serial port, and need to support lower end arduino boards without a lot of RAM, we can't just send all the data. That's the limitation of this plugin. I never thought people would want to sending so much data to the arduino at the beginning. Surely 250 bytes ought to be enough for everybody.

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