Jump to content

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


zitronen

Recommended Posts

On 14/11/2016 at 9:24 PM, c4ooo said:

Do you guys think the arduino should receive what autopilot modes are available? 

Edit: setting / receiving SAS stuff works now :)

Edit 2: Pull request (hopefully) created :) [And hopefully works :P ]

OK That looks good, check github for reply.

Link to comment
Share on other sites

On 11/14/2016 at 8:34 PM, zitronen said:

@Mattew is correct, you need to disable handshake in the cfg file, and manually set the COM port in there as well, then it will work but without inputs. I probably need to add something to the first post to explain it better.

Also 18.3 is not compatible with KSP 1.1, please see first post for info.

Ok here is a copy of my config file,

<?xml version="1.0" encoding="utf-8"?>
<config>
    <double name="refresh">0.2</double>
    <string name="DefaultPort">COM1</string>
    <int name="BaudRate">38400</int>
    <int name="HandshakeDelay">3000</int>
    <int name="HandshakeDisable">2</int>
    <int name="ThrottleEnable">2</int>
    <int name="PitchEnable">2</int>
    <int name="RollEnable">2</int>
    <int name="YawEnable">2</int>
    <int name="TXEnable">2</int>
    <int name="TYEnable">2</int>
    <int name="TZEnable">2</int>
    <int name="WheelSteerEnable">2</int>
    <int name="WheelThrottleEnable">2</int>
    <double name="SASTol">0.05</double>
</config>

I have tried all I can to get it to work without the ch340 usb-ttl convertor (which I ordered) but I still can't get it to work. I've set the handshake to 2 and even changed my Comm Ports, (both in the config and on my arduino) Any thoughts on what I am doing wrong? Thanks.

Link to comment
Share on other sites

Finally got it my Arduino to work with this Plugin, (I disabled the handshake and upgraded to KSP 1.2). I have been playing around with it all day. One problem however. My throttle is stuck at around 25% and it flicks up and down a little bit. When I unplug the Arduino and reload from the VAB it stops. I disabled the throttle control in the config file but I get the same result. Any Ideas?

Link to comment
Share on other sites

2 minutes ago, zitronen said:

What did you set "ThrottleEnable" to? Is your arduino code still constantly sending throttle commands?

I set it to 1, it was set to 2 by default. Still getting it. If I press X it will go back to about 25% throttle, and when I tap shift once, it will fall to 0. that being said, the ship is still throttled to about 25%

Link to comment
Share on other sites

8 minutes ago, zitronen said:

Setting it to 1 means "The external value (read from serial packet) is always used. ", you need to set it to 0. Read the first post for details.

Ok, I'll try it. Thanks

EDIT: Yep that was it.

Edited by Freakout242
Showed answer
Link to comment
Share on other sites

Update 0.18.5:

Changes:

  • Added SAS mode input and output (thanks @c4ooo)
//SAS Modes
#define SMOFF           0
#define SMSAS           1
#define SMPrograde      2
#define SMRetroGrade    3
#define SMNormal        4
#define SMAntinormal    5
#define SMRadialIn      6
#define SMRadialOut     7
#define SMTarget        8
#define SMAntiTarget    9
#define SMManeuverNode  10

Arduino code example for changing mode:

if (digitalRead(SASPIN)) { //--------- This is how you do main controls
      MainControls(SAS, HIGH);
      CPacket.SASMode = SMSAS;
    }
    else {
      MainControls(SAS, LOW);
    }

Download link:

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

Arduino code:

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

Link to comment
Share on other sites

10 hours ago, c4ooo said:

Now let's just hope the code works :P

Yup... your future reputation on this forum is now based on how well this code does or doesn't work :D 

I have faith :) I'll have to wire up another arduino I got lying around to do some tests -- but if @zitronen feels confident the code is good, then I think you'll be ok! Thanks for the dev :cool:

Link to comment
Share on other sites

I'm glad to see that this is still developing. I've been wanting to build something like this for a while, but always thought it needed a navball. I've got an Arduino Mega 2560 drawing a nice navball on a 3.2" TFT LCD in under 80ms. I can orient the ball using the heading, pitch and roll values, but I would like to be able to show nodes as well (prograde, retrograde, target, maneuver node, etc). To even have a chance of calculating the orbit nodes, I will need the longitude of the ascending node and the argument of periapsis added to the output. I'm not sure how to handle maneuver nodes and target direction, but one thing at a time.

Link to comment
Share on other sites

Can someone see what I'm doing wrong? I'm running 1.2.1 in Ubuntu.

I extracted KSPSerialIO_018_5.zip to ~/.steam/steam/steamapps/common/Kerbal Space Program/GameData/KSPSerialIO

I edited ~/.steam/steam/steamapps/common/Kerbal Space Program/GameData/KSPSerialIO/PluginData/KSPSerialIO/config.xml and changed "COM1" to "/dev/ttyACM0"

I compiled and installed KSPIODemo15.zip onto an Arduino Mega, with an LED on pin 5.

My craft is a Mk1 command pod. When I launch this, the LED should turn on. It doesn't.

What am I doing wrong? What else can I check?

The log shows:

[LOG 22:03:43.176] KSPSerialIO: Version 0.18.5
[LOG 22:03:43.177] KSPSerialIO: Getting serial ports...
[LOG 22:03:43.177] KSPSerialIO: Output packet size: 200/255
[LOG 22:03:43.179] KSPSerialIO: Dude do you even win32 serial port??
[LOG 22:03:43.179] [AddonLoader]: Instantiating addon 'KSPSerialIO' from assembly 'KSPSerialIO'

and then

[LOG 22:04:13.426] [AddonLoader]: Instantiating addon 'SettingsNStuff' from assembly 'KSPSerialIO'
[LOG 22:04:13.426] KSPSerialIO: Loading settings...
[LOG 22:04:13.426] KSPSerialIO: Default Port = /dev/ttyACM0
[LOG 22:04:13.426] KSPSerialIO: Refreshrate = 0.2
[LOG 22:04:13.426] KSPSerialIO: BaudRate = 38400
[LOG 22:04:13.426] KSPSerialIO: Handshake Delay = 3000
[LOG 22:04:13.426] KSPSerialIO: Handshake Disable = 0
[LOG 22:04:13.426] KSPSerialIO: Pitch Enable = 2
[LOG 22:04:13.426] KSPSerialIO: Roll Enable = 2
[LOG 22:04:13.426] KSPSerialIO: Yaw Enable = 2
[LOG 22:04:13.426] KSPSerialIO: Translate X Enable = 2
[LOG 22:04:13.426] KSPSerialIO: Translate Y Enable = 2
[LOG 22:04:13.426] KSPSerialIO: Translate Z Enable = 2
[LOG 22:04:13.426] KSPSerialIO: Wheel Steering Enable = 2
[LOG 22:04:13.426] KSPSerialIO: Throttle Enable = 2
[LOG 22:04:13.426] KSPSerialIO: Wheel Throttle Enable = 2
[LOG 22:04:13.426] KSPSerialIO: SAS Tol = 0.05

 

Edited by boostme
Link to comment
Share on other sites

Okay, dumb question :DSAS mode changes work in way I just change SASMode byte while SAS is active,is that right? 

Example: Activate SAS mode by button on SASPIN, then in some convenient place in code I do "SASMode = 8" and whoala, my sas is set to "target". 

I do it right? I dont have time to actualy test in real :/

Link to comment
Share on other sites

3 hours ago, Mattew said:

Okay, dumb question :DSAS mode changes work in way I just change SASMode byte while SAS is active,is that right? 

Example: Activate SAS mode by button on SASPIN, then in some convenient place in code I do "SASMode = 8" and whoala, my sas is set to "target". 

I do it right? I dont have time to actualy test in real :/

I'm just sitting down to do some tests... hold tight :)

Update

Alrighty! It's pretty straightforward 

 

In "KSPIODemo15" Tab, define your input pin for the relevant SAS target (I'm using retrograde in my example):


#define SASRETRO 9

Then in the 'output' Tab, you need to let the system know that it's an input; so under the function 'controlsInit()' add your newly defined input pin:


void controlsInit() {
  // You should have all your other inputs here too
  pinMode(SASRETRO, INPUT_PULLUP);
}

Then, under the 'controls()' function, you need to add the call to read / react to the switch:


void controls() {
  if (Connected) {
 // You should have a heap of other code here too

    if (digitalRead(SASRETRO)) {
      CPacket.SASMode = SMRetroGrade;
    }

}

We're sending the data to the game to enable the craft to point to retrograde (great fun right after take off :D -- as I did with my testing!). Note: Certain SASMODES aren't available if the SAS don't know about it. ie. at take off you can't point anywhere except normal/antinormal, etc. as the buttons themselves are inactive. So you'll get a helpful text on the display saying "sasmode 3 is not available" or something to that effect. :)

So if you try to enable a mode that's not normally an option in the game (ie. greyed out button) then you can't force it via the buttons either).

 

@zitronen -
Just confirming, we don't need:   

else {
      CPacket.SASMode = SMOFF;
    }

After that SASRETRO read do we? 

(It works both with and without... given that  CPacket.SASMode = SMSAS; is set on SASPIN on, it would cause a lot of flip-flopping between the modes if SASPIN is on, but SASRETRO is off...)

Edited by Sputnix
Link to comment
Share on other sites

5 minutes ago, Mattew said:

Oh, good job! So if I understand that correctly, each mode is called separately on its own. If we want be simple as possible then we need just 10 switches (for each mode) and thats it?

Yup... that's how I'd do it :)

or I'm also thinking of using a selector switch to activate the necessary mode - since you can only have one at a time.

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