• Component A UnitTest Class Diagram
    18th, March
    Data Driven Testing with Qt

    !! Code available on my GitHub toskyRocker account !!

    Hi everyone,
    today I’m here to show a brief example of a completely Data Driven Test Suite implemented with the Qt Framework.

    The main goals are:

    • Showing how to execute data driven tests with QtTest.
    • Handling input and verification data directly from a configuration file.

    The focus will be on the configuration and execution of the test rather than on the complexity of the test itself.
    Before digging into the details, clone the repository and open the main project in QtCreator by clicking on Compoent_A_UnitTest_Project.pro.

    The software has been developed with Qt 5.8.0 and QtCreator 4.4.1 in Windows 10.

    Configure then the Build and Run Settings in QtCreator as it follows:

    QtCreator Build Settings

    QtCreator Build Settings

    As depicted in the picture I specified the shadow build, providing its path and I added an extra Build Step where I added: “install clean” in Make Arguments.

    This is needed when you want to perform the install step in order to have all the dependencies installed in your bin folder.

    QtCreator Run Settings

    QtCreator Run Settings

    In the Run Settings shown above I simply specified the configuration file needed to run the test.

    The configuration file can be found at the following path of this repo: Qt_Data_Driven_Test_Suite\Component_A_UnitTest\component_a_unit_test_data.json.

    To execute the program then, just specify the following command line argument:
    -config C:\Users\[path-to-repo]\Qt_Data_Driven_Test_Suite\Component_A_UnitTest\component_a_unit_test_data.json

    Now that we have configured the project we are ready to go through the details.
    The following UML diagrams show the structural and behavioural views of the Test.

    Let’s say we have a class named Component_A which will be our software under test.
    In this simple example Component_A has got only the following method doPow()  which implements the exponentiation provided
    a base and an exponent values as input.

    Component_A_UnitTest will have an instance of Component_A and will run the tests on it by executing doPow() as many times as the entries of the Test Suite.
    In order to avoid hardcoded and make the same program reusable with different inputs, the configuration file has been conceived to store all input and verification data belonging to each Test Case defined in the Test Suite.

    From the picture below, you can see that the configuration file consists of a json file where a list of Test Cases are defined.
    For each Test Case, an ID, input data and verification data are provided so that they can be loaded up and used in the test execution.

    Each block, representing a Test Case holds the following information:

    • Test Case ID: identifier
    • Base value: used as input for the exponentation
    • Exponent value: used as input for the exponentation
    • Expected result: value used in the verification step to check whether the implementation of the exponentiation works as expected.


    Component A Unit Test Configuration File

    Component A Unit Test Configuration File

      In addition to Component_A, the diagram below depicts all the other classes in the project that contribute to run the tests:

    • Component_A_UnitTest is the principal class, implementing the Qt data driven strategy. It takes advantage of an instance of
      JsonFileParser to store the data read from the configuration file.
    • JsonFileParser is an helper class which provides the functionalities for reading the configuration file and storing the extracted information in member data structures (list of TestCaseInfo objects).
    • TestCaseInfo is the class which holds all the information belonging to a single Test Case specified in the configuration file.
    Component A UnitTest Class Diagram

    Component A UnitTest Class Diagram

    The execution of a single Test happens in testProcedurePow(), where providing the right input values,
    Component_A_UnitTest calls Component_A::doPow(), fetches the result and compares is with the expected one.

    As described on Qt Documentation (Qt Test Tutorial),
    for each test procedure X(), the user has to define its matching X_data() method which is foundamental for loading and making available all the data needed in each test procedure execution.
    X_data() builds its internal representation of the Test Suite where each column defines a parameter and each row represents a test.
    The Qt application will then execute X() as many times as the number of rows defined in its table.

    In our specific case, since we have only 2 Test Cases described in the configuration file, there will be 2 execution of testProcedurePow(), each time of course providing and validating the right information, thanks to the mechanism explained.

    The following snippet show exactly this strategy where in testProcedurePow_data() I populate the table by adding each row’s information.

    Each testProcedurePow() needs to know the information previously defined in the configuration file and imported thanks to JsonFileParser.
    This is performed in testProcedurePow_data() which populates the table with all the information.

    void Component_A_UnitTest::testProcedurePow()
        // Fetching all the needed data to run the test from the table
        // defined in testProcedure_pow_data()
        // Fetching the information by providing the key
        QFETCH(QString, test_case_id);
        QFETCH(QString, base);
        QFETCH(QString, exp);
        QFETCH(QString, expected_result);
        qDebug() << "Component_A_UnitTest::testProcedurePow - " << test_case_id;
        // Converting the input data to the needed type
        int baseValue = base.toInt();
        int exponentValue = exp.toInt();
        int expectedValue = expected_result.toInt();
        // Performing the needed operation that need to be tested
        int actualValue = testData->cmpA->doPow(baseValue, exponentValue);
        // Verificaiton Step
        QCOMPARE(actualValue, expectedValue);
    void Component_A_UnitTest::testProcedurePow_data()
        // Populating Columns' headers
        // Populating each row i.e. test
        for(TestCaseInfo testCaseInfo : testData->parser->getTestCaseInfoList())
            // Doesn't accept QString. It needs to be converted to std String
            QString testCaseID = testCaseInfo.getTestCaseID();
            const char* testCaseID_std = testCaseID.toStdString().c_str();
            QString base = testCaseInfo.getInputData().value(BASE);
            QString exp = testCaseInfo.getInputData().value(EXP);
            QString expectedResult = testCaseInfo.getVerificationData().value(EXPECTED_RESULT);
                    << testCaseID
                    << base
                    << exp
                    << expectedResult;

    A behavioural overview is shown in the sequence diagram below that remarks the data driven approach implemented by Qt.
    The core of the program relies in the loop that iterates over the rows of the table, calling each time and sequentially: init(), testProcedurePow(), cleanup().

    Component A UnitTest Sequence Diagram

    Component A UnitTest Sequence Diagram


    Read More
  • Arduino Light Mood Lamp
    16th, February
    Arduino Light Mood Lamp with RGB LEDs

    !! Code available on my GitHub toskyRocker account !!

    Hi folks,

    today I’ll show a simple project I realised for Valentine’s day for my girlfriend.
    The main purpose is using Arduino Uno to build a small ambient lamp which changes LED colours depending on light intensity.
    I have simply adopted few 10mm RGB LEDs, an Arduino Uno as prototyping board and 1 rice paper sheet to make the flower lamp shape.
    The lamp can be powered by one 9V battery or with a 5V-1A adapter.

    Bill of materials:

    – Arduino Uno
    – 2x (up to 3) 10mm RGB LED
    – 1x Photocell
    – 1x 10kΩ resistor
    – 1x Rice paper sheet 30×30 cm
    – 1x Paper box or similar
    – 1x 9V Battery Holder OR 5V-1A adapter


    1 – Electronic wiring

    For a simple prototype, just follow the wiring below and upload the code found at my GitHub Account.
    Remind that to better understand the code concerning fading have a look to my previous tutorial Fading LEDs with Sin Wave.
    You can obviously, modify any range and combine OFFSET and AMPLITUDE of each RGB component to create more colours.

    With my settings the output fading colours are:
    – Green Orange in full light
    – Red Magenta in medium light
    – Red Blue in semi darkness ambient
    – Red in dark ambient

    Arduino Light Mood Lamp Fritzing

    Arduino Light Mood Lamp Fritzing

    2 – Lotus Flower Origami

    Choose the color of your rice paper sheet. I suggest pink, or any light colour.
    Follow the tutorial below:

    3 – Putting all together

    Once you got the flower, you need to assembly a small box or any other vase, container to put all the electronic part inside.
    Before doing that, solder all the wiring shown in step 1.
    Choose to power Arduino with 9V battery or with adapter.

    Read More
  • Led Fading with Sin wave
    15th, February
    Fading LEDs with sine wave

    Hi everybody,
    the purpose of this post is to explain a simple technique concerning LED fading.
    One common issue in fading a LED is blocking the execution of the loop() in a for loop as long as it performs the fading.

    void loop() {
      // fade in from min to max in increments of 5 points:
      for (int fadeValue = 0 ; fadeValue &amp;amp;amp;lt;= 255; fadeValue += 5) {
        // sets the value (range from 0 to 255):
        analogWrite(ledPin, fadeValue);
        // wait for 30 milliseconds to see the dimming effect

    This approach wastes a lot of resources since the microcontroller can only perform this action until the execution goes on after the for loop.

    One possibile solution is to drive LED fading with a sin/cos wave.
    This means that at each iteration a harmonic oscillator value is assigned to the LED.

    The simple harmonic oscillator equation is:
    x(t)=A\cos(\omega t + \phi)

    So, we basically need the amplitude A, ω the angular frequency \omega =\frac{2\pi}{T} and finally the optional φ which determines the starting point on the sine wave.

    Let’s take a common cos wave shown below.

    Cosine wave

    Cosine wave

    This function oscillates in range [-1;1]. To perform a complete LED fading we need to simply modify our cos wave to our purpose.
    Arduino’s output is always between [0;255] (256 values); for this reason we need a cos wave that start at 128 and oscillates oscillates between 1 and 255 to get a reasonable range (128±127).
    The picture below shows y=128+127cos(x), which is the starting point to create our harmonic oscillator.
    The OFFSET 128 shifts my cos wave from 0 to 128 and the AMPLITUDE 127cos(..) tells me that we want to amplifier our wave by 127x.

    Cosine wave - fading LED

    Cosine wave – fading LED

    What happens if we modify the OFFSET or the AMPLITUDE?
    Let’s say we assign OFFSET = 150. This means that our wave OFFSET is shifted from 128 to 150 and it will oscillate in range [23;277] (note! same AMPLITUDE=127, oscillation 150±127) exceeding the upper bound and having 23 as min value. This means our led will never assume 0 value.
    The upper and lower bound issues are easily fixed with a check function which clips the current value to 0 or 255 when it exceeds the bounds.

    Modifying the AMPLITUDE, i.e. AMPLITUDE = 100, will cause a smaller oscillation around my OFFSET.
    Play with these coefficients to get your best result!

    Here there’s a sample code.

    Andrea Toscano 2016
    // Arduino LED PIN
    #define LED_PIN 10
    // Baudrate for Serial Communication
    #define SERIAL_BAUD 115200
    // Time period of fading in millisecs
    #define PERIOD 2000
    // Angular Frequency by definition
    #define OMEGA 2*PI/PERIOD
    // No Phase
    #define PHASE 0
    // Offset of the sine wave
    #define OFFSET 128
    // Amplitude of the sine wave
    #define AMPLITUDE 127
    // Used to generate time for the cos wave
    unsigned long timer = 0;
    void setup() {
      // Uncomment for serial monitor
    void loop() {
     timer = millis(); // updating time
     int ledValue = OFFSET + AMPLITUDE*(cos((OMEGA*timer)+PHASE));
     analogWrite(LED_PIN, checkValue(ledValue));
    // Useful to avoid LED values outside the bounds [0;255]
    int checkValue(int val) {
      if (val &amp;amp;amp;gt; 255)
        val = 255;
      else if(val &amp;amp;amp;lt; 0)
        val = 0;
      return val;
    Read More
  • Comelicottero Team and Zoe Romano @ WeMake Milano
    11th, October
    Comelicottero Team @ WeMake Milano

    Thanks to Zoe Romano (Digital Strategy and Wearables @ Arduino) Comelicottero Team had the opportunity to explain their quadcopter project to the enthusiastic audience of the WeMake makerspace fablab !



    This slideshow requires JavaScript.


    Comelicottero quadcopter developed by Andrea Toscano, Simone Castellani and Giovanni Intorre at Università degli Studi di Milano (UNIMI) – Informatica Magistrale

    Read More
  • DALab team - Università degli Studi di Milano
    09th, August
    DALab @New Game Designer 2015 – Università degli Studi di Milano

    Digital Architecture Lab. took part at New Game Designer 2015 on July 2 at Università degli Studi di Milano.
    DALab team (Andrea Toscano, Federico Pedersini, Simone Mentasti) exhibited new and old projects like Comelicottero quadcopter and FPGA Tetris

    DALab - Stand @ New Game Designer 2015 - Università degli Studi di Milano

    DALab – Stand @ New Game Designer 2015 – Università degli Studi di Milano

    DALab team - Università degli Studi di Milano

    DALab team – Università degli Studi di Milano

    Read More
  • Comelicottero on www.arduino.cc
    11th, June
    Comelicottero quadcopter on Arduino.cc website

    Comelicottero quadcopter Project will be soon available on www.arduino.cc‘s Forum.
    Some tutorials will be provided in order to set up Comelicottero’s firmware on Yun and the Ground Station on the personal computer.

    See Arduino Blog for further info: http://blog.arduino.cc/2015/06/08/building-a-quadcopter-running-on-arduino-yun/

    Comelicottero developed by: Andrea Toscano, Giovanni Intorre, Simone Castellani.
    Andrea’s Supervisor: Prof. Federico Pedersini
    Università degli Studi di Milano – Informatica

    Stay Tuned!

    Read More
  • Arduino Yun ESC - 400Hz PWM Signal (Comelicottero)
    02nd, June
    400Hz PWM on Atmega32u4 for multirotors (without using Servo Library)

    !! Code available on my GitHub toskyRocker account !!

    The main issue using the Servo Library is that you can hardly go faster than 125Hz, with a huge amount of interrupts generated. I use instead 16bit Timer1 and Timer3 to generate PWM signals @400Hz on 4 pins (up to 6 pins). No interrupts are required.

    First of all you need to know what a timers and interrupts are: Timers and Interrups on Arduino

    Once you got some basic info you can read the Atmega32u4 Datasheet for a better comprehension of Timer1 and Timer3 adopted in my code working on any Arduino with Atmega32u4 (Arduino Yun, Micro, Leonardo)

    Andrea Toscano 2015
    Microcontroller : Atmega32u4
    PWM FREQUENCY @ 400Hz for multicopters
    USE PIN   5,9,10,11*/
    #define motor0 OCR1A // PIN 9
    #define motor1 OCR1B // PIN 10
    #define motor2 OCR1C // PIN 11
    #define motor3 OCR3A // PIN 5
    /* These values depend on ICR1 and ICR3 
       You may vary the following parameters if your 
       ESCs seem 
    #define MIN 2200 
    #define MAX 3800
    int motorValue = 0;
    unsigned long newMills = 0;
    unsigned long oldMills = 0;
    void setup()  {
      // Timer 1
      // Pin Setup
      // Output Direction
      DDRB |= (1 << 7) | (1 << 6) | (1 << 5);
      ICR1 = 0x1387;  // 400Hz
     bit 7:2 Compare output mode 3 channels.  
     Setting OCnA/OCnB/OCnC on comptare match, set output to LOW
     bit 1:0  Fast PWM, TOP: ICRn  Modality
      TCCR1A = 0b10101010;
    bit 7:5 Don't Care
    bit 4:3  Fast PWM
    bit 2:0 Prescaler: clock/8
      TCCR1B = 0b00011010;
      // Initializing output variables
      motor0 = 0;
      motor1 = 0;
      motor2 = 0;
      // Timer 3
      DDRC |= (1 << PC6); // motor3  PWM Port.
      ICR3 = 0x1387;  
      TCCR3A = 0b10101010;
      TCCR3B = 0b00011010;
       // Initializing output var
      motor3 = 0;
      motorValue = MIN;
    /* Test the duty cycle with an oscilloscope
       Loop will vary from min to max
    void loop()
      newMills = millis();
      if (newMills - oldMills > 100)
        motorValue += 5;
        if (motorValue == MAX)
          motorValue = MIN;
        motor0 = motorValue;
        motor1 = motorValue;
        motor2 = motorValue;
        motor3 = motorValue;
        oldMills = newMills;
    Read More
  • Metro Drone Challenge - Andrea Toscano - Award Ceremony (Rome Drone Expo 2015)
    01st, June
    Metro Drone Challenge (Roma Drone 2015) – 2nd place winner

    2nd place Winner – Metro Drone Challenge with “Duomo di Milano” shot realised with my Phantom 2 Vision.

    Andrea Toscano - Roma Drone Expo - Duomo di Milano - Drone Phantom 2 quadcopter

    Andrea Toscano – Roma Drone Expo – Duomo di Milano – Drone Phantom 2 quadcopter

    Metro Italia – 29/May/2015
    Metro News Italia 29 Maggio 2015 (29/05/2015)

    Metro News Italia 29 Maggio 2015 (29/05/2015)

    Here you can see all the winners for the photography and video sections:
    Metro Drone Challenge Winners

    Award ceremony available on youtube:

    Read More
  • U-Blox Neo M8N Drotek
    15th, May
    U-Blox Neo M8N U-Center configuration and Arduino parser sketch

    !! U-Blox Neo M8N configuration file and Arduino sketch available on my gitHub toskyRocker account !!

    Today I’ll explain how to configure the outstanding U-Blox Neo M8N GPS/GLONASS receiver for multirotors usage.

    Introduction to the U-Blox Neo M8N

    Why this receiver?
    Well, the answer is pretty simple: it’s one of the best receivers you can get for 50€ . It can be used with many concurrent navigation satellite systems, like GPS+GLONASS, allowing better performance.
    Not all the boards including M8N have the same performance, I suggest you to buy the board developed by DroTek since it seems to have a better accuracy. Different boards with the same M8N receiver have been tested here:  DIY Drones forum.

    First of all you need to:

    1. Download the free tool U-Center available on U-Blox Website.
    2. Install U-Blox Neo M8N driver
    3. Choose a way to connect the U-Blox to your PC. You can use either a FTDI Cable or the PL2303 USB to UART converter (this last needs its driver)

    U-Blox Neo M8N configuration with U-Center

    U-Center is a smart tool that allows you to choose the configuration you need for the GPS receiver and store it in its non volatile memory. With U-Center you can test the accuracy of the receiver with visual instruments displaying info about: satellites, DOP, output messages, baudrate, FIX mode etc..



    There’s a simple way to upload a configuration on the non-volatile memory of the receiver.

      1. Connect the receiver to your PC and open U-Center

    U-Center magic wand
    Click on the magic wand to enable the autobauding. Then the connection status should turn green.

      1. Go to: Tools-> GNSS Configuration

    U-Center GNSS Configuration
    Then browse where Configuration_Ublox_Neo_M8N.txt is stored (download it from my gitHub) and click on “File>GNSS” . Now the configuration is permanently stored on the M8N receiver.
    U-Center upload configuration

    My configuration affects:

    1. Dynamic model configured on Pedestrian (low speed and acceleration)
    2. 10Hz refresh
    3. SBAS On. Be sure your area is covered by SBAS
    4. Static Hold 0.01 m/s
    5. Baudrate fixed to 115200

    If you want to change many more parameters, go to View->Message View

    U-Center Message View
    Browse until UBX->CFG . Here you can set many parameters. Once you’ve done, click on Send (on left bottom-hand of the windows).

    U-Center CFG

    U-Center CFG

    In order to make it permanent on M8N’s flash memory, go to Receiver->Action and select “Save Config”.
    U-Center save configuration

    Arduino parser for the U-Blox Neo M8N

    Do you want to read GPS/GLONASS info on your Arduino?
    You need to parse NMEA output strings from your GPS/GLONASS receiver!
    Wire your receiver on whatever Arduino (e.g. Yun/Micro/Leonardo etc..) having the Atmega32u4. This is essential since we’re going to use Serial1, unfortunately unavailable on Arduino Uno (Atmega328).

    Arduino wiring Ublox Neo M8N

    Arduino wiring for Ublox Neo M8N

    Now compile and run my sketch on Arduino and enjoy your M8N!

    The parser takes into account 5 NMEA messages :

    • GNGGA: latitude, longitude, altitude, fix quality, HDOP, satellites in view, satellites in use
    • GNGSA: Fix Mode, PDOP, HDOP, VDOP
    • GPGSV: Satellites in view, elevation, azimuth, SNR, satellites info
    • GNRMC: Time, latitude, longitude, speed over ground, course, magnetic variation
    • GNVTG: Track made good e ground speed
    Read More
  • FuzzyDeath Robocode bot
    08th, May
    FuzzyDeath – Simple tank with fuzzy approach for FirePower (RoboCode)

    !! Code available on my GitHub toskyRocker account !!
    Bot developed by Andrea Toscano and Francesco Giorgio – Università degli Studi di Milano – Master in Computer Science (Informatica)

    The aim of the project is to implement a fuzzy driven bot, named FuzzyDeath, for Robocode.
    Given enemy’s speed and position our bot will decide the right firePower according to fuzzy rules defined in the FAM (Fuzzy Associative Matrix).

    Other features:

    1. Movement: Anti-Gravity approach keeps FuzzyDeath away from walls and gives him a pseudo-random behaviour
    2. Radar: Lock-on tracker method allows FuzzyDeath to constantly control enemy’s movements

    Further info in Italian are available on my GitHub.

    Read More