Final Presentation

The project was presented in class last Thursday, among many other great projects!

This post is only to share links for the presentation, the time-lapse video of the project working and the github repository with a final report and the code.


Schematics and Arduino Code

The project is working fine and will be presented tomorrow during class. Here are the schematics for the circuit.

finalProject2_schem finalProject2_bb

The arduino code is pretty straight-forward: moving the servos and reading from the sensor. During development two main problems were found. Reading from the sensor inside nested loops was not working properly, making the servos behave unexpectedly. A solution was using conditionals inside the arduino loop() to make the servos move. Another problem was communicating with the PC: took us some time to figure out that the string being sent through the serial port should have a fixed length, therefore adding leading zeros to the angles and the sensor values solved the problem.

New servo arrived!

The new HS-422 servo arrived and we had to disassemble everything to replace it. We used this opportunity to prettify our enclosure with some black spray.

We also have a battery now! Using one of those portable chargers (which we already had) we were able to cut a USB cable and plug it to the protoboard. It is a 15,000 mAh battery with a maximum discharge of 2.1 amps, a bit overkill for our project but it works!

20150324_111719 20150325_165706 20150325_165759

Since I had the idea of painting it black, I had to do it. Meanwhile Arthur was cutting and soldering the battery adaptor and then assembling everything again in the box after it dried.

Software – Under the hood

It is hard to get into the details of our software, but we can explain at least how it works.

As this is a fairly small project (around 1100 lines of code) we decided to leave the loop in the main file, but we tried to keep it simple and clean.

The first lines of codes create all our objects, which are: Rendering Window, an Input Manager, a Window Manager, a Menu and an array of objects to be displayed on screen.

Our main loop is quite simple. It checks what is the current state of the program to decide on what to do. So basically the main loop looks like this (this is not the full code but it can give the idea of what is happening):

while (running)
        //Update objets
        //Clear sceen
        switch (state) {
            case RUNNING: 
                Draw manager
            case MENU: 
                Draw Menu
            case EXIT:
        //Check if user has exited the program by clicking the X button
        if (input.getExit())
            running = false;

        //Swap buffers and display the backbuffer on the screen


The Input Manager object is responsible for everything that has to do with IO. That means it is responsible for saving files, loading files, reading key strokes, reading from the serial and everything IO related. Whenever an object needs to call a IO function it will call a method on the InputManager which will return the desired result.

The WindowManager draws the 3D view on the screen and allows the user to interact with that view. Even when the user is in the Menu, this object is responsible for drawing the main view of the scene. It also setup the OpenGL paramenters when the program starts and change the parameters to adapt for the 3D and 2D view.

To display the data on the screen we use cubes. We have  Cube class that has position, size and color used to store all the cubes information. All the cubes that are being displayed in the 3D view is kept in an array which the main function creates it. Everything that the data from a file is going to be read, this array is passe by reference to the InputManager which clears the previews data and load with the information on the file.

The Menu is composed of a GUI which is keeps all GUIElements. A GUI is basically a class that manages all the GUIElements. Each GUIElement has position, size, text and other attributes that can be shared between all types of elements such as Buttons, Frames (for displayed the saved files) and Panels. The Menu checks if any button is pressed and trigger a function according to it.

A particular GUIElement is the GUIFrame which also displays a 3D view. This element shows a preview of a saved file so that the user can view the file before loading it into the main view. When using 2D and 3D views in OpenGL we must take care of the MatrixMode and the View Perspective. So everytime a frame is displayed it first draws it’s 2D component, and then it changes the OpenGL parameters to 3D to draw the preview of the file.

We started implementing a feature that allows the user to “walk” inside the 3D scanned room using the classic first person view, but we did not have time to take it further as it was quite complex using OpenGL.

Software – The basics

In order to view all the data collected from the range sensor, we’ve built a software that makes possible to view all the measurements in a 3D space.

The idea behind the software is pretty simple:

  1. The arduino reads the sensor and sends the data via serial to the PC. The data sent to the computer consists of the distance and the angle of each stepper motor.
  2. With a C++ Serial Library we read the serial data in batches. As we are using just the USB cable to read from the serial, we have to use work arounds in order to get the data without any noise. It would be better to buy an adapter USB/Serial Port.
  3. The software reads the data and change the coordinate system to the regular Cartesian. This can be done easily as data from the arduino is in Spherical Coordinates.
  4. All the data from all measurements is saved in a file and displayed in the screen.

For now we are simply displaying the data and building a robust software. After finishing all the details on the software we are going to try to work on the data to apply filters and build a more realistic 3D Scene.

You can see bellow the main screen of the software.


If you choose to Load a file, it will show a preview of the file before loading it in the main scene. If you save a file it will automatic be listed together with all the previews files.


The capture mode is also in real time. You can see all the data being plotted in the screen during the capture.

The software was tricky to build as we are using OpenGL and C++. It could be more easily implemented using a high-level interface library. We use cubes to display the measurements as it is the most similar to dots in a 2D space. We also store everything in arrays so it is easily to work and the access of the elements is quite fast.

We built a structure to minimize our work. So we have a class to handle all the GUI components, a class to handle the inputs (Save to file, load from file, keyboard inputs…). We also have a class that manages the main view, which you can navigate using the WASD keys and the mouse to look around.

The software is still under construction and may change until the presentation.


Now the focus was on building the enclosure. While thinking about several options, we noticed that the box in which the components were shipped was quite robust, so why not?

Arduino fits perfectly with the protoboard:


Cut a hole for the USB port:


Another hole to place the servo, and securing it with glue-gun:

20150318_181313 20150318_181317

And then connect all the tables:


After some testing we found problems. The servo used from ardx arduino kit was not powerful enough,so we had to order a new one (another HS-422). In order to the arduino being able to power all the electronics we had to wake up the lidar, make the reading, sleep it and then move the servos. This was really time consuming, specially because we have to repeat this procedure for the 32,400 readings, which adds up a lot of time. Changing the lidar to continuous-read mode solves the problem but need more power than the arduino is able to supply. Well, now we a need a battery to power everything.

LIDAR Mounting

The pan-tilt mount for the servos and a new powerful servo (hs-422) were delivered, allowing us to build the rig for mounting the LIDAR. For the tilt movement we used the HS-422 and for the pan we used the servo from our ardx arduino kits.


All the sensor and servos wires were connected to jumper wires and secured with a glue-gun.


Everything was finally connected to arduino so the code could be written and tested in real time.


Initial tests with Lidar-LITE

We finally got our Lidar-LITE delivered from France (bought from EU RobotShop) and started making some tests. We wired everything and the lidar is quite good for the purpose we need. It measures corners precisely (the sonar would bounce on corners and give wrong readings) and has a good accuracy (+- 2.5cm) and a good range (~40m). According to the datasheet, its beam width is around 1.5º, which gives us around a 25 cm range over objects positioned 10m from the sensor.

Using the same software and servo mount from the hackday, we used the following setup to try and map it in 2D only:


This is the result we got. We can clearly see the walls and the computers identified by the sensor.


One problem we found, since it is a laser-based sensor, is that it cannot measure distances to very shiny surfaces (which reflects a lot of light) or to windows, since the beam goes through it. Unfortunately there is not a sensor that would be good for all the situations, so we are sticking with the lidar because it is the one that suit us best.

Next steps are acquiring servos and coming up with a pan and tilt mount so we can move the lidar around.

Projects plans

After our brainstorming section this week, we sketched the basics of our project structure, including the C++ classes and what features would the software support. We also talked about what tasks each one would be initially working on, as we have a lot of research to do and work to be done.


  • Use of Lidar-Lite as range finder
  • Two servos to create a pan and tilt movement
  • External power supply for the servos
  • Enclosure to hide the arduino and power supply


  • C++ and OpenGL
  • Ability to save and load scanned rooms
  • Easy to interact menu
  • Interactive 3D View of the real-time scanning

As we both have previous experience in both hardware and software, we randomly assigned which area (hardware or software) to each of us would lead. André will be responsible for leading the hardware development and I will be leading the software development. We also have regular meetings so it is easy to help each other on any decision regarding the development and to help each other on the hardcore stuff.

Hacksmiths Hack-Day – 12/02/2015

We participated on the Hacksmiths Hack-Day which was an event to create something in 7 hours (more or less). About six groups showed up, and as always we did not have idea of what to do. Since we didn’t want to stay thinking about an idea for the whole thing, we decided to try something related to our Physical Computing project.

During the Hack-Day we were able to build a prototype to demonstrate the concept of our project. We used one servo motor and one ultrasonic to rotate in 180º and measure the distance in all these degrees. We used the Arduino as micro-controller and we used C++ with SFML to capture the data from the serial port and print in the screen.

We got very disappointed to discover that the ultrasonic sensor is very limited and it can’t measure distance from objects that are not perpendicular to the sensor beam, like corners. We also had to apply some filters in the data to remove noise from the incoming data. Later on we found out that the noise was mostly because the servo motor and the sonar were connected in the same power supply, which can generate noise in the sonar.

During the hack-day we also researched for a good alternative to the sonar and we ordered the Lidar-LITE which is a laser range finder and is 2.5x times faster than the sonar and very accurate.

You can see the video of our hack in the event webpage bellow: