Jump to content

Recommended Posts

11 minutes ago, Kerbart said:

No. The dictionary (let's name if fd for flightdata) is the variable. (Python pro's spare me the flaming I know we're mangling semantics here), but it helps you in reducing the number of variables you'd have to pass around (or to bypass that define as globals).

 

So instead of:


x = 100
y = 200
mass = 350

(and many more like those) you do:




fd = {'x': 100, 'y': 200, 'mass': 350}

And instead of doing print(x) you now do print(fd['x']) - but in return for that little extra typing you only have to pass one variable around, that holds all your flight data values - accessible through keys that are defined as readable strings



Oh ok that makes sense. How do I change the flight data? If I wanted to make the x 100 to an x 150. I think im going to use this more for logging data than for actual use (atleast for now) That is really useful. What did you think of that adafruit sensor?  https://www.adafruit.com/product/2472#description-anchor

Edited by Cheif Operations Director
Link to comment
Share on other sites

47 minutes ago, Cheif Operations Director said:

Oh ok that makes sense. How do I change the flight data? If I wanted to make the x 100 to an x 150. I think im going to use this more for logging data than for actual use (atleast for now) That is really useful.

 

 

You can simply change the values stored in a dictionary, for instance like this:

fd['x'] = 150
fd['y'] = 230

But it's more useful to see things in perspective, so here is a more elaborate example:

def main():
    # initialize flight data
    fd = {'x-pos': 0.0, 'y-pos': 0.0, 'mass': 200.0 }
    lift_off(fd, max_height=50)
    ...

def lift_off(fd, max_height):
    while fd['y-pos'] < max_height:
        fd['y-pos'] += 10

While the code itself is complete BS, it demonstrate how you'd store flight data inside a dictionary, access it elsewhere and modify it as needed.

 

47 minutes ago, Cheif Operations Director said:

What did you think of that adafruit sensor?  https://www.adafruit.com/product/2472#description-anchor

It looks cool, but I think it's the sensor only, you will probably need a processing board as well. If that's needed, start out with the Circuit Playground Express; it's great fun, and has a ton of sensors and leds to play around with and get some hands-on experience in what you want to achieve.

5 minutes ago, Cheif Operations Director said:

As a secondary note: If I use a sensor to input data into a variable (ex: Gyroscope ---> 345* ---> gx=345*) I use this data to do certain things in flight. I then also log this data but I never actually change it. I do not need global variables right?

What you probably want to do is create a function that reads your sensor, like gx = read_gyroscope()

Link to comment
Share on other sites

On ‎7‎/‎5‎/‎2019 at 4:05 PM, Kerbart said:

 

You can simply change the values stored in a dictionary, for instance like this:


fd['x'] = 150
fd['y'] = 230

But it's more useful to see things in perspective, so here is a more elaborate example:


def main():
    # initialize flight data
    fd = {'x-pos': 0.0, 'y-pos': 0.0, 'mass': 200.0 }
    lift_off(fd, max_height=50)
    ...

def lift_off(fd, max_height):
    while fd['y-pos'] < max_height:
        fd['y-pos'] += 10

While the code itself is complete BS, it demonstrate how you'd store flight data inside a dictionary, access it elsewhere and modify it as needed.

 

It looks cool, but I think it's the sensor only, you will probably need a processing board as well. If that's needed, start out with the Circuit Playground Express; it's great fun, and has a ton of sensors and leds to play around with and get some hands-on experience in what you want to achieve.

What you probably want to do is create a function that reads your sensor, like gx = read_gyroscope()

Spoiler

I haven't had time to go through this and completely and test all of the code sorry Im going through it now. On another subject I was trying to log flight data on where my gimbals are pointing. I represent this with the gx  variable. However I need to log this flight data in another function. When I try to log the data it says the gx is not defined (I assume because gx is a local variable) so I made gx global however apparently you can no have a global variable be the parameter of a function. So I need to set gx = gx2 with gx2 being global but It does not work as somehow gx2 is not defined even though I just defined it

Here is the warning message

File "C:/Users/censored/censored/Flight Computer 0.5 Graph.py", line 366, in flightcomputer
    gx==gx2

NameError: name 'gx2' is not defined

#Spoiler has fixed problem

On ‎7‎/‎5‎/‎2019 at 4:05 PM, Kerbart said:

It looks cool, but I think it's the sensor only, you will probably need a processing board as well. If that's needed, start out with the Circuit Playground Express; it's great fun, and has a ton of sensors and leds to play around with and get some hands-on experience in what you want to achieve.

I will look into this

On ‎7‎/‎5‎/‎2019 at 4:05 PM, Kerbart said:

gx = read_gyroscope()

Should'nt this be gx = read_gyroscopex(gx)? This ties into my first question

Edited by Cheif Operations Director
Dumb grammer mistake
Link to comment
Share on other sites

36 minutes ago, Cheif Operations Director said:


gx=4
def read_gyroscope(gx):
    print(gx)
gx=read_gyroscope(gx)

This seems to have worked more or less

 

But gx will now be None, because the function isn’t returning a value.

Link to comment
Share on other sites

40 minutes ago, Cheif Operations Director said:


gx=4
def read_gyroscope(gx):
    print(gx)
gx=read_gyroscope(gx)

This seems to have worked more or less

 

The bottom line binds the variable gx to the return value of read_gyroscope. But since it doesn’t have a return statement, the return value is None.

So what you probably want is something like this, in lieu of actually reading the gyroscope hardware port:

def read_gyroscope():
  return 64.8

gx = read_gyroscope()
print(gx)

 

Link to comment
Share on other sites

2 minutes ago, Kerbart said:

The bottom line binds the variable gx to the return value of read_gyroscope. But since it doesn’t have a return statement, the return value is None.

So what you probably want is something like this, in lieu of actually reading the gyroscope hardware port:


def read_gyroscope():
  return 64.8

gx = read_gyroscope()
print(gx)

 

Im not following what you are saying. I just ran the code on two different documents and it went fine as well as simulating for a changing value in the gyro number

I need it to read the gyro number for the x axis which is being actively put into the variable gx. It would have to be return gx in that case which would solve nothing

Link to comment
Share on other sites

gx=4
def read_gyroscope(gx):
    print(gx)
gx=read_gyroscope(gx)

This really does print out 4. But perhaps you'll understand this better if you try running this:

gx=4
print("before", gx)
def read_gyroscope(gx):
    print("during",gx)
gx=read_gyroscope(gx)
print("after",gx)

You get:

Quote

before 4                                                                                                                                                                        

during 4                                                                                                                                                                        

after None 

 

Link to comment
Share on other sites

11 hours ago, Shpaget said:

gx=4
def read_gyroscope(gx):
    print(gx)
gx=read_gyroscope(gx)

This really does print out 4. But perhaps you'll understand this better if you try running this:




gx=4
print("before", gx)
def read_gyroscope(gx):
    print("during",gx)
gx=read_gyroscope(gx)
print("after",gx)

You get:

 

Ok I see, that problem did not arise with the full flight computer code ( I have no idea why not it should have) however ill add in the return statement.

Link to comment
Share on other sites

  • 4 weeks later...

Hello Again people, I will not have a ton of time to reply as quickly because I am at KSC, however I had a few more questions, I assume that python has no libraries with stuff robotics, if it does what are they I did not see anything useful on the list.  If there are not any python libraries for this sort of thing I assume someone has made some sort of add-on for python that allows you to turn servos etc. If so what is that, Im referring only to code add-on here and nothing with actual hardware I need to buy yet. 

Also on a side note I had a question. How does a computer send digits? I had an idea but it seems unlikely, 
If you simpily  said each digit should take x "Nanoseconds" to send if it is 1 nanosecond it is 1 if it is 2 it is two etc. Then you could send numbers in the millions with just one port. The second idea was where 9 wires go into a computer, and the computers sees how many are active over a specified period of time and that is the digit. Either way what is a digit even to a computer? What does it represent etc? 

Edited by Cheif Operations Director
Link to comment
Share on other sites

I also need to tell the code to create a new variable. As in not me but the code itself creates a variable. Each time the script runs it says the variable y is equal to the code created variable HOWEVER when the script runs again it is equal to a second code created variable.This way I can access a list of past data without interfering with the main code. This way I can log all movements and how they affect the rocket in flight.

Link to comment
Share on other sites

Im not sure how to do this so excuse the pseudocode but something like this. I only need the way to insert the number which is the hard part

Insert_Number = 0
def create_var_function_one(war_one):
  	Insert_Number = Insert_Number + 1
	var_addon--->Insert_Number<--- = var_one
  

create_var_function_one(var_one)



Print(var_addon-->etc<--)
	

 

Link to comment
Share on other sites

18 hours ago, Cheif Operations Director said:

Hello Again people, I will not have a ton of time to reply as quickly because I am at KSC, however I had a few more questions, I assume that python has no libraries with stuff robotics, if it does what are they I did not see anything useful on the list.  If there are not any python libraries for this sort of thing I assume someone has made some sort of add-on for python that allows you to turn servos etc. If so what is that, Im referring only to code add-on here and nothing with actual hardware I need to buy yet. 

Also on a side note I had a question. How does a computer send digits? I had an idea but it seems unlikely, 
If you simpily  said each digit should take x "Nanoseconds" to send if it is 1 nanosecond it is 1 if it is 2 it is two etc. Then you could send numbers in the millions with just one port. The second idea was where 9 wires go into a computer, and the computers sees how many are active over a specified period of time and that is the digit. Either way what is a digit even to a computer? What does it represent etc? 

Most modern communication is done with some sort of digital encoding. For your purposes, serial is probably the simplest way. There are other options, of course, such as I2C, 1-Wire etc.

18 hours ago, Cheif Operations Director said:

I also need to tell the code to create a new variable. As in not me but the code itself creates a variable. Each time the script runs it says the variable y is equal to the code created variable HOWEVER when the script runs again it is equal to a second code created variable.This way I can access a list of past data without interfering with the main code. This way I can log all movements and how they affect the rocket in flight.

You need a data logging device, such as an SD card.

17 hours ago, Cheif Operations Director said:

Im not sure how to do this so excuse the pseudocode but something like this. I only need the way to insert the number which is the hard part


Insert_Number = 0
def create_var_function_one(war_one):
  	Insert_Number = Insert_Number + 1
	var_addon--->Insert_Number<--- = var_one
  

create_var_function_one(var_one)



Print(var_addon-->etc<--)
	

 

Use arrays.

Link to comment
Share on other sites

3 hours ago, Shpaget said:

Most modern communication is done with some sort of digital encoding. For your purposes, serial is probably the simplest way. There are other options, of course, such as I2C, 1-Wire etc.

So how does it actually send a digit, something like an adafruit. 

 

3 hours ago, Shpaget said:

You need a data logging device, such as an SD card.

I intend to have one, I still need to be able to have separate variables for logging however.

 

3 hours ago, Shpaget said:

Use arrays.

ok, is it possible to make these all have a prefix variable and then print all vars with the prefix?

Link to comment
Share on other sites

5 hours ago, Cheif Operations Director said:

So how does it actually send a digit, something like an adafruit. 

I intend to have one, I still need to be able to have separate variables for logging however.

ok, is it possible to make these all have a prefix variable and then print all vars with the prefix?

Adafruit is a company, so I don't understand this part.

Anyway, in communications, you usually have two lines (physical wires), one is called Data and used for data transmission, and the other, called Clock, is for synchronization.

Let's say microcontroller works on 5 volts, and can change voltage on its pins. If it sends out 5V, we call that logical 1 or high, if it drops the voltage down to 0V, we call it logical 0 or low.

Clock line sends regular pattern of voltage - high, low, high, low... represented as 010101010101010101010. It doesn't contain data, it is just used so the receiving side can synchronize itself with the sender. It is used because detecting such sharp changes in voltage is something that is very easy to do for microcontrollers - they can detect it and act very fast.

At the same time Data line also changes in voltage. Every time the microcontroller sends "1" on clock line it also adjusts Data line.

So Clock line sends 1
At the same time Data is set to 1
Short time passes
Clock is set to 0
Data is still 1
Short time passes

(This is the first bit transmitted)

Clock is set to 1
Data is set to 0
Short time passes
Clock is set to 0
Data is still 0

(This is the second bit transmitted)

and so on...

Clock 010101010101010101010
Data  110011000011110011000

e66rc5x.png

 

Why do you need to have separate variables for logging?

One array named MaxHeightLog can contain hundreds of values, one from each run.

This is an array, in C/C++, because my Python sucks:

int MAxHeightLog [100];

It is just a baby array that contains no data, but it can hold 100 values. It is ready to be filled.

When the code runs for the first time, you call that run 0 (because computers like counting from 0 and not 1).

So we have a variable RunNumber = 0.

If we have a variable called MaxHeight with the highest altitude we achieved (lets say it was 1000 of some units) and want to store this into the array we can do it simply with:

MaxHeightLog [RunNumber] = MaxHeight;

The value of MaxHeight (1000) is now stored into the position 0 of the array MaxHeightLog.

Next time we run the script, RunNumber will have the value of 1, so running the same line of code as above will result in value of MaxHeight (lets say it is now 1050) being stored in position 1 of the array. We still keep the data from the first run.

When we are done with running the script we can list all our results easily:

for (int i = 0; i < 100; i++)
{
  print (MaxHeightLog [i];
}

It will output this:

1000
1050
0
0
0
0
0
...

Since we ran the code only twice there are only two non zero values and 98 zeroes, because the array has 100 positions.

Keep in mind that is you do this in RAM and not store it to some type of permanent memory the data will get lost on every power cycle and restart of the program.

 

3 hours ago, Cheif Operations Director said:

Also this array thing. Can it be used to name functions?

 

No. But a function can draw parameters from many different arrays. which when you think about it the only sensible way. You don't want to write hundreds of functions that are almost the same apart from some value in a variable.

Link to comment
Share on other sites

1 hour ago, Shpaget said:

Adafruit is a company, so I don't understand this part.

Im referring to computer parts that are not bristiling with hundreds of communication prongs

 

 

1 hour ago, Shpaget said:

No. But a function can draw parameters from many different arrays. which when you think about it the only sensible way. You don't want to write hundreds of functions that are almost the same apart from some value in a variable.

I was thinking more for an AI System but I suppose you have a point.

 

1 hour ago, Shpaget said:

Keep in mind that is you do this in RAM and not store it to some type of permanent memory the data will get lost on every power cycle and restart of the program.

Hence the SD card correct?
 

1 hour ago, Shpaget said:

it can hold 100 values

What If I want the maximum hold capacity to be infinite?

1 hour ago, Shpaget said:

Why do you need to have separate variables for logging?

Each X seconds in my code I log data, so if I am at 5 altitude readings in I may be at 1 second. then I can take data from other parts of the rocket and see what was happening at one second. Also (if/when I get to it) I can have the computer review past flight data while in flight to make sure other parts of the rocket are fine on the overall and not second to second level. 

For example if an array has 1000 items and each value should not be greater than one. If the arrays value is greater than 2 we have a problem. It allows you to examine large amounts of data quickly, that is basically my idea.

I could also have a computer read an SD card as another stores the data but that is long term again

Link to comment
Share on other sites

5 minutes ago, Cheif Operations Director said:

Im referring to computer parts that are not bristiling with hundreds of communication prongs

A simple serial port needs only a few physical connections. If you are communicating with another microcontroller, through those connections you can send as many different pieces of data as you want (limited by bandwidth, of course).

I2C protocol allows one master device to communicate with multiple slave devices using three shared lines, plus one for each slave device.

1-Wire protocol needs only one wire to communicate with as many as you like.

 

5 minutes ago, Cheif Operations Director said:

Hence the SD card correct?

Yes, SD will hold memory even after shutdown, but probably more important than that, it can store MUCH more data than you usually find in RAM of microcontrollers.

 

5 minutes ago, Cheif Operations Director said:

What If I want the maximum hold capacity to be infinite?

There is no such thing, at one point you need to define the limits of your system.

That being said, a 4GB SD card should be more than adequate for anything you need.

5 minutes ago, Cheif Operations Director said:

Each X seconds in my code I log data, so if I am at 5 altitude readings in I may be at 1 second. then I can take data from other parts of the rocket and see what was happening at one second. Also (if/when I get to it) I can have the computer review past flight data while in flight to make sure other parts of the rocket are fine on the overall and not second to second level. 

Yeah, an SD card would be ideal for this. Your microcontroller would generate a TXT file that would contain something like a comma separated value containing timestamp and values from all the sensors you monitor, then waits 5 seconds (or however long you want) and, in a new line, write the new timestamp and new values. Repeat until done. Once you recover your rocket, you take out the SD card, pop it into the PC and import into Excel, or what have you, to analyze it.

Link to comment
Share on other sites

2 hours ago, Shpaget said:

There is no such thing, at one point you need to define the limits of your system.

The limit of the system is the code. when the code stops running it stops logging. that is why it needs to be infinite, it is only supposed to run when the rest of the code runs. Each time the while loop runs it logs data. I have no idea how long  the guidance computer will run because it depends on the flight of the rocket. I mean I COULD make it 99999999999999999999 long and make. It theoretically it would run forever but that is annoying for me and the computer. 

Link to comment
Share on other sites

You need to have a general idea how long the flight will take. Is it 1 minute? is it 10 minutes? Maybe it is 10 years, but it is certainly not forever. Once you have your expected life, and what data you are collecting, you can calculate how much storage you need, or how often you can log data given certain amount of storage.

For example if one full entry (timestamp, altitude, speed etc...) takes up 40 bytes, a 1 GB SD card can store 25 000 000 entries. If you log data once every second, your 1 GB card can hold about 300 days worth of data. If you want to log data 10 times per second, that same card will run out available space in about 30 days. Is that enough for you? I don't know? Can you fit all the sensor data you want to collect in 40 bytes? I don't know. Maybe it will take you 400 bytes. Is 10 times per second often enough for you? If you need 100 times per seconds and 400 bytes per entry, you only have enough room for about 7 hours. These are the numbers you need to figure out.

Once you fill up your memory, you could potentially delete oldest data, but that too is a design consideration. It won't happen by itself.

In case of an amateur rocket launch I think we can safely say that 1 GB is more than enough, but you can see the design problem? If you were building a weather station that is going to be placed in a remote location, perhaps 30 days of storage is not enough since it would be too expensive to go out every month to get the data. But if the storage is sufficient for a years worth of data collection, then you can proceed with the design. If you can't achieve that, for whatever reason, you need to reevaluate the feasibility of the project. Today, even amateurs can build this sort of weather station for as little as $50, add another $50 for a solar panel and battery to power it. In 1970's this type of device would be prohibitively expensive for enthusiasts.

Bottom line, first figure out your needs, then see how you'll do it, not the other way around.

Link to comment
Share on other sites

59 minutes ago, Shpaget said:

You need to have a general idea how long the flight will take. Is it 1 minute? is it 10 minutes? Maybe it is 10 years, but it is certainly not forever. Once you have your expected life, and what data you are collecting, you can calculate how much storage you need, or how often you can log data given certain amount of storage.

Again though, this is a problem. Take the Voyager craft they still transmit and their life expectancy is over. I need it to run unless I say it should not.Im going to have an if statement so I can turn it off if I need too

Edited by Cheif Operations Director
Link to comment
Share on other sites

I am not familiar with intricacies of the data storage of Voyager, nor do I think that it is relevant for this discussion. I'm sure some very smart people found a way to overcome many issues, including data storage.

Sure, you can stop data logging if you want. It's just a matter of software.

I'm not sure what is the topic any more. I believe I answered all your questions, taking into account your lack of specifics.

How long do you expect your flight to last? Even high power amateur rocket flights last only a few minutes.

Link to comment
Share on other sites

3 hours ago, Shpaget said:

I am not familiar with intricacies of the data storage of Voyager, nor do I think that it is relevant for this discussion. I'm sure some very smart people found a way to overcome many issues, including data storage.

Sure, you can stop data logging if you want. It's just a matter of software.

I'm not sure what is the topic any more. I believe I answered all your questions, taking into account your lack of specifics.

How long do you expect your flight to last? Even high power amateur rocket flights last only a few minutes.

I am mentioning the fact that I do not know exactly how long the flight will be. I want the flight to last about 1-2 minutes but if it happens to hit a strong stream of air and gets carried along half way across the ocean I do not want it to stop logging data. My point is that I can only estimate how long the flight will last, it could last many times greater than that estimate hence the voyager analogy.  My point was that I want it to stop logging data when I tell it to stop. This could be via code or radio communication etc. This was as long as I have enough storage on the SD card I can get store more stuff, you may say that I should max the storage at the SD max, but if I ever try to transmit the SD card data that would still not be a problem because I could just keep inserting new SD cards to record data. Fundamentally I have no idea how long it will take to come back down and I want as much data as possible. 

This is what I want to do. When the rocket is on the ground I turn of the data gathering system, if it over the ocean and it hits water after 1 month of going around the world I turn off the system (yes I realize this is preposterous just bear with me)

while return_f_data = True
	#create new vars
	log_data()

 

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