Hi, I am working on a flight computer program of a model rocket and I have some trouble with GPS data. I need some information (acceleration, angle, altitude, location etc.) to take some actions during the flight. The problem is that when I run the program, the first sentence of the GPS data comes up once and nothing follows it after that. The picture I attached and the code below will explain the problem better. The GPS module's data pins are connected to the pins 10 and 11 of my Arduino UNO and I am using SoftwareSerial for the GPS module because the HardwareSerial is being used by XBee modules to transmit the data. I used while(ss.available){...} command to get all the data the GPS module sends in a certain interval. May this be the reason -I do not think so though-? If not, what am I doing wrong? Thank you.
Reduce the program to a minimum, get rid of 95% (or more) of the code and prove to yourself you can read the characters from the GPS, encode them, and print out the location and altitude etc.
The code you posted is very difficult to read and understand, did you write it all yourself ?
srnet:
Reduce the program to a minimum, get rid of 95% (or more) of the code and prove to yourself you can read the characters from the GPS, encode them, and print out the location and altitude etc.
The code you posted is very difficult to read and understand, did you write it all yourself ?
Hi, thanks for the reply! How can I prove that I can read the character from the GPS? And I actually do not want to encode the GPS data, I want to get the GPS data in NMEA format so that I can use Earth Bridge software to get a location on a map. But if things go so hard, I may consider getting and using latitude and longitude data only.
The code was all written by me, with help of some example codes. I think it is not difficult to understand, I would like to shorten it but all the rows are connected to each other somehow. So, I think I should not remove any row to keep it logical.
You can look into the getNMEA() and flight() only if it will be better to extract the problem. Thank you very much for your interest
I have read it many times. So, should we catch the GPS data when the GPS module sends them? How can I get the last GPS data whenever I want? Can I buffer them for a while?
jremington:
2. It is bad programming practice to use goto statements. Learn to use control structures instead.
I know. I would like to do that but I have a really limited time and I should let well enough alone.
jremington:
3. Add comments. Six months from now you won't remember what you did.
I have done it in my original code. I translated the code into English so that you can understand it better and removed the command lines
yusufbudakli:
I think it is not difficult to understand.
Well you wrote it, so know what the structure of the should be and what it is supposed to be doing. And if it works then thats fine.
But now you want help, which means the code has to be clear and easy to understand so that the volunteers on this forum can quickly give you assistance.
Aaa, will the code work the same when I expunge these?
srnet:
Well you wrote it, so know what the structure of the should be and what it is supposed to be doing. And if it works then thats fine.
But now you want help, which means the code has to be clear and easy to understand so that the volunteers on this forum can quickly give you assistance.
Okay, sorry for making things hard for you. Hope this is better:
wildbill:
Thanks for deleting all those goto but I think you broke it.
For example getAltitude never gets called now.
What is this version supposed to do?
Hi, thanks for replying! The problem is actually about the getNMEA(). I did not delete the getAltitude() because it is kind of relevant to the problem. When the flight() is begun, I should get an altitude data, GPS data and another altitude data. When I run the code, these are done well for once, no more. I thought that the problem may be caused by the if statement which checks if alti is bigger than startingaltitude, by missing GPS data transmission or something else I could not consider. That is why I did not remove the getAltitude(), even though it is not used in the recent, cut code. I just want to make you understand that I need full GPS data during all the flight, and there are some conditions to take some actions during the flight. Even though the actions are taken in the relevant conditions, I need to continue getting full GPS data, from the beginning of the flight to the end of it. Since the flight parameters are continuously checked to be matched with the conditions, I could not set an appropriate interval allowing getting the GPS data on time. At least, that is what I understood from the problem.
yusufbudakli:
Aaa, will the code work the same when I expunge these?
If you do it correctly, yes. Of course, you can't just remove them. You have to figure out what normal, built in feature of C would normally be used instead of that horror.
aarg:
If you do it correctly, yes. Of course, you can't just remove them. You have to figure out what normal, built in feature of C would normally be used instead of that horror.
But the code is in setup, not in loop. Are the functions repeated from the beginning while the if statement's condition is not matched? That is why I used goto functions. What built in feature of C is normally used instead of those?
let's look at the text "MAIN: THRESHOLD ALTITUDE EXCEEDED". I want it to appear once when the threshold altitude is exceeded. And if I wrote the code in loop, it appears continuously while the altitude is bigger than the threshold altitude, doesn't it? I think I can manage this by adding a kind of switch which is set to 1 in the beginning, and will be changed to 0 when the function responsible for printing the text "MAIN: THRESHOLD ALTITUDE EXCEEDED" out runs once, the function will not print that text more than once since the switch will be set to 0 in the end of the first run. But is there any better and shorter way to do this?
The code with switches is below, can/should I improve it?
Can I use SerialEvent with SoftwareSerial? Does it catch the GPS data when it comes and continue getting them until they are all sent? Or is there any command that listens to the serial port and starts another command when the data starts being sent?
So, is your help made up of pushing me to obey the forum rules 100% instead of giving advices about my problem? Am I in a Debian forum or an Arduino one?