Difference between revisions of "Flynntestpage"

From Stanford SSI Wiki
Jump to navigation Jump to search
(Sort of works?)
 
(docx and odt seem to work equally well. ODT has weird spacing, both bolded a section incorrectly)
 
Line 1: Line 1:
= Dataplicity Tutorial 1: Getting Access, Online Interface, and Unix Tools =
+
'''Why do we need this?'''
  
We use Dataplicity to remotely manage Raspberry Pi’s and access to flight hardware such as PyCubed. First, ask Langston, Moritz, or Flynn for access to Dataplicity.
+
The normal way our telemetry radio communicates is LoRa, which is a proprietary form of modulation designed for long distances. CircuitPython already has libraries for LoRa.
  
https://www.dataplicity.com
+
However, as part of the satellites operations, the satellite will need to transmit a beacon. This is basically a very slow, weporful message that we decide ahead of time. It is usually transmitted using morse code. As an example, our satellite might transmit "SSI" in morse code. This is usually implemented using something called On/Off Keying (OOK). Basically, the radio turns on to transmit a one and turns off to transmit a zero.
  
Head over to the <code>devices</code> page:
+
Our radio's hardware supports OOK, and there are drivers written for it already. However, none are in CircuitPython.
  
[[File:https://media.githubusercontent.com/media/stanford-ssi/sequoia-software/assets/dataplicity/devices.png=true|thumb|none|alt=Devices|Devices]]
+
'''How do we implement this?'''
  
Select the <code>Sequoia</code> Raspberry Pi:
+
It's pretty much just writing a driver for the radio. We write values to various registers to set the radios configuration, and to receive and send messages. We will do this in CircuitPython.
  
[[File:https://media.githubusercontent.com/media/stanford-ssi/sequoia-software/assets/dataplicity/pycubed_mnt.png?raw=true|thumb|none|alt=PyCubed|PyCubed]]
+
'''What do we have to work off of?<br />
 +
'''We will start with the codebase for the existing driver ([https://github.com/adafruit/Adafruit_CircuitPython_RFM9x <u>here</u>]). We also have the RFM98 datasheet ([https://cdn.sparkfun.com/assets/learn_tutorials/8/0/4/RFM95_96_97_98W.pdf <u>here</u>]). This is pretty much the same datasheet as the underlying radio chip, the SX1278 (datasheet is [https://www.semtech.com/products/wireless-rf/lora-transceivers/sx1278 <u>here</u>]). There's an existing implementation of the driver in the RadioLib library, except it's written in C ([https://github.com/jgromes/RadioLib <u>here</u>]). There are most likely other implementations (tip: you'll have more luck finding info if you search for SX1278, not RFM98).
  
The PyCubed drive is mounted at <code>/media/PYCUBED</code>. In the web view here, there are a number of software tools available to you, such as the ability to reboot, in the right column. All of the unix tools installed on the Raspberry Pi are somewhat accessble to you–for example, you can use the <code>nano</code> text editor to edit files but you can’t use the <code>scp</code> command to copy files from your computer to the Raspberry Pi in this interface.
+
With regard to RadioLib, most of the code is in the folder src/modules/SX127x/, in SX1278.cpp, SX127x.cpp, and their corresponding .h files. You can start in the beginFSK functions and then follow the code from there. FSK is another type of modulation, and the functionality for OOK is linked to the functionality for FSK (you'll see what I mean if you look at the relevant datasheet sections).
  
== Editing files on the PyCubed drive ==
+
'''On a high level, how does the radio work?'''
  
Let’s edit a file on the PyCubed drive with <code>nano</code>!
+
Basically, the registers all have different functions in OOK mode versus LoRa mode. In OOK mode, we can set the relevant configurations (it looks like they will be bitrate, current limit, frequency, bandwidth, power, and preamble length). We can then create transmit and receive functions (it looks like the radio has intermediate states between transmit and receive, but they might be irrelevant). To receive, theres a FIFO that we put data in, which is read by SPI (there's another way to do this but it's probably not what we want). There's also some weird things with node addressing to be cognizant of.
  
<source lang="bash">nano main.py</source>
+
'''What are some potential hurdles?'''
[[File:https://media.githubusercontent.com/media/stanford-ssi/sequoia-software/assets/dataplicity/nano_main.png?raw=true|thumb|none|alt=Nano main|Nano main]]
 
  
<code>Enter</code> to edit the file. Once you make your edits, type <code>ctrl-o</code> to “write” the file. Then, do <code>ctrl-x</code> to exit.
+
It will be hard to test since it's very low-level code. Also, it looks like the OOK module is designed to prepend a preamble to the data it sends, which might not be the behavior we want. There are two modes to use the OOK module, one involving raw pins, and I'm not sure which to use yet.
 
 
[[File:https://media.githubusercontent.com/media/stanford-ssi/sequoia-software/assets/dataplicity/nano_main_save.png?raw=true|thumb|none|alt=Nano main save|Nano main save]]
 
 
 
== Copying files to the PyCubed drive ==
 
 
 
Make a file and put some stuff in it.
 
 
 
[[File:https://media.githubusercontent.com/media/stanford-ssi/sequoia-software/assets/dataplicity/tmp_test.png?raw=true|thumb|none|alt=Temp test|Temp test]]
 
 
 
This time, let’s save the file with <code>ctrl-s</code> (same as <code>ctrl-o</code> but it does not prompt for a file name). Then <code>ctrl-x</code> to exit.
 
 
 
[[File:https://media.githubusercontent.com/media/stanford-ssi/sequoia-software/assets/dataplicity/nano_save.png?raw=true|thumb|none|alt=Nano save|Nano save]]
 
 
 
Make sure you saved the file with the <code>cat</code> command (<code>cat</code> is technically for concatenating (combining) files, but works fine for printing them in the terminal!)
 
 
 
[[File:https://media.githubusercontent.com/media/stanford-ssi/sequoia-software/assets/dataplicity/cat.png?raw=true|thumb|none|alt=Cat image|Cat image]]
 
 
 
Now, we will move the file to the PyCubed with the <code>cp</code> (“copy”) command. Syntax for this is
 
 
 
<source lang="bash">cp SOURCE DESTINATION</source>
 
For you, this would be:
 
 
 
<source lang="bash">cp tmp/test /media/PYCUBED/</source>
 
[[File:https://media.githubusercontent.com/media/stanford-ssi/sequoia-software/assets/dataplicity/copied.png?raw=true|thumb|none|alt=Copied|Copied]]
 
 
 
Print the file in your terminal with:
 
 
 
<source lang="bash">cat /media/PYCUBED/test</source>
 
And then delete the file with:
 
 
 
<source lang="bash">rm /media/PYCUBED/test</source>
 
Despite all of these cool things, ''we don’t recommend using the web interface'' because it crashes fairly often.
 
 
 
 
 
-----
 
 
 
== Next Steps ==
 
 
 
Checkout the [[tutorial_2.md|next tutorial]] to learn how to access Dataplicity enabled Raspbery Pi’s with Porthole in your desired terminal—-on your computer, ''not'' in a browser!
 

Latest revision as of 00:55, 27 October 2020

Why do we need this?

The normal way our telemetry radio communicates is LoRa, which is a proprietary form of modulation designed for long distances. CircuitPython already has libraries for LoRa.

However, as part of the satellites operations, the satellite will need to transmit a beacon. This is basically a very slow, weporful message that we decide ahead of time. It is usually transmitted using morse code. As an example, our satellite might transmit "SSI" in morse code. This is usually implemented using something called On/Off Keying (OOK). Basically, the radio turns on to transmit a one and turns off to transmit a zero.

Our radio's hardware supports OOK, and there are drivers written for it already. However, none are in CircuitPython.

How do we implement this?

It's pretty much just writing a driver for the radio. We write values to various registers to set the radios configuration, and to receive and send messages. We will do this in CircuitPython.

What do we have to work off of?
We will start with the codebase for the existing driver (here). We also have the RFM98 datasheet (here). This is pretty much the same datasheet as the underlying radio chip, the SX1278 (datasheet is here). There's an existing implementation of the driver in the RadioLib library, except it's written in C (here). There are most likely other implementations (tip: you'll have more luck finding info if you search for SX1278, not RFM98).

With regard to RadioLib, most of the code is in the folder src/modules/SX127x/, in SX1278.cpp, SX127x.cpp, and their corresponding .h files. You can start in the beginFSK functions and then follow the code from there. FSK is another type of modulation, and the functionality for OOK is linked to the functionality for FSK (you'll see what I mean if you look at the relevant datasheet sections).

On a high level, how does the radio work?

Basically, the registers all have different functions in OOK mode versus LoRa mode. In OOK mode, we can set the relevant configurations (it looks like they will be bitrate, current limit, frequency, bandwidth, power, and preamble length). We can then create transmit and receive functions (it looks like the radio has intermediate states between transmit and receive, but they might be irrelevant). To receive, theres a FIFO that we put data in, which is read by SPI (there's another way to do this but it's probably not what we want). There's also some weird things with node addressing to be cognizant of.

What are some potential hurdles?

It will be hard to test since it's very low-level code. Also, it looks like the OOK module is designed to prepend a preamble to the data it sends, which might not be the behavior we want. There are two modes to use the OOK module, one involving raw pins, and I'm not sure which to use yet.