Lego Mindstorms Minimalist Matlab Library for mobile robot simulation

LM3LT is a minimalist class written entirely in Matlab that simulates, with certain degree of physical realism, a Lego Mindstorms robot with its basic sensors and actuators:

  • Two independent motors (left and right) with simulated first-order rotation speeds.
  • Ultrasonic sensor with longitudinal noise of similar magnitude to the real one and also with the possibility of adding angular noise and beam thickness.
  • Reflected light sensor with measurement noise and with modifiable area of measurement. Picture files (e.g., png) can be used as light map on the floor.
  • Gyro sensor that mimics the behaviour (angle + velocity) of the EV3 gyro sensor.
  • Collision detection with obstacles (walls).
  • Physical parameters of the configuration (position of the sensors, radii of the wheels, etc.) can be defined at will.

This class is intended to provide an alternative to the use of the real robot in engineering contexts, for instance in university courses. It has been used intensively in a Robotics undergraduate course starting from the academic year 2019/2020 and in a Mobile Robotics master course starting in the academic year 2020/2021 (both due to the COVID-19 pandemic).

Its documentation is quite self-explanatory. A script skeleton is included in the downloadable.

You can download the latest version of the library here.

C library for using a SRAM Microchip 23LC512-I/SN connected to an ATmega328P

The SRAM Microchip 23LC512-I/SN is a very nice chip that can serve as external RAM (64KB) for the ATmega328P.  This simple C library deals with block writings and readings to that chip from the MCU, in a most efficient way (it can use assembler code internally, and some hard real-time techniques for reducing the execution time, if the user wishes to).

It has been tested with the scripts for bare programming the ATmega328P of an Arduino UNO, i.e., with the compiler that comes with the Arduino IDE.

Features:

  • It uses the SPI module of the ATmega328P, and therefore its associated MISO/MOSI/SCK pins, for communications.
  • It always uses pin 2 of PORTB as output because otherwise the SPI module of the ATmega328P does not work properly. Nevertheless, the chip select for the SRAM can be B2 or D3.
  • Including the call to the writing routine and without interrupts enabled, the transfer speed is around 5 microsecs per byte of the transmitted block (200KHz).
  • Including the call to the reading routine and without interrupts enabled, the transfer speed is around 5.3 microsecs per byte of the transmitted block (190KHz).

Installation and usage:

  • Download the library.
  • Just read the .h.

C library for RS232 communications in the ATmega328P

This library allows the programmer to use the RS-232 communications of the ATmega328P (for instance, the one of the Arduino Duemilanove or UNO boards) directly.

Features:

  • It works correctly only with ATmega328P @ 16MHz.
  • The user can set the bauds (up to 2Mbauds), but the library forces asynchronous, no parity, 1 stop bit, 8 data bits.
  • It uses ISR-guided processing for receptions and no ISRs for transmissions, particularly USART_RX_vect, that has higher priority than ADC_vect and lower than  external interrupts or  timers. The ISR will delay the latter when executing -the non-interruptible code in this library has been kept to a minimum, though-.
  • Transmissions from the ATmega to the outside consist of commands of unlimited length ended in a given particular character.
  • Receptions consist of commands of a given maximum length, also ended in a given ending character.
  • Both transmissions and receptions are full-duplex. Receptions can be  configured to receive and drop characters while using only transmissions (for instance, for tracing programs).

Installation and usage:

  1. Download the library sources.
  2. Include the .h in your program. In the sources there is an example demo of program. Compile your program, the .c file of the library, and link all of them together.
  3. In your program, first call RS232_Init; then enable interrupts and use RS232_Read and RS232_Send at will; finalize your use of the rs232 system with RS232_Finish (it can be re-activated with a new RS232_Init).
  4. In Windows and Linux you can use putty, for example, in order to connect to the arduino and test this library.

Matlab Toolbox for Control and Simulation of Scorbot ER-V Robots

scorbotp2_fondo_chica The Scorbot ER-V robotic manipulator arms, sold by Intellitek in the early 90s, are still -in their new models and in the oldies, if they still survive- a nice educational tool for Robotics subjects, lying in an intermediate level between real industrial manipulators and low-cost devices.

In this page you can find a Matlab© toolbox (entirely written in Matlab©) that includes a kinematic simulation of these kind of robots and a connection, through RS232 serial port, to a real robot of the old versions. This has served us for recovering and still using these robust machines in a modern environment, even after so many years. It has been reported previously in this paper.

The toolbox is still in a beta version, but it has several nice features already:

  • Faithful kinematic simulation (only poses, not speeds) of the ER-V robotic arm, that includes both direct and inverse kinematic models.
  • Graphical window that shows a wireframe simple 3D model of the robot in simulation mode, with some visual aids such as spatial references.
  • Serial connection to a real ER-V controller to command the robot from Matlab©, that only consumes a position variable in the RAM of the controller (all the other stuff -positions, program logic, etc.- is managed in Matlab©).
  • Easy programming in Matlab© of the robot (both real and simulated) through a basic set of commands and a very simple object-oriented interface.
  • Possibility of controlling both the simulation and the real robot simultaneously, with a single object.

snapshot

Installation and usage:

  1. Download the sources of the library (zip).
  2. Decompress the ScorbotERVlibForMatlab.zip file into any accessable MatLab© folder.
  3. Run demo to see a basic demo.
  4. Type help Scorbot to see detailed help of the Scorbot object, its methods and usage.

Here you can see a video of the basic demo that comes with the toolbox:

Scripts for using Arduino as a bare microcontroller

Arduino_Uno_-_R3In engineering courses that deal with microcontrollers it comes handy to program the one in the Arduino board -e.g., the ATmega328P– directly (without the Arduino IDE), taking advantage of the bootloader that comes pre-installed in that CPU to upload the programs to the board through the USB port -without a programmer device-, but also writing code that is not polluted with Arduino libraries, interrupts that are stolen for internal affairs, or setup/loop artificial functions.

The following files provide that functionality. They work both in Linux and Windows, and have been tested in Arduino Duemilanove, UNO and Leonardo boards. They require the arduino IDE to be installed in your computer, which is only used (seamlessly) for compiling and uploading.

Installation and usage:

  1. Download an Arduino IDE. For example, the 1.0.5 version for Windows.
  2. Download either the Windows or the Linux-bash versions of the compiling/linking scripts.
  3. Modify the first section of the scripts (it is properly indicated in them) according to the path of the Arduino IDE in your computer. You can also add the S option for compiling in order to produce assembler code, and change the optimization options too.
  4. Download either the Windows or the Linux-bash versions of the uploading scripts.
  5. Modify the first section of the scripts according to the serial port and board of your Arduino device.
  6. Create a folder for your sources and a folder for the building (intermediate files).
  7. Write your code in the sources directory. For instance:
    /* ------------------------------------
    A test program: make the LED blink. 
    Juan-Antonio Fernández-Madrigal, 2014 
    --------------------------------------*/
    
    #include <avr/io.h>
    #include <avr/interrupt.h>
    
    int main(void)
    {
    	unsigned f;
    	unsigned char c;
    
    	c=0;
    	DDRB=(1<<5);
    	while (1)
    	{
    		if (c==0) 
    		{
    			PORTB &= ~(1 << 5);
    			c=1;
    		}
    		else 
    		{
    			PORTB |= (1 << 5);
    			c=0;
    		}
    		for (f=0; f<40000; f++);
    	}
    }
    
  8. Call the compiling/linking scripts using as arguments the file(s) to compile/link.
  9. Fix any error until no one is raised.
  10. Call the uploading script.

MatLab Toolbox for the PCI1202 Data Acquisition Board

PCI-1202HUThis library provides Matlab© with access to the high-level functionality of the PCI1202 acquisition board by ICP-DAS. It has been reported previously in this paper.

Currently, the following functions are available:

  • PCI1202_InitDriverAndBoard – initiates the driver and the  first board encountered.
  • PCI1202_CloseDriverAndBoard – finishes accesses to the board PCI1202_ErrorText – gets the description of an error code of  the driver.
  • PCI1202_Delay – performs hardware short delays.
  • PCI1202_SendDA – sends digital data through the digital/analogic  channels.
  • PCI1202_ReadAD – reads digital data from the analogic/digital channels.
  • PCI1202_SendAndRead – simoultaneously sends and reads data to/from analogic channels.
  • PCI1202_PID – implements a PID controller.

For more information on any function, type help <function name>.

Installation and usage:

  1. Download the sources of the library (zip).
  2. Decompress the PCI1202MatLab.zip file into any accessable MatLab folder.
  3. Run mex -setup and then the script dll_compile.
  4. Use help PCI1202 to get further info.

The BABEL Development System

babelpiramidThe BABEL Development System is a software development framework intended for creating complex applications with the focus in coping with heterogeneity (typically, very different program code produced by different people to manage diverse software and hardware devices). It was born in the robotics domain, where heterogeneity is of the uttermost importance, particularly in today’s large scale and long-term projects.

It is neutral with respect to the programming language and underlying operating system, and covers several aspects of the robotic software lifecycle, such as the design, validation, debugging, implementation, testing, and manteinance phases.

This framework is being developed since 1996.