Search This Blog

Wednesday, November 22, 2017

Control A.R. Drones with Q.R. Codes


It's been a while since my last post about quadcopters, but I will be showing you a really amazing A.R. Drone trick today.  In this post, I will demonstrate how to let QR Codes generated from a script's text control your A.R. Drone.
Before starting, it is important to note that this guide is for Linux users only (I used Debian, so some parts of the procedure might be different).  The scripts needed to enable the QR reading functionality work best in Linux environments because many of them have a lot of dependencies; it would be a pain to compile, configure, and set the correct paths for those files in Windows (some cannot even be compiled and configured in the newer versions of Windows).  Additionally, make sure that you have node.js, npm, the A.R. Drone modules (refer to my previous guides about programming A.R. Drones) and ffmpeg installed in Linux.

To install node.js and npm:
sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

To install ffmpeg:
sudo apt-get install ffmpeg

Then, install the following dependencies:
sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev

Next:
npm install qrar

By this point, you are nearly ready to make your A.R. Drone read QR codes.  You will also need to create three scripts in the same folder.

Name the first script decoder.js and put this code in it:

var QRAR = require('qrar');
var drone = require('ar-drone');

var codes = new QRAR(drone);

codes.on('qrcode', function (code) {
  console.log(code);
});

codes.start();

Name the second script main.js and put this code in it:

var arDrone = require('ar-drone');
arDrone.createClient().createRepl();

Name the last script qrcodelauncher.sh, and place the following script in it.

node decoder.js | node main.js

Moreover, also generate a few QR codes; only the text of the script is needed in the QR code (Ex. If you want the drone to take off when it sees the QR code, simply generate a QR code representing "takeoff()").  For a list of all possible functions, check out the Client API section of this link.

Now, you can finally show a QR code to your A.R. Drone.  As long as it is valid, your drone will respond!  However, you might have to wave it a few times for it to respond (your console will also output what it sees from the QR code).  I attached a few QR codes to get you started.

To takeoff:


To land:

Stay tuned for more cool A.R. Drone guides!

Saturday, July 8, 2017

Converting CT scans into 3D printable models

In this post, I will show you how to convert CT scans into 3D printable models.  With this technique, you can extract different structures in a person's body and then print them out to use in experiments or to just keep as decor.  Many scientists use this technique to study individual patients and try to develop a specialized solution for their patients; for example, one UCSD professor 3D printed a patient's brain aneurysm to study his blood flow and determine the best course of action.  I had to perform these tasks at a recent bioengineering internship.

Steps:

1. Download a DICOM file:  You can find many DICOM files that are for public use on online databases (these files are also quite large).  However, the DICOM file you download must be from a CT scan and when you extract the zipped DICOM, it must end up as a folder with many subdirectories filled with dcm files (some websites provide a you with a single dcm file and that will not work in this method).

2. Install Invesalius 3.0.  This software was designed by the Brazilian government for research purposes but is now only hosted on Github.  Go to the releases section on their Github page (https://github.com/invesalius/invesalius3/releases) and download the correct installer for your operating system.  Once your download finishes, just install it; there is no bundled malware and adware.  You can also compile it with the Github source code, but this process is very complicated and convoluted (don't even try this process if you run Windows).  However, if you are a Linux user (especially Ubuntu users) and would like to attempt this, you need to first follow their repo's instructions, but DO NOT install Python-vtk6 and USE PIP to install Cython.   If you followed the repo's instructions completely, many of your Python based programs will break because python-vtk6 breaks the dependencies for the commonly used python-vtk and your compilation progress will fail because apt-get does not provide the newest version of Cython.

3. Open up your DICOM file with Invesalius by navigating to File - import DICOM.  Next, without clicking on any of the image groups, press the import button.  This action will load the Dicom images on three different planes.  Windows users may need to move the scroll icon a little on each of the four boxes that appear afterward in order to visualize the CT scan.

4. Scroll around on each plane until you find your region of interest.  Then, on the Create New Mask tab, you can use a predefined preset (Ex. muscle, bone, fat) or play around with the mask settings until your region of interest is selected. Remember, the area in green is the selected area.
The predefined presets give users a faster way to select an area of interest; however, it does not work everytime.

5. Now, check Overwrite last surface and press Create surface.  This process generates the 3D model and will take a while.

6.  You can play around with Configure 3D surface, but that step is not necessary.  You can get the stl file now by clicking Export 3D surface.

7. Now download and install MeshMixer here.

8. Open up the exported stl file with MeshMixer. With this tool, you can isolate a specific section of your region of interest (Invesalius's masking tool leaves a lot of extra unnecessary regions.  For example, when I was isolating an abdominal aorta, Invesalius left the spine in the exported stl).

9. You rotate the 3D object by holding the right click button and you pan the view by holding down the middle click button.

10. Press select and use the brush tool to select regions you do not need.  You can either draw shapes around or paint certain regions; the program will highlight those regions orange.  Then, press the del key (not the backspace one) on your keyboard to delete that region.  Repeat this procedure until you have isolated your region of interest; this procedure will take a while.

Highlighted regionn for deletion
The abdominal aorta I isolated from the torsa region of a CT scan

11. Now, you can smooth your model.  Use the brush tool, paint the entire object, and press Ctrl F.  A window will pop out and you need to click accept in order to finalize the smoothing procedure (you can play around with the smoothing settings in that window).
The abdominal aorta after smoothing
12. Now export the model as a stl file.  In order to 3D print, you will need to run it through a program that will convert the stl file into a GCODE file (Ex. Slic3r).  However, you will need to also generate support for the model and the printed model's resolution may not be as great as the one you see on MeshMixer.  You can also 3D bioprint the model with printers like the BioBot, but that procedure is much more complicated and is different for each printer and each type of material.