Jump to content

[KSP 1.10.0] Kerbal Simpit: A KSP serial mod for hardware controllers (1.4.1)


stibbons

Recommended Posts

8 hours ago, TrainWreck said:

Are there any plans to include the SAS headings as controllable items (e.g. hold prograde, hold retrograde, etc.)? I looked through the docs and it doesn't look like this is available currently. Are you open to accepting pull requests if you don't have the time to put in anymore?

Hi!

Over recent months my development on this code (and playing KSP) has slowed some. I'm trying to get back in to it recently but, you know, life. :)

SAS mode control is on the list of things I'd like to get done - you can see my planned progress at https://trello.com/b/t6YUftuS/kerbal-simpit-progress . That said, pull requests would be very, very gratefully received. Have a look at the other providers and https://bitbucket.org/pjhardy/kerbalsimpit/wiki/PluginHacking.md to get started writing code if that's what you'd like to do.

Link to comment
Share on other sites

EDIT: oops, I didn't see the reply from Stibbons.

I was able to get SAS modes to work by using a kOS module and including a script that attaches modes to extended action groups, but that's a bit of a forced solution.

Edited by Codapop
Link to comment
Share on other sites

  • 2 weeks later...

I'm having some trouble getting analog controls to work. I am using a slide pot for debugging purposes, and I am able to get it to control the throttle, but adapting that code to control rotation is producing no results. Here's the code:

#include "KerbalSimpit.h"

KerbalSimpit mySimpit(Serial);

rotationMessage myRotation;

void setup() {
  Serial.begin(115200);

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  while (!mySimpit.init()) {delay(100);}
  digitalWrite(LED_BUILTIN, LOW);

  mySimpit.registerChannel(ROTATION_MESSAGE);
}

void loop() {
  int pitchRead = analogRead(A0);
  int pitchR = map(pitchRead, 0, 1023, -32768, 32767);
  myRotation.pitch = pitchR;
  myRotation.yaw = pitchR;
  myRotation.roll = pitchR;
  mySimpit.send(ROTATION_MESSAGE, myRotation);
  delay(1);
}

Based on the code, the p/y/r of the vessel should all move together, but nothing happens when I move the potentiometer. The LED_BUILTIN turns off indicating a connection. Similar code works with the same hardware to control the throttle, so I'm probably missing some key component in my code.

Also, is there a way to upload new code to the arduino while KSP is running? It's a bit of a pain to have to close out of the game and reopen just to edit the code.

EDIT: Also is there a way to allow for keyboard functionality while Simpit is running?

Edited by Codapop
Link to comment
Share on other sites

Quote

Also, is there a way to upload new code to the arduino while KSP is running? It's a bit of a pain to have to close out of the game and reopen just to edit the code.

If you have an ISP (or another Arduino board) I think you should be able to upload sketches that way. Googling "arduino upload sketch without usb" returned some seemingly useful results for me.

Quote

EDIT: Also is there a way to allow for keyboard functionality while Simpit is running?

I don't remember the keyboard being disabled when I was testing, but I can't say for sure until I can test again at home.

Link to comment
Share on other sites

On 11/27/2018 at 3:55 AM, TrainWreck said:

If you have an ISP (or another Arduino board) I think you should be able to upload sketches that way. Googling "arduino upload sketch without usb" returned some seemingly useful results for me.

I don't remember the keyboard being disabled when I was testing, but I can't say for sure until I can test again at home.

So you're saying I should unplug it and upload and then plug it back in while the game is running? That may work, but I think a simple command to Simpit to disconnect, or some sort of basic UI (like an on/off button) would be a great addition if it isn't already included.

The keyboard issues might have just been something with my code or machine. I'll do some more testing with it once I figure out the analog code problem I posted above.

Link to comment
Share on other sites

I have replicated Codapop's code for the most part in my setup with the same results. In my setup I have a slide pot controlling the throttle, and the same value is also sent to the ROTATION_MESSAGE.

  throttleValue = analogRead(throttlePin);
  throttleValue = map(throttleValue, 0, 1023, 32767, 0);

  mySimpit.send(THROTTLE_MESSAGE, (unsigned char*) &throttleValue, 2);

  rotation.pitch = throttleValue;
  rotation.yaw = throttleValue;
  rotation.roll = throttleValue;
  mySimpit.send(ROTATION_MESSAGE, rotation);

In KSP, when I move the slide pot the throttle works fine, but no movement on any of the rotational controls.

 

EDIT:

On looking through the code on bitbucket (finally), it looks like the below callback is handling the rotational control messages. There is a bitwise and operation being performed against newRotation.mask, but I can't see newRotation.mask actually getting set anywhere. IIRC (and my memory of C# is pretty rusty, so I could easily be wrong) structs are always pre-zeroed, and performing a bitwise & against 0 is always going to give you zero. If all of the above is correct, it would make sense that nothing you send in will do anything, because the code will always evaluate it to zero! Stibbons, please correct me if I'm wrong here!

public void vesselRotationCallback(byte ID, object Data)
        {
            
            newRotation = KerbalSimpitUtils.ByteArrayToStructure<RotationalStruct>((byte[])Data);
            // Bit fields:
            // pitch = 1
            // roll = 2
            // yaw = 4
            if ((newRotation.mask & (byte)1) > 0)
            {
                myRotation.pitch = newRotation.pitch;
            }
            if ((newRotation.mask & (byte)2) > 0)
            {
                myRotation.roll = newRotation.roll;
            }
            if ((newRotation.mask & (byte)4) > 0)
            {
                myRotation.yaw = newRotation.yaw;
            }
        }

EDIT 2:

After further review, the fix was incredibly simple like @Codapop expected, and I was just over-complicating things. All I did was add

rotation.mask = (byte)7;

To the code above and the throttle works as expected. Set rotation.mask based on which of the 3 axis' are getting updated (see lines 59-66 here. Luckily, debugging this (admittedly self inflicted) issue finally got me to pull down the repos and set up my make environment. Hopefully I'll be able to find time to work on them a little bit and open some pull requests.

Edited by TrainWreck
New information
Link to comment
Share on other sites

@codapop I second the simple on/off button. I am currently planning my own control panel now and hope to get started within the next few days. From previous experience with arduino, being able to have a disconnection/reconnection option available without restarting programs is a godsend. Going from prior experience in python, implementing a disconnect/reconnect feature is just a matter of reworking the initial start connection and end connection code. I may have a look at the code in more detail tomorrow, and see if I can work out at least some psuedocode for potential implementation. 

Link to comment
Share on other sites

Okay, I have just had some time to look over the code, to see about adding in a way to terminate and reopen a serial connection, without restarting the game/mod. @stibbons is it possible to break out the code currently in the start method that is responsible for calling the various commands and functions to create and initialise the serial port, into its own function? This function could then be used to initialise the various data structures to be in the required state to create a new serial connection, and then start the connection. Something similar could also be used for the termination of the port?

These methods could then possibly be linked to a simple toggle button in game, that can be used to toggle the connection status.

Link to comment
Share on other sites

On 12/5/2018 at 1:13 PM, TrainWreck said:

After further review, the fix was incredibly simple like @Codapop expected, and I was just over-complicating things. All I did was add


rotation.mask = (byte)7;

To the code above and the throttle works as expected.

Well, dang. Apologies for the dumb bug, and thanks for sorting it out, @TrainWreck. Can I assume the PR for SAS mode is from you too? I'll make sure I can merge that, and get this fix in a new release this week.

On 12/5/2018 at 1:13 PM, TrainWreck said:

Luckily, debugging this (admittedly self inflicted) issue finally got me to pull down the repos and set up my make environment.

I really hope getting set up to actually build the plugin wasn't too hard. Tried to document it thoroughly, but have never heard of anybody else trying to do it. Please let me know if there's anything that wasn't clear, or that could be done better.

9 hours ago, LRTNZ said:

Okay, I have just had some time to look over the code, to see about adding in a way to terminate and reopen a serial connection, without restarting the game/mod. @stibbons is it possible to break out the code currently in the start method that is responsible for calling the various commands and functions to create and initialise the serial port, into its own function?

Possible, but I'd avoided it because adding UI code seemed massively complicated, and to be honest I've only really thought of the dev loop in terms of getting the plugin and arduino library functional. Actually hacking on serious controller code isn't something that I'd considered, sorry.
I've added manual disconnect/reconnect at runtime to my backlog.

Link to comment
Share on other sites

@stibbons Having looked around some more, I think I may have found a simpler solution for the serial stream: To just add a command to the in game debug terminal. Now, my C# programming experience is next to none, only having used it for some very basic things in a unity project I was tinkering with. However, as I am currently have a few months of holiday I am quite happy to have a go at getting the terminal command going ( Just will have to learn C# to do it, something I have been meaning to do anyway) If I do get the command functioning would you be happy to take the code and change it to match your preferred syntax/stylising and add it to your main code? This is just so I know whether to approach it as "Its just me using it, I can deal with it being bodged and hacky" ,vs "Ok, got to get it right, other people are potentially using it".

On a side note, is it possible to enable an issue tracker on the repository itself, to keep track of issues and suggestions in the same location as the code?

Link to comment
Share on other sites

@stibbons your instructions for pulling down and starting development were actually pretty spot on. There were a few extra packages required for my system to be able to run make correctly, but that's on me and not your documentation. That is indeed my pull request.

On 12/10/2018 at 6:29 AM, stibbons said:

Well, dang. Apologies for the dumb bug, and thanks for sorting it out,

This is actually not a bug at all! Your Arduino library code very clearly documented that the line I mentioned was required, and I just didn't notice it. the (byte)7 is reasonable to me, as this was just test code and any reasonable implementation would have that in a byte variable anyway.

Link to comment
Share on other sites

On 12/15/2018 at 2:28 AM, TrainWreck said:

This is actually not a bug at all! Your Arduino library code very clearly documented that the line I mentioned was required, and I just didn't notice it. the (byte)7 is reasonable to me, as this was just test code and any reasonable implementation would have that in a byte variable anyway.

I had to go and read up on all of this stuff again, because it'd been a while since I looked hard at this code, sorry. And I realised that hardcoding magic numbers like that isn't much fun. So I've added constants for the rotation and translation masks, similar to the action group constants. You can set the mask like this now:

rotation.mask = PITCH_ROT|ROLL_ROT|YAW_ROT;

 

On 12/12/2018 at 8:41 PM, LRTNZ said:

Now, my C# programming experience is next to none, only having used it for some very basic things in a unity project I was tinkering with.

Heh, if it makes you feel any better, this is pretty much my first C# project too (after some small contributions to other KSP plugins).

On 12/12/2018 at 8:41 PM, LRTNZ said:

If I do get the command functioning would you be happy to take the code and change it to match your preferred syntax/stylising and add it to your main code?

YES. Definitely. Contributions are very welcome, and using the debug terminal like you're suggesting sounds great.

Note that the way the plugin is built is currently a little idiosyncratic, I'm generating the .csproj and AssemblyInfo files dynamically, which may not play nicely with IDEs like VS and monodevelop without some work. https://bitbucket.org/pjhardy/kerbalsimpit/wiki/PluginHacking.md has some details on getting set up to build it.

On 12/12/2018 at 8:41 PM, LRTNZ said:

On a side note, is it possible to enable an issue tracker on the repository itself, to keep track of issues and suggestions in the same location as the code?

For what it's worth, I've been using a trello board at https://trello.com/b/t6YUftuS/kerbal-simpit-progress to track what I'm doing. But that's not easily accessible to people who aren't me. So, sure, I've just turned on the issue tracker on the bitbucket project - https://bitbucket.org/pjhardy/kerbalsimpit/issues

 

After fighting with my deployment environments for a while, there's a new release of the Kerbal Simpit plugin. 1.3.0 includes a new command channel to set the SAS mode, thanks to @TrainWreck. CKAN should have it in the next few hours.

The Arduino library has also bumped to version 1.2.1. This includes the bits needed so your Arduino can send SAS mode commands, which look a lot like this:

mySimpit.setSASMode(AP_RETROGRADE);

I've also added some constants to make setting the mask on rotation and translation commands a little more intuitive. The Arduino library manager should have the new release shortly as well.

Link to comment
Share on other sites

16 minutes ago, stibbons said:

Heh, if it makes you feel any better, this is pretty much my first C# project too (after some small contributions to other KSP plugins).

@stibbons Well, I seem to be picking it up okay. The general consensus of once you have done programming with a common OOP language, working with another will not be to hard seems to be holding true. Not to mention learning it is handy for me, as I will need it in my final year of secondary education next year, then probally at uni as well.

21 minutes ago, stibbons said:

YES. Definitely. Contributions are very welcome, and using the debug terminal like you're suggesting sounds great.

Sweet, because I am hopefully going to get these commands going soon, and hopefully my code opens up new doorways to simplify future development for everyone. 

I found this example on the usage of the terminal commands, and have spent the past day and a bit just converting that code over to something that will work for this plugin. The terminal commands are surprisingly easy to add ( Well, having never worked with KSP addons before, I am going off experience with other programming), as long as you remember to add their ".cs" files to the serial ".csproj" file so they get compiled into the dll… :blush:. Yeah, that took me a bit longer than I care to admit to work out. Okay, okay , I think it may have been an hour … or two before I facepalmed. Currently, I have help commands running, in the form "/sim help <command>"
I have settled on "sim" as the "identifier"(? or whatever the correct term is for it) for the commands that I am developing, although it is easy enough to change it if so required. I am going to start attacking the serial start/stop commands tomorrow ( Well, more like later today ), and if all goes well I may have a very WIP version submitted in the next couple of days.

29 minutes ago, stibbons said:

Note that the way the plugin is built is currently a little idiosyncratic, I'm generating the .csproj and AssemblyInfo files dynamically, which may not play nicely with IDEs like VS and monodevelop without some work. https://bitbucket.org/pjhardy/kerbalsimpit/wiki/PluginHacking.md has some details on getting set up to build it.

I actually did not find it to bad to get going. After having tried Visual Studio by itself to no avail, I then tried VS Code. I gave up on that, as trying to program without having the ability to "go to definition" was going to make things a nightmare. Anyway, went back to Visual Studio, and it just worked with importing the existing code as a project. However, the second time I tried it, I had pulled the repo down again, having deleted it locally, so that is probally what did it.

To compile, I am just running the makefile using "GNU make" running on a Debian Linux Shell( Purely personal preference, as it is the distro that I regularly use if I am not on Windows 10), with the install option to have the DLLs automatically get moved to the games install location. Thank you for including that [ the install argument ], it has greatly simplified the building and testing process.

To those who want to develop this code in an IDE, I recommend going the route that was recommended here.
For Win 10 users: I enabled the Windows Linux Feature, installed the Debian GNU/Linux shell from the windows store, and then installed the recommended packages.  I then setup symlinks from the required sections in the KSP install to the main project file at the same level as the makefile. Following this, I then edited the makefile to use the local symlinks in the project folder, instead of having them recurse from the top of the install drive, to the game files.

NB: BEFORE attempting to install the packages, you need to edit the "sources.list" file, to have the source links be "trusty main restricted". I am not sure on the reasoning, I just know that without that it will REFUSE to install the packages. I think it was more to do with the shell running on windows than anything, from what I briefly read.

@stibbons Would it be worth looking into a documentation tool like doxygen for this project? This may make it easier for multiple people to keep track of the code structure, as well as making it easier for other people to come onboard and work with the code in the future? I have never worked with a documentation tool like that before, but to my understanding doxygen is one of the more commonly used ones for generating documentation for projects?

52 minutes ago, stibbons said:

So, sure, I've just turned on the issue tracker on the bitbucket project - https://bitbucket.org/pjhardy/kerbalsimpit/issues

Sweet! This should definitely make it easier for all of us to keep track of what is going on/needs fixing!

Link to comment
Share on other sites

7 hours ago, LRTNZ said:

For Win 10 users: I enabled the Windows Linux Feature, installed the Debian GNU/Linux shell from the windows store, and then installed the recommended packages.

That works? Awesome! I'd wondered, but hadn't found the time to actually boot my one Windows install to try it out. Thank you so much for letting me know how you're going doing this stuff on Windows.

7 hours ago, LRTNZ said:

Would it be worth looking into a documentation tool like doxygen for this project?

The arduino library is all doxygenised, which is how https://kerbalsimpit-arduino.readthedocs.io/en/stable/ is generated. But, once again, I've been working on the plugin code with the assumption nobody else would read it. ;) Pretty much all of the documentation that's there was intended to be notes to myself. But properly documenting what's there sounds like a good plan.

Link to comment
Share on other sites

@stibbons Just a brief update:

I am taking a tad longer than I expected to get the code in a state that I consider good enough state to be considered for implementing into a releasable version. Mainly due to that fact that as I am learning c# while programming the commands, I have ended up finding better ways to do most things, and have then gone and reworked chunks of code. I also may have implemented localisation to my code, and the commands. That actually was not to bad to do, once I worked out the way I think is best in our case to store the tags for the localizer. It also meant that I had to rework some of the code for processing the commands, which actually resulted in it being more reliable, cleaner, and more flexible to running without being dependent on the values for commands being hardcoded in, as to be localised they need to be in the localisation file. 

Anyway, all my code that puts anything into the terminal has an English localisation , and my mate @meh? has just translated it into German, which I will test tomorrow. I have gotten the serial port code extracted from the start method, into its own method, and have it being called by a command. The testing of that code is a job for tomorrow. Fingers crossed it all goes well, and that I have the code in a state to be pulled in, so everyone can begin trialling the commands.

Link to comment
Share on other sites

@stibbons Well, I do have the commands working now. They are still in their early stages of development, but the framework is now all there. I did submit a pull request for review the other day, so that you and others can take a look at the code, and offer suggestions on what may need to be adjusted for it to be added to the main branch. I am planning to start more development on my actual simpit, so I will probally shift towards the hardware/Arduino side of things for the next little while. However, if there are issues with my code/you would like me to change and work on some things I am more than happy to do so ( Will give me something to do while waiting for my 3D printer to print out prototyping parts for my simpit). Also, if I find any issues with my terminal command code while developing my simpit, I will be sure to submit a pull request for a bugfix. 

Depending on the reception by the users of your addon to the addition of the commands, and if people do find them useful, I may potentially end up developing an in game GUI button/panel for those who would rather not use the debug console.

Something else that is worth noting with the serial stopping and starting: When you have disconnected the serial port from the game, the Arduino IDE can then claim it and program the device. However, once the Arduino IDE has programmed the device, you need to press the reset button on the device that has just been programmed, so that it's serial port is properly released from the IDE, before trying to reconnect it to KSP.

Also, if you disconnect the serial port from KSP while in a flight, you cannot reconnect the device and have it take over the flight controls without having left and re-entered the flight view. I assume this is due to when KSP attaches the controls to a vessel, and I am yet to look into the code enough to see if there is a possible fix.

Link to comment
Share on other sites

10 hours ago, LRTNZ said:

I did submit a pull request for review the other day, so that you and others can take a look at the code, and offer suggestions on what may need to be adjusted for it to be added to the main branch. I am planning to start more development on my actual simpit, so I will probally shift towards the hardware/Arduino side of things for the next little while. However, if there are issues with my code/you would like me to change and work on some things I am more than happy to do so ( Will give me something to do while waiting for my 3D printer to print out prototyping parts for my simpit).

I saw! Thank you so much for that. :) I haven't yet had a chance to go over it properly, sorry, holiday season and all. Will add some comments to the PR soon though, and think long and hard about starting the ports automatically again.

10 hours ago, LRTNZ said:

Also, if you disconnect the serial port from KSP while in a flight, you cannot reconnect the device and have it take over the flight controls without having left and re-entered the flight view. I assume this is due to when KSP attaches the controls to a vessel, and I am yet to look into the code enough to see if there is a possible fix.

I've tried to write the plugin to support subscribing and unsubscribing from channels at any time (not least because that's something I would like to do for the ghetto MFDs on my controller). But I've never explicitly tested this, all of the arduino code I've written for this plugin so far subscribes in `setup()`, long before a flight scene is loaded. I wonder if something is going strange there.

Link to comment
Share on other sites

I forgot to add a few details in regards to the behaviour of the serial port attaching and detaching while the game is running. When the serial port is detached completely from the game on KSPs side of things, for it to reattach you need to leave and reenter the flight scene when you reconnect it. You can reconnect the serial port in the flight scene before you leave it, or once you have left it but before returning to it. The requirement though is at some point after reconnecting the serial port, for it to have its controls applied, you must have refreshed the flight scene. 

From memory, I think this is due to when the computer side of the code checks what gamescene/view the player is currently in when it goes to attach the commands, nothing to do with the arduino's code. Also, it could possibly be partially due to how I have the code terminating the running workers when the serial port is disconnected, with one of those potentially responsible for passing the users control panel input to KSP. I will look into this some more, and see if there is a way to reconnect the command passing from the add on to ksp, without the need to refresh the flight game view.

However, I will look at this, after I get the ports automatically connecting upon startup. I may look into how the config files are read, because maybe it should be a config option for the user to choose whether or not they want the port automatically connecting upon startup? For the automatic reconnection, I suspect I just need to change the code so there is a one time call when the game starts to the serial command to try start the connection.

I will most likely keep the serial command responsible for the creation of the KSPit instance, as it does mean the commands I have implemented are in control of the serial ports, and it does not run the risk of having 2 instances of the KSPit class trying to talk to the serial port/s. Although, if anybody with more experience in these matters has a better idea/s, I am all ears, and game to implement it if it will result in a better outcome. 

I have not tried the subscribing and unsubscribing on the arduino yet, however I do not see why my changes would have affected that in any way. I must say, of the arduino code I have used, the arduino library has all been wonderful, with the only issues having been computer side from the visual studio arduino plugin taking over the serial ports, even when it had never been told to connect.... So that plugin is disabled, and I am just using the arduino ide. 

On a side note, my mate @meh? does have some free time to do more German translating, if you would like him to do it for the verbose terminal outputs you have in the code? Would only take me about half an hour to find them all, and add them to the English localisation file, which can then be translated. Is this effort worthwhile, or do you think it may be to futile to worry about? 

Link to comment
Share on other sites

  • 2 weeks later...

Hej.

I was not active for a long time, but getting back at it again.

Is that correct:   mySimpit.send(THROTTLE_MESSAGE, (unsigned char*) &throttle, 2);

 

I don't know about the size, the 2 at the end. Found the 2 on the forum. Isn't this: sizeof((unsigned char*) &throttle) maybe a better solution? No, it's not. It's an array.

 

Hmmm, the throttle doesn't work. Anyone know why?

Edited by Benji
It does not work
Link to comment
Share on other sites

On 1/2/2019 at 2:06 PM, Benji said:

Hej.

I was not active for a long time, but getting back at it again.

Is that correct:   mySimpit.send(THROTTLE_MESSAGE, (unsigned char*) &throttle, 2);

 

I don't know about the size, the 2 at the end. Found the 2 on the forum. Isn't this: sizeof((unsigned char*) &throttle) maybe a better solution? No, it's not. It's an array.

 

Hmmm, the throttle doesn't work. Anyone know why?

//KerbalSimPit
#include <KerbalSimpit.h>
#include <KerbalSimpitMessageTypes.h>
#include <PayloadStructs.h>

KerbalSimpit mySimpit(Serial);


void initializeSimpit() {
      
  while (!mySimpit.init());
}

void updateSimpit() {
      
  mySimpit.update();
}

void sendACG(uint32_t acg) {

  if (acg == acgStage)
    mySimpit.activateAction(STAGE_ACTION);
  else if (acg == acgAbort)
    mySimpit.activateAction(ABORT_ACTION);
  else if (acg == acgLight)
    mySimpit.toggleAction(LIGHT_ACTION);
  else if (acg == acgGear)
    mySimpit.toggleAction(GEAR_ACTION);
  else if (acg == acgBrakes)
    mySimpit.toggleAction(BRAKES_ACTION);
  else if (acg == acgRCS)
    mySimpit.toggleAction(RCS_ACTION);
  else if (acg == acgSAS)
    mySimpit.toggleAction(SAS_ACTION);
  else
    mySimpit.toggleCAG(acg);
}

void sendSAS(uint32_t sas) {

  if (sas == sasStability)
    mySimpit.send(SAS_MODE_MESSAGE, AP_STABILITYASSIST, 1);
}

void sendThrottle(uint32_t throttle) {

  mySimpit.send(THROTTLE_MESSAGE, (unsigned char*) &throttle, 2);
}

Here's some more information...

The helper functions I used for action groups work like a charm.

Throttling does nothing.


'SAS Mode doesn't even compile:

error: 'AP_STABILITYASSIST' was not declared in this scope

SAS_MODE_MESSAGE' was not declared in this scope

 

 

I just found out that you're at 1.2.1 on bitbucket but the "by arduino loaded" library is at 1.1.5...

Edited by Benji
Link to comment
Share on other sites

I manually updated to the code on bitbucket.

SAS Modes are compileable now.

 

But they still don't work. Throttle still doesn't work.

I got 1.3.0.64 through ckan.

Is that correct?

Link to comment
Share on other sites

  • 3 weeks later...
On 1/7/2019 at 4:27 AM, Benji said:

I manually updated to the code on bitbucket.

SAS Modes are compileable now.

 

But they still don't work. Throttle still doesn't work.

I got 1.3.0.64 through ckan.

Is that correct?

 

I'm using the latest release on bitbucket (I think it was #64?) and used this code:

#include "KerbalSimpit.h"

KerbalSimpit mySimpit(Serial);

rotationMessage myRotation;

void setup() {
  Serial.begin(115200);

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  while (!mySimpit.init()) {delay(100);}
  digitalWrite(LED_BUILTIN, LOW);

  mySimpit.registerChannel(THROTTLE_MESSAGE);
}

void loop() {
  int pitchRead = analogRead(A0);
  int throttle = map(pitchRead, 0, 1023, -32768, 32767);
  mySimpit.send(THROTTLE_MESSAGE, throttle);
  delay(1);
}

This works well for me, though for some reason it seems to not register until the potentiometer reads above about 1/3. It's been this way for several months, so it's not a new development. My serial monitor shows the pot is working correctly. Stibbons do you happen to know why or how to fix this?

 

Also, I still can't seem to get rotation messages to work properly. I'm using this:

#include "KerbalSimpit.h"

KerbalSimpit mySimpit(Serial);

rotationMessage myRotation;

void setup() {
  Serial.begin(115200);

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  while (!mySimpit.init()) {delay(100);}
  digitalWrite(LED_BUILTIN, LOW);

  mySimpit.registerChannel(ROTATION_MESSAGE);
}

void loop() {
  int pitchRead = analogRead(A0);
  int pitchR = map(pitchRead, 0, 1023, -32768, 32767);
  myRotation.pitch = pitchR;
  mySimpit.send(ROTATION_MESSAGE, myRotation);
  delay(1);
}

I tried making some various changes to reflect the discussion above, but the information is sorta randomly talked about and difficult for me to understand with my limited coding knowledge. Can you please give a short example of how to write a proper rotation message?

Edited by Codapop
Link to comment
Share on other sites

49 minutes ago, Benji said:

Quick question:

What range of values does KSP expect?

Are the attitude and translation controls ranged from

-1024 to 1023 ,

-512 to 511 or

0 to 1023 ?

I believe Simpit expects 16-bit integers: -32768 to 32767.

So 0 on throttle is -32768, and 100% throttle is 32767. For rotation/translation it should still use the same intregers, but the program would interpret them differently (like -32768 is all the way left and 32767 is all the way right). When using Arduino, you map the input from the potentiometer to those integers. So the potentiometer reads a voltage, arduino reads that voltage as being somewhere between 0 and 1023, and then it gets mapped relative to -32768 and 32767 and then sent to Simpit.

Edited by Codapop
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...