programming with matlab/simulink - ndsu - north · pdf filebest robotic, inc. matlab/simulink...

Post on 17-Mar-2018

246 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

BEST Robotic, Inc.MATLAB/Simulink Team Training

Programming With MATLAB/Simulink

September 20, 2014 1BISON BEST

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 2Bison BEST

Key Software Locations

August 1, 2010 3Copyright © 2010 BEST Robotics, Inc. All rights reserved.

Click on the MATLAB r2014a link

Starting MATLAB

August 1, 2010 4Copyright © 2010 BEST Robotics, Inc. All rights reserved.

Something on MATLAB

August 1, 2010 5Copyright © 2010 BEST Robotics, Inc. All rights reserved.

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

Choose Apps from the main menu

For BEST Robotics tools

August 1, 2010 6Copyright © 2010 BEST Robotics, Inc. All rights reserved.

….Best Robotics tools

September 20th, 2014 Bison BEST 7

• Choose VEX Companion

Using VEX Support

September 20th, 2014 Bison BEST 8

Mathworks VEX support is embedded in Simulink, which is accessed using the following interface

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 9Copyright © 2010 BEST Robotics, Inc. All rights reserved.

September 20th, 2014 Copyright © 2010 BEST Robotics, Inc. All rights reserved. 10

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

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 12Copyright © 2010 BEST Robotics, Inc. All rights reserved.

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 14Copyright © 2010 BEST Robotics, Inc. All rights reserved.

+ 127

+ 127

-127

-127

+ 127

+ 127

-127

-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.

Accelerometer rotate right limit + 127

Accelerometer rotate left limit - 127

Accelerometer rotate forward limit + 127

Accelerometer rotate back limit -127

Reading the Joystick Signals

Y Axis

X A

xis

September 20th, 2014 15Copyright © 2010 BEST Robotics, Inc. All rights reserved.

4 Analog Signals4 Digital Signals4 Accelerometer Signals

September 20th, 2014 16Copyright © 2010 BEST Robotics, Inc. All rights reserved.

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 19Copyright © 2010 BEST Robotics, Inc. All rights reserved.

Actuator Controls

August 1, 2010 20Copyright © 2010 BEST Robotics, Inc. All rights reserved.

August 1, 2010 21Copyright © 2010 BEST Robotics, Inc. All rights reserved.

Add motors and Servos

Other Model Functions

August 1, 2010 22Copyright © 2010 BEST Robotics, Inc. All rights reserved.

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 asNeeded, and Connect

September 20, 2014 25Copyright © 2010 BEST Robotics, Inc. All rights reserved.

Now, Set the Channels

August 1, 2010 26Copyright © 2010 BEST Robotics, Inc. All rights reserved.

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

August 1, 2010 32Copyright © 2010 BEST Robotics, Inc. All rights reserved.

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 33Copyright © 2010 BEST Robotics, Inc. All rights reserved.

Simulating the Arcade

August 1, 2010 34Copyright © 2010 BEST Robotics, Inc. All rights reserved.

• 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

Simulation Control

August 1, 2010 35Copyright © 2010 BEST Robotics, Inc. All rights reserved.

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 Choose Code-> C/C++ Code -> Build Model

August 1, 2010 36Copyright © 2010 BEST Robotics, Inc. All rights reserved.

Additional support http://www.mathworks.com/academia/student-competitions/best-robotics/

September 20th, 2014 Bison BEST 37

top related