Saturday, November 16, 2013

iRobot Create: MATLAB Control

Introduction

This is the third section of the iRobot Create tutorial. If you have not completed the first and second sections, I would recommend that you go back and do so by following the links below. They provide more insight into how the toolbox actually works. This section covers control of the iRobot Create via MATLAB. If you do not have access to MATLAB, feel free to skip this section. While it may be possible to use GNU Octave (a free Matlab compatible software), I know very little about that(Update: See my post on Octave serial communication HERE. More details on an Octave package coming soon).

Sections

Reference Documents

These documents should be referenced for details on interfacing with the Create
  • MATLAB Toolbox Documentation - This document provides details on the various functions included in the MATLAB toolbox. More information can be found in comments in the functions themselves.
  • iRobot Create Open Interface Manual (OIM)- This manual provides detailed information on the serial interface with the Create. It details the implementation of the opcode system used to control the various systems as well as the necessary measures that must be taken to receive sensor data from the Create. Information regarding sensor packet size, connector pinouts, and command details can be found here.
  • iRobot Create User Manual - This manual provides an introduction to the basic functions of the Create and an overview of the basic onboard functionality

    Necessary Hardware

    Necessary Software


    MATLAB Control

    Another convenient way to control the Create is with a MATLAB toolbox. The MATLAB toolbox to be used in this lab (Developed by Joel Esposito at the US Naval Academy) allows the user to control the Create from any computer via a serial tether. This lab will explore the basic functions of this toolbox. See comments in the scripts for details on each function. For more information, see comments in the functions themselves or read the MTIC Documentation

    Before beginning, download the MATLAB toolbox HERE and unzip it into the folder in your MATLAB directory. In windows it will be "C:\Program Files\MATLAB." Next connect to the computer the Create using either the iRobot serial cable and a serial extension or a bluetooth serial link. Open the Device Manager and make note of the COM port associated with the Create. Open MATLAB and proceed.

    ExampleButtonBeep

    This example demonstrates the use of the Create's Advance and Play buttons. When in Full or Safe Mode, these buttons may be read as digital inputs. The function ButtonSensorRoomba returns 1 for a depressed button and 0 for a button that is not depressed.
    1) Open ExampleButtonBeep.m
    2) Set serial port to COM port associated with Create. 
    Example: For a Create connected to COM 8. Change RoombaInit() to RoombaInit(8) 
    3) Click the green run icon in the center of the MATLAB toolbar.
    4) Press combinations of the Play and Advance buttons to hear different patterns of beeps

    ExampleDrive

    This example explores two of the ways the user can control the Create's wheels, SetFwdVelRadiusRoomba and SetDriveWheelsCreate. See comments in the scripts for details on each function. For more information, see comments in the functions themselves or read the MTIC Documentation.
    1) Open ExampleDrive.m
    2) Set serial port to COM port associated with Create. 
    Example: For a Create connected to COM 8. Change RoombaInit() to RoombaInit(8) 
    3) Place Create on large, flat surface (e.g. the floor).
    4) If not already done, turn Create to ON.
    5) Click the green run icon in the center of the MATLAB toolbar. 

    Observe how each function moves the Create. Note the distance measurements displayed in the MATLAB Command Window. They are the distance readings from the Create's wheel encoders. Note that the distance is taken as the average of the two wheels, so if one wheel traveled 1m and the other wheel traveled -1m. The distance is still 0. 

    Explore how different inputs effect the Create's movements and the sensor readings.

    ExampleDrive2

    This example demonstrates two of the ways to control the Create's wheels using feedback from the Create's wheel encoders, travelDist and turnAngle.
    Note: travelDist and turnAngle use scripting from the Create Open Interface. This means that these functions are blocking. The Create waits and will not accept any new commands (e.g. requests for sensor data or commands to STOP!!) until it has traveled the desired distance. For this reason, use of these functions should be limited to small distances.

    1) Open ExampleDrive2.m
    2) Set serial port to COM port associated with Create. 
    Example: For a Create connected to COM 8. Change RoombaInit() to RoombaInit(8) 
    3) Place Create on large, flat surface (e.g. the floor).
    4) If not already done, turn Create to ON.
    5) Click the green run icon in the center of the MATLAB toolbar. 
    Observe how each function moves the Create.
    Explore how different inputs effect the Create's movements.

    ExampleSensorRead

    This example demonstrates the various methods of reading the Create's sensors. For details on interpreting the sensor readings, see the Create Open Interface Manual. 
    Note that not all sensor read functions are included in this example. See the MTIC documentation for information on other individual sensor read functions. 
    1) Open ExampleSensorRead.m
    2) Set serial port to COM port associated with Create. 
    Example: For a Create connected to COM 8. Change RoombaInit() to RoombaInit(8) 
    3) If not already done, turn Create to ON.
    4) Click the green run icon in the center of the MATLAB toolbar. 
    Observe the values printed to the MATLAB Command Window from the different functions. Note the format of each reading. Using the Create Open Interface Manual and the MTIC documentation, interpret each value displayed and consider how that value might be useful. For example:
    CliffRgt = 0. What does that mean?
    Wall = 1. What does that mean?
    pCharge = 66.4563. What does that mean? 

    ExampleBasicObjectAvoidance

    This example demonstrates the implementation of basic object avoidance using the Create's bump sensors. 
    The Create drives forward until it encounters an object and turns away from it. Pressing either button (Advance or Play) while the script is running stops the Create. 
    Note: Set Serial Port to port connected to Create
    Note: ctrl + c stops execution of MATLAB code 
    1) Open ExampleBasicObjectAvoidance.m
    2) Set serial port to COM port associated with Create. 
    Example: For a Create connected to COM 8. Change RoombaInit() to RoombaInit(8) 
    3) Place Create on large, flat surface (e.g. the floor).
    4) If not already done, turn Create to ON.
    Note: To stop the Create's movements, press one of its buttons or simply lift one of its wheels off the ground. If the Create becomes disconnected from the computer, it will follow the last command it was given.
    5) Click the green run icon in the center of the MATLAB toolbar. 
    Observe the behavior of the Create. Make changes to the example sketch to improve its functionality. What do the limitations seem to be in the system?

    ExampleKeyboardControl

    This example demonstrates keyboard control of the iRobot Create. 
    Note: Exiting keyboard control by any method other than pressing 'q' (e.g. clicking the red x on the window) will likely crash MATLAB. 
    1) Open ExampleKeyboardControl.m
    2) Set serial port to COM port associated with Create. 
    Example: For a Create connected to COM 8. Change RobotHardKeyBoard() to RobotHardKeyBoard(8), and change RoombaInit() to RoombaInit(8) 
    3) Place Create on large, flat surface (e.g. the floor).
    4) If not already done, turn Create to ON.
    5) Click the green run icon in the center of the MATLAB toolbar.
    6) Use keyboard commands displayed on screen to control Create.
    7) Press 'q' to end keyboard control

    No comments:

    Post a Comment