Jump to content

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


zitronen

Recommended Posts

Here is my log as requested. https://drive.google.com/file/d/0BywyT2cDCiRoR2pPa2ZSYk1WdlU/edit?usp=sharing

Thanks mulbin for the info.

also, here is something in the log that has to do with the IODemo

[LOG 01:37:21.646] AddonLoader: Instantiating addon 'KSPSerialPort' from assembly 'KSPSerialIO'

[LOG 01:37:21.649] KSPSerialIO: Version 0.14.3

[LOG 01:37:21.649] KSPSerialIO: Getting serial ports...

[LOG 01:37:21.649] KSPSerialIO: Output packet size: 129/255

[LOG 01:37:21.652] KSPSerialIO: Found 2 serial ports

[LOG 01:37:21.653] KSPSerialIO: trying default port COM1

[LOG 01:37:21.667] Error opening serial port COM1: CreateFile Failed: 2

[LOG 01:37:21.668] KSPSerialIO: trying port \Device\USBSER000 - COM3

[LOG 01:37:25.688] KSPSerialIO: KSP Display not found

[LOG 01:37:25.689] AddonLoader: Instantiating addon 'KSPSerialIO' from assembly 'KSPSerialIO'

[LOG 01:37:25.690] AddonLoader: Instantiating addon 'SteamGauges' from assembly 'SteamGauges'

[LOG 01:37:26.022] Parsing rect

[LOG 01:37:26.023] Parsing bool

[LOG 01:37:26.023] Parsing double

[LOG 01:37:26.024] Parsing bool

[LOG 01:37:26.024] Parsing rect

[LOG 01:37:26.024] Parsing bool

[LOG 01:37:26.025] Parsing bool

Edited by thatsmessedup
Link to comment
Share on other sites

OK so for some reason it can't detect the arduino, it is on COM3? Try increasing the handshake delay in the settings .xml file in the gamedata folder

You also seem to have quite a few mods installed, can you try it on a fresh install?

You can also try the new version of the plugin and arduino code in post 317.

Link to comment
Share on other sites

Try



float drainPerSecond;
float chargePrevious;
...

drainPerSecond = (VData.ECharge - chargePrevious)/VData.deltaTime;
chargePrevious = VData.ECharge;

Ok, sorry, newb questions again.

I assume I put the floats in the list with the existing floats... but where do I put this?

drainPerSecond = (VData.ECharge - chargePrevious)/VData.deltaTime;

chargePrevious = VData.ECharge;

I can't find anywhere to put it that doesn't just throw errors back at me about them not being defined.

Link to comment
Share on other sites

Ok, sorry, newb questions again.

I assume I put the floats in the list with the existing floats... but where do I put this?

drainPerSecond = (VData.ECharge - chargePrevious)/VData.deltaTime;

chargePrevious = VData.ECharge;

I can't find anywhere to put it that doesn't just throw errors back at me about them not being defined.

If you put the declarations in the main tab with the rest of the variable you should be able to put the calculations anywhere.

Link to comment
Share on other sites

Thanks. I reinstalled the game and used the updated arduino code. It works great now! Iv reinstalled my plugins and save folder and it is still working so It must have been the code I was running or the ksp install was broken.

Alright cool, I thought you found yet another annoy bug.

Link to comment
Share on other sites

If you put the declarations in the main tab with the rest of the variable you should be able to put the calculations anywhere.

Sorry, still don't understand. What do you mean by "declarations and "Variable", I'm not a coder so don't know the jargon.

I have put the floats in StructVesselData so it now looks like this...

struct VesselData

{

byte id; //1

float AP; //2

float PE; //3

float SemiMajorAxis; //4

float SemiMinorAxis; //5

float VVI; //6

float e; //7

float inc; //8

float G; //9

long TAp; //10

long TPe; //11

float TrueAnomaly; //12

float Density; //13

long period; //14

float RAlt; //15

float Alt; //16

float Vsurf; //17

float Lat; //18

float Lon; //19

float LiquidFuelTot; //20

float LiquidFuel; //21

float OxidizerTot; //22

float Oxidizer; //23

float EChargeTot; //24

float ECharge; //25

float MonoPropTot; //26

float MonoProp; //27

float IntakeAirTot; //28

float IntakeAir; //29

float SolidFuelTot; //30

float SolidFuel; //31

float XenonGasTot; //32

float XenonGas; //33

float LiquidFuelTotS; //34

float LiquidFuelS; //35

float OxidizerTotS; //36

float OxidizerS; //37

uint32_t MissionTime; //38

float deltaTime; //39

float drainPerSecond;

float chargePrevious;

But still can't find anywhere that I can put this...

drainPerSecond = (VData.ECharge - chargePrevious)/VData.deltaTime;

chargePrevious = VData.ECharge;

...without just getting errors.

I either get this...

output:1: error: expected constructor, destructor, or type conversion before '=' token

output:2: error: expected constructor, destructor, or type conversion before '=' token

Or I get this...

utput.ino: In function 'void output()':

output:9: error: 'drainPerSecond' was not declared in this scope

output:9: error: 'chargePrevious' was not declared in this scope

Link to comment
Share on other sites

Got my LCD Displaying some data WOOOHOOO!! Just wanted to make a shout out to the creator of this plugin. Thanks for doing all the dirty, under the hood stuff. That would have been very difficult for a hobbyist like myself. I get jealous looking at all these different control panel mods. I just need to figure out what I want and get the pieces together. OOO, and Im still not quite sure how I am going to hook everything up with just my one uno. I will probably need to do research. I want about 15 buttons/switches with leds and a few lcd... possible an rcs thruster joystick.

Link to comment
Share on other sites

Could you look at my code and tell me what's wrong? you're not making it very clear where I put the two separate bits of code and it's still just throwing up error messages. I know it's a pain having noobs trying to understand your plugin but I'm not a coder so things you might assume are intuitive to me really aren't :) Thanks for being patient!


/pins for LEDs
#define GLED 40
#define YLED 41
#define RLED 42
#define RCSLED 44
#define RCSWARNLED 43
#define RWLED 45
#define RWWARNLED 46
#define MONOWARNLED 47

//pins for input
#define RCSPIN 22
#define SASPIN 23
#define CG1PIN 24
#define CG2PIN 25
#define CG3PIN 26
#define CG4PIN 27
#define CG5PIN 28
#define CG6PIN 29
#define GEARPIN 30
#define CG7PIN 31
#define CG8PIN 32
#define LIGHTPIN 33
#define CG9PIN 34
#define CG10PIN 35

//pins for gauges
#define MONOPIN 2
#define CHARGEPIN 3
#define DRAWPIN 4

#define THROTTLEDB 4 //Throttle axis deadband

#define SAS 7
#define RCS 6
#define LIGHTS 5
#define GEAR 4
#define BRAKES 3
#define PRECISION 2
#define ABORT 1
#define STAGE 0

//macro
#define details(name) (uint8_t*)&name,sizeof(name)

//if no message received from KSP for more than 2s, go idle
#define IDLETIMER 2000
#define CONTROLREFRESH 25

//warnings
#define GWARN 9 //9G Warning
#define GCAUTION 5 //5G Caution
#define FUELCAUTION 10.0 //10% Fuel Caution
#define FUELWARN 5.0 //5% Fuel warning


unsigned long deadtime, deadtimeOld, controlTime, controlTimeOld;
unsigned long now;

float drainPerSecond;
float chargePrevious;

drainPerSecond = (VData.ECharge - chargePrevious)/VData.deltaTime;
chargePrevious = VData.ECharge;

boolean Connected = false;

byte caution = 0, warning = 0, id;

struct VesselData
{
byte id; //1
float AP; //2
float PE; //3
float SemiMajorAxis; //4
float SemiMinorAxis; //5
float VVI; //6
float e; //7
float inc; //8
float G; //9
long TAp; //10
long TPe; //11
float TrueAnomaly; //12
float Density; //13
long period; //14
float RAlt; //15
float Alt; //16
float Vsurf; //17
float Lat; //18
float Lon; //19
float LiquidFuelTot; //20
float LiquidFuel; //21
float OxidizerTot; //22
float Oxidizer; //23
float EChargeTot; //24
float ECharge; //25
float MonoPropTot; //26
float MonoProp; //27
float IntakeAirTot; //28
float IntakeAir; //29
float SolidFuelTot; //30
float SolidFuel; //31
float XenonGasTot; //32
float XenonGas; //33
float LiquidFuelTotS; //34
float LiquidFuelS; //35
float OxidizerTotS; //36
float OxidizerS; //37
uint32_t MissionTime; //38
float deltaTime; //39
};

struct HandShakePacket
{
byte id;
byte M1;
byte M2;
byte M3;
};

struct ControlPacket {
byte id;
byte MainControls; //SAS RCS Lights Gear Brakes Precision Abort Stage
byte Mode; //0 = stage, 1 = docking, 2 = map
unsigned int ControlGroup; //control groups 1-10 in 2 bytes
byte AdditionalControlByte1; //other stuff
byte AdditionalControlByte2;
int Pitch; //-1000 -> 1000
int Roll; //-1000 -> 1000
int Yaw; //-1000 -> 1000
int TX; //-1000 -> 1000
int TY; //-1000 -> 1000
int TZ; //-1000 -> 1000
int Throttle; // 0 -> 1000
};

HandShakePacket HPacket;
VesselData VData;
ControlPacket CPacket;

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

initLEDS();
InitTxPackets();
controlsInit();

LEDSAllOff();
}

void loop()
{
input();
output();
}

All I am still getting is...

KSPIODemo2:63: error: expected constructor, destructor, or type conversion before '=' token

KSPIODemo2:64: error: expected constructor, destructor, or type conversion before '=' token

Edited by Mulbin
Link to comment
Share on other sites

The declarations are correct, but these need to go in your inputs() function, where you do the rest of your input stuff, dials LEDs and so on


drainPerSecond = (VData.ECharge - chargePrevious)/VData.deltaTime;
chargePrevious = VData.ECharge;

"drainPerSecond" is called a variable, when you do "float drainPerSecond" you are declaring that "drainPerSecond" to be a variable that is of the floating point type (i.e. with decimal point), so the next time you use "drainPerSecond" the compiler know what to do with it.

Link to comment
Share on other sites

AAAAAA!! This is what im missing. I was playing around with my pot for a good while and finally decided to search the thread for "throttle". Had to enable the the bit in the config file. Maybe add that to the comments :wink:..

"Weekly" update 8: 0.14.1

Axes! Currently Only throttle, will add others later. You will need to go to settings file and set ThrottleEnable to 1, by default throttle is not enabled. Once throttle is enabled you will lose the ability to control it with keyboard. Connect a pot to an analog input pin 0 and that's it (see arduino.cc/en/Tutorial/ReadAnalogVoltage).

Plugin:

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

Arduino:

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

Once this has been tested I will add more axes and update the first post.

Edit: Unfortunately I'm away to Germany next week, will not be able to answer questions.

Link to comment
Share on other sites

Before anyone facedesks at me, I'm a total Arduino noob.

I can't upload the code for the LED warning lights, because it claims:

KSPIODemo.ino: In function 'void setup()':

KSPIODemo:58: error: 'initLEDS' was not declared in this scope

KSPIODemo:60: error: 'LEDSAllOff' was not declared in this scope

KSPIODemo.ino: In function 'void loop()':

KSPIODemo:67: error: 'KSPBoardReceiveData' was not declared in this scope

KSPIODemo:71: error: 'Handshake' was not declared in this scope

KSPIODemo:74: error: 'Indicators' was not declared in this scope

KSPIODemo:87: error: 'LEDSAllOff' was not declared in this scope

I have no clue what to do, and I'm amped about this plugin.

Link to comment
Share on other sites

AAAAAA!! This is what im missing. I was playing around with my pot for a good while and finally decided to search the thread for "throttle". Had to enable the the bit in the config file. Maybe add that to the comments :wink:..

Um this is described in the first post! :)

Link to comment
Share on other sites

You've just reminded me my Smart House project in school..

Pretty impressive =D

I never thought of that..

Perhaps you can use that to make your own Space Center at home!..

Another suggestion: Why not just label all the fuels with numbers, then just dispatch the remaining resource values just by numbers.. So you dont need to worry about those words or something...

I'm sure KSC will approve this =P

Link to comment
Share on other sites

Ok, been a while since I've posted here. Been very busy lately.

Received my 20x4 LCD display and have been fighting with it for a couple of days, finally ironed out my problems and got it working (Hello World! :P)

And just now (as a proof of concept) had it displaying the 'vertical velocity' :)

Thanks again for this amazing plugin, will post back when I have something more stubstantial to reporting... Might look at the throttle next...

Any idea what rating pot would be best used to get the full range of it working? 5k? 10K? Obviously need to put it all the way to 100%, but don't want it to reach 100% when the physical throttle is only at 75%...

Link to comment
Share on other sites

how are you dealing with the 'trash' characters on your LCD? ie, your speed drops from 100 to 99 but the LCD displays 990 because you didn't tell it to stop displaying the last 0 from 100...

**EDIT - also, just realised, there is no orbit velocity reading? or am I missing something?

Edited by pantner
Link to comment
Share on other sites

You can simply print some blank spaces where your number is before you print the number every time, or you can use a function such as "dtostrf" to print formatted strings.

I'll add orbital velocity this weekend. Anything else you want added?

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