Jump to content

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


zitronen

Recommended Posts

Nope.. lol, cant compile it just getting the following error... what am I doing wrong?


Arduino: 1.5.5-r2 (Windows XP), Board: "Arduino Uno"

output.ino: In function 'void controls()':
output:14: error: 'SAS' was not declared in this scope
output:16: error: 'SAS' was not declared in this scope
output:19: error: 'RCS' was not declared in this scope
output:21: error: 'RCS' was not declared in this scope
output:24: error: 'LIGHTS' was not declared in this scope
output:26: error: 'LIGHTS' was not declared in this scope
output:29: error: 'GEAR' was not declared in this scope
output:31: error: 'GEAR' was not declared in this scope
output:34: error: 'BRAKE' was not declared in this scope
output:36: error: 'BRAKE' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Not sure what the problem is as it is saying the bits zitronen put in are wrong too (SAS and RCS)

Link to comment
Share on other sites

When you open an arduino project there are tabs at the top that open different bits of code... sorry I don't know the technical jargon for them, I'm not a programmer. The tabs available when you open KSPdemo2 are... KSPDemo2, Handshake, Input, SerialCOMMS, Output, Utilities

The code is edited from the demo provided by zitronen.

Complete code under the "KSPDEMO2" tab


//pins for LEDs
#define GLED 5
#define YLED 6
#define RLED 7

//pins for input
#define SASPIN 8
#define RCSPIN 9
#define LIGHTPIN 7
#define GEARPIN 6
#define BRAKEPIN 5
#define ABORTPIN 4
#define STAGEPIN 3

//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;

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 Fuelp; //16
float Vsurf; //17
float Lat; //18
float Lon; //19
};

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;
};

HandShakePacket HPacket;
VesselData VData;
ControlPacket CPacket;

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

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

LEDSAllOff();
}

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

The code I posted previously which is in the "Output" tab is already complete. every other tab is unchanged from zitronens code.

Link to comment
Share on other sites

I haven't done arduino in a while but when I did the tabs were for completely separate bits of code, not sure if they've done some way to split a project into multiple parts now but clearly something isn't connecting right

Just installed 1.0.5 and I can't see anything like that in the menu etc, you can make a new tab but it asks what filename that one will be, some way to include the other tabs I guess in the "root" sketch but I don't really see the point.

Edited by K3|Chris
Link to comment
Share on other sites

I haven't done arduino in a while but when I did the tabs were for completely separate bits of code, not sure if they've done some way to split a project into multiple parts now but clearly something isn't connecting right

Yeah, Zitronen will know what I've done wrong :) Trouble is I don't really understand what I'm doing with code... I can make very nice control panels but need someone elses brain when it comes to making them work! Also finding it hard to keep up as Zitronen knows C and uses a lot of C syntax that isn't in beginner arduino coding..

For example he would use..

#define ledPin 3

Whereas arduino tutorials would tell me to use...

int ledPin = 3;

Link to comment
Share on other sites

Nope.. lol, cant compile it just getting the following error... what am I doing wrong?


Arduino: 1.5.5-r2 (Windows XP), Board: "Arduino Uno"

output.ino: In function 'void controls()':
output:14: error: 'SAS' was not declared in this scope
...

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Not sure what the problem is as it is saying the bits zitronen put in are wrong too (SAS and RCS)

When you added in what you had in the KSPIODEMO File, I found your problem.

As you might have found out, the

    #define [i]word[/i] value 

creates global variables using the preprocessor. All that this means is that every time it sees the word, it just replaces it with the specific value that you gave. Additionally, unlike calling "int variable = value", this value cannot be changed within the program (cannot do value = value + 1 or anything). That is why the common notation for these types of variables is to put them in all caps. Arduino actually already has some of these built-in but that you never noticed. For example: TRUE is actually just the number one (try seeing what TRUE + TRUE is) and FALSE is zero. You cannot reassign these values, but having them makes it easier to read.

When Zitronen originally sent out the KSPIODemo file for Arduino output, it had another block of "define"'s that you appear to have misplaced along the way. As such, just add the following into your KSPIODemo file (mine is right below the section labeled "pins for input" and right before the section labeled "macro"):

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

This should clear up the problem.

Weird, found the arduino page about this: http://arduino.cc/en/Hacking/BuildProcess#.UxN2cyiupoo mentions multiple files per sketch, but it doesn't say how it works, or why you'd use it, does the "main" sketch go on the top and the others get put bellow it? in what order? it's really confusing.

The way that the Arduino IDE/program appears to work is that each of the additional tabs are essentially header files that are automatically included (if you have any background in C). They just include additional functions that you might want to use within your code but that you don't want in your "main" file in order to keep the main file neat and so that you can copy these functions over to other sketches without having to copy them from within the code file (just copy the files for these tabs). Since these files only contain functions, it does not matter what order they are, if that clears it up for you.

As far as I can tell, the Arduino software tells which file is the main one and which are the additional tabs by the main file must have the same name as the folder it is in. That is why if you try to open any of the additional files by themselves, it will ask if you want to put it into a new folder.

Link to comment
Share on other sites

In preparation for the new controls, more labels are being added to my control panel :D

EDIT - although the "Fire" switch looks like a toggle it's actually a sprung-loaded momentary switch.

So I have to ask, because I am really wanting to make a cool-looking control panel, but I have no experiences and am living at college, so I can't easily head to a machine shop until I have a plan. Your panels look really cool.

What are you using to make them (or what would you suggest to make them from) and how are you printing onto them? My first guess would be Masonite and then painted over, but I honestly don't know.

Link to comment
Share on other sites

...add the following into your KSPIODemo file....

ahhh, I see. I had mistakenly thought they were placeholder pin allocations, I'll add them back in, thanks!

So I have to ask, because I am really wanting to make a cool-looking control panel, but I have no experiences and am living at college, so I can't easily head to a machine shop until I have a plan. Your panels look really cool.

What are you using to make them (or what would you suggest to make them from) and how are you printing onto them? My first guess would be Masonite and then painted over, but I honestly don't know.

The panels are made from aluminium composite board (sometimes known as sandwich panel) which is made from a sheet of hard plastic sanwiched between thin sheets of aluminium. It looks like metal but is much cheaper and lighter. It is really easy to work with, you just score throught the outer metal layers with a craft knife then bend and snap through the plastic. The only tools I use are a craft knife and a drill. For the labels I make my own water-slide transfers using transfer paper (they work like the decals you get in a model kit). The type of transfer paper I use is designed for ceramics so is meant to be baked in an oven to help fix/melt it onto the surface... I've found that a hairdryer works really well as the metal surface of the board gets really hot, really quickly!

This system works well at present but in future I have a printing company I deal with that can print directly onto composite board (for sign making etc.) so might consider getting them manufactured in a short run.

Link to comment
Share on other sites

ahhh, I see. I had mistakenly thought they were placeholder pin allocations, I'll add them back in, thanks!

I hope we all learnt a lesson here, this is what happens when you don't treat my code with respect! :D

So now we have most of the basic functionalities, what would you guys like me to do next?

Link to comment
Share on other sites

I hope we all learnt a lesson here, this is what happens when you don't treat my code with respect! :D

So now we have most of the basic functionalities, what would you guys like me to do next?

It would be nice to get the rest of the keyboard commands. Off the top of my head you are still missing...

action groups (1-10)

stage lock (ALT+L)

precision (CAPS)

kill thrust (X)

toggle translate/rotate (SPACE - when in docking mode)

Select docking mode (DEL)

Select staging mode (INS)

I'm trying hard but with not much success to get someone out there to make a mod that gives you extra action groups... all the trouble you went to coding for lots of inputs is a bit wasted when ksp only recognises a total of 21 commands suitable for switches!

Once you have all the inputs I'd love to see either KSP feeding back signals for the lights or possibly start to work through the lists we made you of outputs.

Link to comment
Share on other sites

This thread, and a few others, have prompted me to finally order an Arduino. I also ordered three 8 Digit LED displays with the intent of showing Apoapsis, Altitude, and Periapsis. I figure that should be enough of a challenge to start with. Once that works, I'll move on to bigger goals. I'm sure I'll be back with questions.

Link to comment
Share on other sites

So since I know C, I tried last night to see how C# works and glance through the KSP Assembly library to see if I could locate the "read sas/lights/etc. status". After an hour, I now fully understand why they say C# is not like C and also I realize how little I understand about classes (and how hard it is to find documentation on the KSP C# library). About all I could figure out was what all was under the activevessel.orbital object and all the data that could be read from that. I do not think I will be going back for more. :confused:

So that random tidbit aside, here are my thoughts on what I would like to see (and I have no clue if any of these are possible):

Personally, I would like a few additional readins to KSP; specifically the Action Groups 1-10 and Kill Thrust. Most of the rest of the ones Mulbin mentioned, I rarely ever use.

After that would be some of the readouts that the library can currently send in to KSP but can't read out (i.e. SAS, Landing Gear, Lights). This would be moreso for confirmation or just to kind of ensure that everything lines up.

Link to comment
Share on other sites

This thread, and a few others, have prompted me to finally order an Arduino. I also ordered three 8 Digit LED displays with the intent of showing Apoapsis, Altitude, and Periapsis. I figure that should be enough of a challenge to start with. Once that works, I'll move on to bigger goals. I'm sure I'll be back with questions.

this Is what I ordered, will see how I go when It arrives...

http://www.ebay.com.au/itm/271061312409?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

I hope we all learnt a lesson here, this is what happens when you don't treat my code with respect! :D

So now we have most of the basic functionalities, what would you guys like me to do next?

I mirror the requests of the other guys, action groups, cut engines, change control modes...

As I mentioned before, would also love an analogue throttle control... but currently my control panel consists of an Arduino on a breadboard with a single switch, so no rush :)

Also need to order myself a Mega, me thinks...

Link to comment
Share on other sites

Managed to get a quick test done on the UNO, seems the new controls are working well. Also the 1 second latency I was getting has disappeared somewhere along the way! I'll run a test on my troublesome Funduino mega later as it often doesnt work with this plugin.

Link to comment
Share on other sites

This thread, and a few others, have prompted me to finally order an Arduino. I also ordered three 8 Digit LED displays with the intent of showing Apoapsis, Altitude, and Periapsis. I figure that should be enough of a challenge to start with. Once that works, I'll move on to bigger goals. I'm sure I'll be back with questions.

Great! That's what the project is for!

I think I would do control groups next. I don't think we need a dedicated bit for cutting throttle, you should be able to just have a button that sets throttle = 0 in arduino code once we have axes working. Edit: on second thought, that may not work if you are not using a hardware throttle.

Edited by zitronen
Link to comment
Share on other sites

Next noobish question... what is the best way to wire up a signal light to the switches? I tried wiring an LED and resistor in series with the switch and while the light works... the switch no longer works the SAS - I'm guessing the resistor is messing things up re the arduino getting the signal.

EDIT - I can also report that the plugin is now working with the mega :) now I have 50 pins to play with.

Link to comment
Share on other sites

This thread, and a few others, have prompted me to finally order an Arduino. I also ordered three 8 Digit LED displays with the intent of showing Apoapsis, Altitude, and Periapsis. I figure that should be enough of a challenge to start with. Once that works, I'll move on to bigger goals. I'm sure I'll be back with questions.

Ha. Those are the exact same panels I have. Maybe we can fumble our way through this together!

Link to comment
Share on other sites

Next noobish question... what is the best way to wire up a signal light to the switches? I tried wiring an LED and resistor in series with the switch and while the light works... the switch no longer works the SAS - I'm guessing the resistor is messing things up re the arduino getting the signal.

This is how you will want to hook up (sorry about the odd symbols, the software isn't really made for Arduino).

2bFAPGY.png

V_High is your 5V output from the Arduino, Input_Pin is the pin to read from, and Ground is your standard ground.

What happens is that while the switch is open, the pin should read ground, but when you close the switch, there will be no voltage drop across it, so the pin will read high. Then the 5V will drop across the resistor and the LED then be back to ground, so it will power the LED. Remember, input pins act like voltmeters, so they do not normally really take any current flow through them.

Link to comment
Share on other sites

Ok thanks, I'll give that a try. Although I'm now thinking longer term I may put the leds on another pin... I'm planning to have dual active/warning lights that with a bit of coding in arduino should work like this example..

RCS switch off = led off

RCS switch on + monopropellant on board = green RCS led lit.

RCS switch on but out of monopropellant = red RCS led lit.

similar things to tie electric charge to various functions... a basic form of error light really.

Link to comment
Share on other sites

Great job! Too bad it's Windows-only... if I were to rewrite parts of this to make a plugin that sends data over a fifo or something, would that be ok? I'm also working on a physical display :)

Link to comment
Share on other sites

Ok thanks, I'll give that a try. Although I'm now thinking longer term I may put the leds on another pin... I'm planning to have dual active/warning lights that with a bit of coding in arduino should work like this example..

RCS switch off = led off

RCS switch on + monopropellant on board = green RCS led lit.

RCS switch on but out of monopropellant = red RCS led lit.

similar things to tie electric charge to various functions... a basic form of error light really.

If you keep planning like that you will soon be out of pins!

Great job! Too bad it's Windows-only... if I were to rewrite parts of this to make a plugin that sends data over a fifo or something, would that be ok? I'm also working on a physical display :)

You are free to rewrite whatever you like. Someone is working on a Mac version: http://forum.kerbalspaceprogram.com/threads/68642-Arduino-Addon-for-Mac

Link to comment
Share on other sites

If you keep planning like that you will soon be out of pins!

Lol yeah, its going to take careful planning, I only have 54 in total... and putting any momentary buttons that don't really need the plugin on a separate arduino (keystroke emulating),of course if you were able to make the plugin support multiple arduinos at the same time... ;)

EDIT - of course eventually I might learn how shift registers work... then I have lots of pins :)

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