0

the_cockpit.png

MODULE 7

Sensing with the SAGAN

Your space mission requires you to know your tools well. The skills you’ve learnt so far have been in preparation for real life use of your tool - the SAGAN.
Your SAGAN is powered by a powerful computer that you’ve already been using - the Raspberry Pi. It’s going to be the brains of the SAGAN when it is in space. It will power and run all the sensors on board in whichever way you tell it to. It will store all the information you collect onto the SD card until either the astronauts or ground control request that information to be sent back down to Earth.


LIBRARIES

In order to make your coding time a whole lot less stressful, we have made some useful libraries for the ASIMOV / SAGAN sensors. A programming library is a set of pre-compiled functions that you can incorporate into your code in the beginning of your program. What these libraries do is make using the sensors easier by being able to call on different functions at any time. You won't have to worry about having to interact with most of these libraries as they work behind the scenes. We’ll work through some sample code and then you will work through some of your own code!

STARTING OFF

Often starting off a piece of code is the hardest part. So to help you get started, there's a few simple rules you can follow for your program. 

Firstly, you need to figure out what libraries you need for your program. Cuberider libraries include the logbook, sensor, led and timer libraries, these are the only libraries you'll need to import in order to start using your sensors!

The logbook library helps you record your data and the sensor library will allow you to use all of the SAGAN's sensors.

 
from Logbook import* #This library allows you to create logbooks to store data
from Sensor import*#This library will let you use all of the ASIMOV / SAGAN sensors
from LEDS import*#This library will let you use your Led lights, you only need to include it when you want to use LED functionality
from Timer import* #This library is only important when you want to run gather data at specific time increments ie: once every 2 seconds. It is not required to gather and log data
 

HOW DO THE LIBRARIES WORK?

Each library has a variety of functions that perform different tasks in order to operate the ASIMOV / SAGAN successfully. The sensor library allows you to create variables and assign them to different sensors, by doing this you can start gathering data from them. Variables you create are assigned to functions that exist in a dictionary and all of the important code required to gather data specific to that sensor is stored.

 
#An example of how you'd assign variables to sensor functions
exampleVariable = Sensor("ExampleSensor")
 

The logbook library allows you to store data to the SD card in a html file. You can create new files, structure and present data neatly and collect and store data using the logbook library. In order to use the logbook library successfully, you need to create an object that can access the functions of the library. Objects are very different to variables in a number of ways, however, they've been designed to be used in a similar fashion to the sensor and logbook libraries. 

In order to call a function from a different class (like the classes that exist in the sensor and logbook libraries) you need to create an object of that class that can call upon functions when you need them. In the logbook library you need to manually do this, in the sensor library another layer has been added in order for you to use variables that take functions from dictionaries inside of that library.

 
from Sensor import*#This imports all of the functions from the sensor library
from Logbook import* #This imports all of the functions from the logbook library
#Setup your logbook
exampleObject = Logbook("logbook1")

#Setup your logbook columns by getting the object to call a function in the lib
exampleObject.AddColumn("This_Name_Can_Be_Whatever_You_Want_ :D")

#An object calls the Start function, which allows you to start recording data
exampleObject.Start()

#The object calls the log function that captures data from the sensor. The log function takes the variable as an input
exampleObject.NewData(exampleVariable)

#An object calls the Finish function, which stops you from recording data
exampleObject.Finish()
 

There are a few different ways you can write software in order to collect data. One programming tool that you can use to collect multiple data points is a 'for' loop. A For loop can execute a certain piece of code several times over. For loops operate in a similar way to while loops, however a while loop will only work when a certain condition is met, whereas a for loop will only run a certain amount of times before it stops.

 
#The for loop will execute whatever code you have nested in it until your variable reaches its count. 
for exampleVariable in range (0,5):
    exampleFunction()
#In this case exampleVariable will execute exampleFunction 5 times before it exits the for loop.
 

You can do the same thing in a while loop too! This achieves the same outcome as the for loop but it uses more lines of code.

 
a = 0
while(a<5): #While variable a < 5 execute while loop code
      exampleFunction() #run exampleFunction()
      a = a + 1 #Add the value of a and 1 together
 

You'll have to use loops like these in order to gather data from the sensors aboard the ASIMOV / SAGAN. The two example loops shown above are the equivalent of writing the same code out constantly.

 
#If you were to write code manually without loops, this is poor coding practice don't do this!
exampleFunction()
exampleFunction()
exampleFunction()
exampleFunction()
exampleFunction()
 

Another important aspect of writing good code for your space mission is using delays. You might think that collecting as much data as you can is a good thing, however if you collect thousands and thousands of data points as fast as you can, this could overload the ASIMOV / SAGAN as the file size might be too big for the Raspberry Pi to handle. 

You need to think about how to manage your code carefully. We've made a special type of delay library called Timer, the timer library will allow you to space out your data collection very precisely and ensure that your code has even less chance of crashing in space. 

 
from Timer import* #Include the timer library

def exampleFunction(): 
#This example function will do things and collect data.
    
timing = Timer(1, exampleFunction) #You create an object called timing. Timing object will now make sure that the exampleFunction will run once every second.

timing(20) #Now the timing function will run a total of 20 times implementing the example function once every second for a total of 20 seconds
 

A delay could be useful when you want to gather data at specific times. For instance, if you only wanted to gather data from your experiment every 30 seconds, you might want to use a delay that lasts for 30 seconds in between the times you capture data. 


 

LIGHT EMITTING DIODES (LEDS).

The LEDs (Light Emitting Diodes) are a set of small devices on your AGAN board that will glow with light when you supply them with power. There are TWO red LEDs that can be turned on and off, as well as a special multi-coloured red-green-blue (RGB) LED that when told can produce all the colours of the rainbow. This LED uses the individual red, green and blue lights in many combinations to do this.

The LEDs on your SAGAN are very handy as they are able to tell you how your programs are running. You can tell an LED to turn on when a sensor finishes gathering data, or even flash when the SAGAN senses something in particular.

For the meantime, we will focus on making the LEDs blink by themselves, in patterns and more. This sensor does not output any data onto the SD card. It will light up and you will visually be able to see it.

 
#This code will help you to understand how to flash LEDs
from LEDS import* #This will import all of the code required to run LEDS


#Firstly you need to create an object
myLed = LEDS()

#Now you can start flashing the different LEDs to create different colours
myLed.LEDOn("Green") #Makes the Green LED from the RGB LED flash
myLed.LEDOn("Red") #Makes the Red LED from the RGB LED  flash
myLed.LEDOn("Blue") #Makes the Blue from the RGB LED  LED flash
myLed.LEDOn("Led1") #Makes Led 1 Flash
myLed.LEDOn("Led2") #Makes Led 2 Flash

#You can also turn Leds off
myLed.LEDOff("Green")
myLed.LEDOff("Red")
myLed.LEDOff("Blue")
myLed.LEDOff("Led1") 
myLed.LEDOff("Led2")

THERMOMETER

There are two dedicated temperature sensors on the SAGAN that are located on the top and bottom of the board. These sensors can be used to collect temperature data on the environment or the temperature of the board as the electronics begin to heat up. This sensor measures the temperature just like any other thermometer you may have used. However, these thermometers don’t use mercury though, they use a modern device known as a thermocouple. At the end of the day, it gives you a more accurate result than a mercury thermometer.

In space, there are many reasons why temperature data is important. If you are inside a spacecraft, a sudden drop or rise of temperature could mean a leak or failure in the air conditioning system. On satellites, temperature sensors monitor electronics to make sure they don’t overheat, this applies to the efficiency of solar panels as well.

 
#Remember to include the two libraries otherwise your code wont work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
toptemp = Sensor("Top Temperature")
bottemp = Sensor("Bottom Temperature")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Top Temperature")
MyLogbook.AddColumn("Bottom Temperature")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(toptemp)
    MyLogbook.NewData(bottemp)
    MyLogbook.NextRow()
#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

BAROMETER

A barometer measures the pressure, temperature, humidity and altitude of the air around the SAGAN. It’s really useful at predicting weather (ever heard of high and low pressure systems?). This sensor isn't used in space that much but it could be used by satellites in LEO to monitor weather patterns and systems down on Earth, or inside manned spacecraft like the International Space Station to monitor the environment of the Astronauts living inside of the spacecraft.

#Remember to include the two libraries otherwise your code won't work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
humid  = Sensor("Humidity")
press  = Sensor("Pressure")
alt    = Sensor("Altitude")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Humidity")
MyLogbook.AddColumn("Pressure")
MyLogbook.AddColumn("Altitude")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(humid)
    MyLogbook.NewData(press)
    MyLogbook.NewData(alt)
    MyLogbook.NextRow()

#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

AMBIENT LIGHT

This sensor measures the brightness of the light surrounding the SAGAN. It detects visible light. So for instance, if you put it in the sun it will read higher than if you put it in a dark room. The ambient light sensor also allows you to get a break down of exactly how much red, blue and green light there is coming from a particular source of light. This is called an RGB sensor and is in-built to the ambient light sensor.

Visible light is just a small part of the light spectrum. The spectrum is a continuum of different wave forms, ranging from heat, visible light, and high energy radiation.

 
#Remember to include the two libraries otherwise your code wont work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
amb  = Sensor("Ambient Light")
rgb  = Sensor("Colour")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Ambient Light")
MyLogbook.AddColumn("Colour")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(amb)
    MyLogbook.NewData(rgb)
    MyLogbook.NextRow()
    
#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

ULTRA-VIOLET LIGHT (UV)

This sensor detects the amount of UV radiation the ASIMOV / SAGAN is exposed to. UV, or Ultra-Violet, is on the far end of the blue side of the light spectrum. In space, the UV radiation is much worse than here on Earth because you aren’t protected by the atmosphere. The atmosphere stops a lot of radiation from hitting the ground (and us) by reflecting it off the surface. That means that satellites get even more radiation in space as they are exposed to extra radiation reflected from the atmosphere!

 
#Remember to include the two libraries otherwise your code wont work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
uv  = Sensor("Ultraviolet")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Ultraviolet")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(uv)
    MyLogbook.NextRow()

#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

INFRA-RED LIGHT (IR)

This sensor measures a particular type of wave, just like UV and visible light, but instead of being on the blue side of the spectrum, it’s on the red side of the spectrum. This is why it’s called infra-RED radiation. Infra-red is basically heat and you know this from seeing things going red-hot. So, when something is hot it radiates infra-red radiation, a variable which this sensor measures.

 
#Remember to include the two libraries otherwise your code wont work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
ir  = Sensor("Infrared")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Infrared")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(ir)
    MyLogbook.NextRow()
    
#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

GYROSCOPE

Gyroscopes are used to measure any movements an object makes. They use something called a gyroscopic effect. This is the sensor that your phone and tablet uses to detect whether you’ve rotated it. Airplanes use them and rockets and satellites definitely do! They help to keep things balanced and pointed the right way. The gyroscope is actually one part of a larger sensor called an IMU or Inertial Measuring Unit that consists of a gyroscope, accelerometer and magnetometer.

 
#Remember to include the two libraries otherwise your code won't work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
gryo  = Sensor("Rotational Acceleration")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Rotational Acceleration")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(gyro)
    MyLogbook.NextRow()
    
#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

ACCELEROMETER

Accelerometers measure acceleration or vibration, as in how much your speed changes over time. You accelerate when you speed up or slow down in your car, bike or even while running, as a change in velocity has occurred. This is includes the acceleration felt from Earth’s gravity by satellites in orbit.

 
#Remember to include the two libraries otherwise your code won't work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
acc  = Sensor("Acceleration")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Acceleration")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(acc)
    MyLogbook.NextRow()
    
#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

MAGNETOMETER

This sensor measures the magnetic field around the SAGAN. In space, this can be useful as satellites travel through Earth's magnetosphere. Larger satellites might monitor this as the magnetosphere can be impacted by large space weather events (like a solar storm).

 
#Remember to include the two libraries otherwise your code wont work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
magnet  = Sensor("Magnetic Field")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Magnetic Field")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(magnet)
    MyLogbook.NextRow()
    
#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

CAMERA

The camera is a camera. It takes pictures and saves them as a jpeg, just like your phone. In space, photos are really valuable and useful. You can monitor weather patterns, natural disasters and everything in between. When you use the camera on the ASIMOV / SAGAN, you'll be able to take awesome photos that show the effects of objects in a microgravity environment. 

NOTE: In order to operate the Camera you need to include a time delay of 2 seconds.

 
#Remember to include the two libraries otherwise your code won't work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
cam  = Sensor("Image")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Image")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(cam)
    MyLogbook.NextRow()
    
#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

REAL TIME CLOCK

A real time clock, or RTC, keeps track of the current time on the SAGAN. It's powered separately from the SAGAN, and is instead powered by the flat, round battery on the bottom of the SAGAN. RTCs record a very accurate time, which can be used to verify other sensors and equipment, or collect time sensitive data. They are found in nearly all electrical devices. 

By knowing the time in which you've collected your data, it can help make your experiments much more accurate.

 
#Remember to include the two libraries otherwise your code won't work
from Logbook import*
from Sensor import*

#Setup sensors and assign variables used for logging
time = Sensor("Time")

#Setup your logbook.html file
MyLogbook = Logbook("logbook1")

#Setup columns in your logbook file to record data
MyLogbook.AddColumn("Time")

#Start recording data in your logbook
MyLogbook.Start()

#The code will start to collect data using a for loop that collects 20 samples
for takeReadings in range(0, 20):
    MyLogbook.NewData(time)
    MyLogbook.NextRow()
    
#Remember to add this software, as it finishes the logbook
MyLogbook.Finish()
 

COLLECTING DATA

Once you've collected your data from your experiment, it will be stored in a html file. Html files open in your web browser, with or without an internet connection. You open them just like any other file you'd open on your computer (just double click on the file). Included below is an example of a html file with data that has already been collected by an ASIMOV / SAGAN and the .py file that was created to collect that data.