BEST Robotic, Inc.
MATLAB/Simulink Team Training
Programming With MATLAB/Simulink
September 20, 2014
BISON BEST
1
What You’ll Need…
 Minimum System Requirements




Microsoft Windows XP or Later
32-bit or 64-bit machine
Administrator Access on the PC
Internet connection
 Software required



MATLAB R2014a free version available at
http://www.mathworks.com/academia/student-competitions/best-robotics/
Registration and application required; approval expected in three days !
Installation instructions will be provided in the approval email
 Associate to your license to your registered account
 Download and install MATLAB from the link provided (about 40 minutes)
 Activate the software
 Install the VEX Support Package and Companion App (about 15 minutes)
September 20th, 2014
Bison BEST
2
Key Software Locations
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
3
Starting MATLAB
 Click on the MATLAB r2014a link
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
4
Something on MATLAB
 MATLAB Window Opens: MATLAB means Matrix
Laboratory. It is textural programming environment.
 It can execute commands directly as typed in the command
window or run a script code from a saved file
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
5
For BEST Robotics tools
 Choose Apps from the main menu
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
6
….Best Robotics tools
• Choose VEX Companion
September 20th, 2014
Bison BEST
7
Using VEX Support
 Mathworks VEX support is embedded in Simulink,
which is accessed using the following interface

September 20th, 2014
Bison BEST
8
MATLAB Simulink
 Simulink is MATLAB’s graphical programming
interface.
 Programming is accomplished by connecting various graphical
icons in a specific order.
 Simulink graphical icons are collected in what are known as
Libraries.
 Simulink programs are known as Models
 The Simulink Library collection is opened by
clicking the Simulink library icon
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
9
Simulink VEX Library
•
•
To open Simulink VEX Library,
Click Open Library
NOTE: The Library window may be
hidden far to the right of your screen
September 20th, 2014
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
10
Before Creating your Program
 You must know what you want to achieve
 The connection layout of motors and servos
to the Cortex controller.
 The assignment of Joystick keys and their
intended control functions.
 How the joysticks will control the motors and
servos
 Any other interaction between the Cortex
controller and the hardware such as sensors
September 20th, 2014
Bison BEST
11
The Typical BEST Robot Model
 The robot can be driven either in Tank or in Arcade
mode.
 The joystick has four analog channels and four digital
channels
 The controller can drive
 Up to 10 motors and servos in analog mode
 Up to 4 servos in digital mode
 Can read up to 8 analog sensors (such as potentiometers)
 Can read up to 8 digital sensors (such as limit switches)
 Simulink library has an icon for each of the possible functions: to
read the joystick, to drive motors and servos, and to read
sensors.

Our example robot will run in arcade driven by two motors; there will be
two actuator motors, one with a limit switch and four servos

Analog joysticks to motors and digital sticks to servos
September 20th, 2014
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
12
Creating a Simulink Robot
Program
 Open a robot model window by clicking the “Create
new model” button on the VEX Support Package
Companion menu
September 20th, 2014
Bison BEST
13
The BEST Robot Model
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
14
Reading the Joystick Signals
Accelerometer
rotate left limit - 127
The joystick and accelerometer limit return
values are +127 and -127 as shown in the
figure. The buttons have a return value of 0
when pressed and 1 when released.
4 Analog Signals
4 Digital Signals
4 Accelerometer Signals
+
127
127
+
127
127
127
+
127
Accelerometer
rotate forward limit +
127
127
X Axis
Accelerometer
rotate back limit 127
+
127
Y Axis
Accelerometer
rotate right limit +
127
September 20th, 2014
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
15
September 20th, 2014
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
16
Start building your robot
 Click and drag one Game pad button and one one
game pad joystick.
September 20th, 2014
Bison BEST
17
…robot building
 Make four copies of gamepad joystick and four
copies of gamepad buttons
September 20th, 2014
Bison BEST
18
Actuating Motors and Servos
September 20th, 2014
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
19
Actuator Controls
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
20
Add motors and Servos
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
21
Other Model Functions
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
22
Contents of the Utilities module
September 20th, 2014
Bison BEST
23
Motors
 Drag the Arcade module into your model. Connect two motors
and two analog joysticks as
 Drag the two digital inputs (to serve as limit switches) and one
Limit switch control block in the model. Connect the motor, limit
switch and joystick
September 20th, 2014
Bison BEST
24
Bring as Many Functions as
Needed, and Connect
September 20, 2014
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
25
Now, Set the Channels
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
26
Channles for the Digital
Input Limit Switches
September 20th, 2014
Bison BEST
27
Working with Digital
Joysticks
 Analog joysticks spits numbers from -127 to +127, i.e.
while digital joysticks spits only two numbers, 0 and
1.
 Therefore, digital joystick commands are ON and
OFF only, there are no intermediate values. You can
have slow and high speeds or stop the servo in
between fully open and fully closed.
 When a digital joystick is connected to the servo, we
need to translate its value of 1 as 127using a
multiplier
 Open the Mathematical tools library, and get a GAIN
September 20th, 2014
Bison BEST
28
 Drag the Gain icon and make as many copies as the
digital joysticks that you have
September 20th, 2014
Bison BEST
29
Set the multiplier
 Double click the gain to open its properties window
 Set a Gain or multiplier of 127 for all digital joysticks
that drive servos (or motors)
September 20th, 2014
Bison BEST
30
The final model
September 20th, 2014
Bison BEST
31
After Building the Model
 Save the simulink model file
 You may want to Simulate the model before
downloading into your Vex Controller.
 Open the utilities block again (if it is closed)
 Pay attention to the Simulation Input, and the
Simulation Output collections
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
32
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
33
Simulating the Arcade
•
Pull a variable input, a the field simulator
and a toggle. Make as mane copies as necessary
•
•
•
Connect the variable inputs to the inputs of the joysticks
Connect the toggles to the inputs of the joysticks
Connect the field simulator to the two drive motors
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
34
Simulation Control
August 1, 2010
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
35
After Simulation
 Remove all simulation signals
 Save your model file
 Compile the model to generate C-codes and
upload into Cortex microcontroller. Make sure
Cortex is connected

August 1, 2010
Choose Code-> C/C++ Code -> Build Model
Copyright © 2010 BEST Robotics, Inc. All rights reserved.
36

Additional support
http://www.mathworks.com/academia/student-competitions/best-robotics/
September 20th, 2014
Bison BEST
37