Hey Fellow Tinkers,
I've been lurking for awhile and jumped in to building my own controller a couple weeks back. Gotten staging and action groups going no problem. Tonight I set up two four axis joysticks, which worked with a bit of helped from past posts. However, i'm having trouble setting a deadzone (or some sort of restraint that limits the input until its reach a certain threshold, one way or another). Currently the crafts end up fairly unstable (basically spinning faster and faster until its out of control in orbit...) as I believe the Joysticks may be providing a slightly off centre inut when nothing is pressed. I'm super excited to keep going with this build so I'd really appreciate some insights as to how to get this sorted out. Thanks in advance and thanks so much for all the inspiration! I never would've thought i could've done this two months ago.
#include "KerbalSimpit.h"
KerbalSimpit mySimpit(Serial);
rotationMessage myRotation;
translationMessage myTranslation;
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);
mySimpit.registerChannel(TRANSLATION_MESSAGE);
// This loop continually attempts to handshake with the plugin.
// It will keep retrying until it gets a successful handshake.
while (!mySimpit.init()) {
delay(100);
}
// Turn off the built-in LED to indicate handshaking is complete.
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
//ROTATION//
//Pitch - Back and Forward on Joystick//
int pitchRead = analogRead(A0);
int pitchR = map(pitchRead, 0, 1023, -32768, 32767);
myRotation.mask = 1;
myRotation.pitch = pitchR;
mySimpit.send(ROTATION_MESSAGE, myRotation);
delay(1);
//Yaw - Side to Side on Joystick//
int yawRead = analogRead(A1);
int yawR = map(yawRead, 0, 1023, -32768, 32767);
myRotation.mask = 4;
myRotation.yaw = yawR;
mySimpit.send(ROTATION_MESSAGE, myRotation);
delay(1);
//Roll - Twist Joystick//
int rollRead = analogRead(A2);
int rollR = map(rollRead, 0, 1023, -32768, 32767);
myRotation.mask = 2;
myRotation.roll = rollR;
mySimpit.send(ROTATION_MESSAGE, myRotation);
delay(1);
//TRANSLATION//
//X - XX//
int XRead = analogRead(A3);
int XR = map(XRead, 0, 1023, -32768, 32767);
myTranslation.mask = 1;
myTranslation.X = XR;
mySimpit.send(TRANSLATION_MESSAGE, myTranslation);
delay(1);
//Y - YY//
int YRead = analogRead(A4);
int YR = map(YRead, 0, 1023, -32768, 32767);
myTranslation.mask = 4;
myTranslation.Y = yawR;
mySimpit.send(TRANSLATION_MESSAGE, myTranslation);
delay(1);
//Z - ZZ//
int ZRead = analogRead(A5);
int ZR = map(ZRead, 0, 1023, -32768, 32767);
myTranslation.mask = 2;
myTranslation.Z = ZR;
mySimpit.send(TRANSLATION_MESSAGE, myTranslation);
delay(1);
}