Data acquisition and device control with Scilab.

Dependencies:   Servo MPU6050

Desciription

Scilab is a freeware alternative to MATLAB. For low-cost data acquisition and device control a nice Arduino toolbox is available.

https://os.mbed.com/media/uploads/hudakz/scilab.png

This site presents a Mbed port which allows to use Mbed boards (equipped with Arduino header) rather than Arduino to import real time data into Scilab and to control real equipment witch Scilab.

https://os.mbed.com/media/uploads/hudakz/arduino-temp-read_imagelarge_1.jpeg

Installation
  • Install Scilab to your PC, if not done yet.
  • Launch Scilab and install the Arduino toolbox by executing the following command from the Scilab console:

--> atomsInstall("arduino")
Controlling Mbed's digital output from Scilab
  • In Xcos open examples/Arduino1.zcos

/media/uploads/hudakz/scilab_arduino1.png

  • Double click on the Board setup block and replace the serial port number with mbed's actual virtual serial port number.
  • Double click on the Digital WRITE block and set Digital Pin to 13 (D13 is connected to LED1).
  • Start simulation and LED1 on the Mbed board should start blinking.
Reading and displaying Mbed's analog input
  • In Xcos open examples/Arduino2.zcos

/media/uploads/hudakz/scilab_arduino2.png

  • Double click on the Board setup block and replace the serial port number with mbed's actual virtual serial port number.
  • Double click on the Analog READ block and set Analog Pin to 2.
  • Start simulation and a graph should appear showing the analog signal measured on Mbed's pin A2.

NOTE: Currently, there is bug in the toolbox ARDUINO_ANALOG_READ_sim function (I have reported to Scilab) so the analog readings are not correct.

/media/uploads/hudakz/scilab_graph.png

PID controller
  • In Xcos open examples/Arduino9.zcos

/media/uploads/hudakz/scilab_arduino9.png

ScilabSerial/DcMotor.cpp

Committer:
hudakz
Date:
2021-01-18
Revision:
0:295b7e1c12f3

File content as of revision 0:295b7e1c12f3:

#include "DcMotor.h"

/**
 * @brief   The DcMotor class
 * @note    Driven by L293 or L298
 */
DcMotor::DcMotor(PinName pin1, PinName pin2, int driverType) :
    _driverType(driverType)
{
    _pwmOut1 = new PwmOut(pin1);
    _pwmOut1->write(0);
    switch (_driverType) {
        case 0: //L293
            _pwmOut2 = new PwmOut(pin2);
            _pwmOut2->write(0);
            break;

        case 1: //L297
            _digitalOut2 = new DigitalOut(pin2);
            _digitalOut2->write(0);
            break;
    }
}

/**
 * @brief
 * @note
 * @param
 * @retval
 */
DcMotor::~DcMotor()
{
    delete _pwmOut1;
    delete _pwmOut2;
}

/**
 * @brief
 * @note
 * @param
 * @retval
 */
void DcMotor::run(int direction, float speed)
{
    switch (_driverType) {
        case 0: //L293
            if (direction == 0) {
                _pwmOut1->write(0);
                _pwmOut2->write(speed);
            }
            else {
                _pwmOut1->write(speed);
                _pwmOut2->write(0);
            }
            break;

        case 1: //L297
            if (direction == 0)
                _digitalOut2->write(0);
            else
                _digitalOut2->write(1);

            _pwmOut1->write(speed);
            break;
    }
}