Presentation is loading. Please wait.

Presentation is loading. Please wait.

BEST Robotic, Inc. MATLAB/Simulink Team Training

Similar presentations


Presentation on theme: "BEST Robotic, Inc. MATLAB/Simulink Team Training"— Presentation transcript:

1 BEST Robotic, Inc. MATLAB/Simulink Team Training
Programming With MATLAB/Simulink September 10, 2016 BISON BEST

2 What You’ll Need… Minimum System Requirements Software required
Microsoft Windows 7 or Later 32-bit or 64-bit machine Administrator Access on the PC Internet connection Software required MATLAB R2016a free version available at Go to mathworks.com Search “Best Robotics” On the search List, choose “BEST Robotics” Click “Request Software” If you are not registered at Mathworks, you will be asked to create an account You will get an approval by in minutes. Installation instructions will be provided in the approval Associate to your license to your registered account Download and install MATLAB from the link provided (about 40 minutes) Activate the MATLAB September 10th, 2016 Bison BEST 2

3 Key Software Locations
September 10th, 2016 Bison BEST 3

4 Starting MATLAB Click on the MATLAB r2015b link September 10, 2016
Bison BEST

5 What You’ll Need… After installing MATLAB, choose Apps
-> Get More Apps September 10, 2016 Bison BEST

6 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

7 After the VEX block opens, choose Get Support Package
Choose Apps, then VEX Companion After the VEX block opens, choose Get Support Package (Must be connected to the internet) September 10, 2016 Bison BEST

8 At the end of installation, it helps to restart MATLAB
MathWorks Website opens, Click Get Support Package and follow instructions for installation. At the end of installation, it helps to restart MATLAB September 10, 2016 BISON BEST

9 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 Familiarize yourself with the three tabs: HOME, PLOTS, APPS September 10, 2016 Bison BEST

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

11 For BEST Robotics tools
Choose Apps from the main menu September 10, 2016 Bison BEST

12 ….Best Robotics tools Choose VEX Companion September 10th, 2016
Bison BEST

13 Using VEX Support Mathworks VEX support is embedded in Simulink, which is accessed using the following interface September 10, 2016 Bison BEST

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

15 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 19, 2015 Bison BEST

16 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 next 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 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

17 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 10, 2016 Bison BEST

18 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
The BEST Robot Model September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

19 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
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. 12 Digital signals (button) on 4 channels 4 Analog signals on four channels (two joysticks) 2 Accelerometer signals (roll and pitch) + 127 - 127 Accelerometer rotate forward limit + 127 Accelerometer rotate back limit - 127 X Axis Y Axis Accelerometer rotate right limit + 127 September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

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

21 Start building your robot controller
Click and drag one Game pad button and one Game pad joystick from the VEX Library into your untitled model. September 10, 2016 Bison BEST

22 …robot controller building
Make four copies of gamepad joystick and four copies of gamepad buttons September 10, 2016 Bison BEST

23 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
Actuating Motors and Servos September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

24 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
Actuator Controls September 19, 2015 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

25 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
Add motors and Servos September 19, 2015 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

26 Convenience Libraries
September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

27 Contents of the Utilities module
September 10, 2016 Bison BEST

28 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 10, 2016 Bison BEST

29 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
… Finish the connection September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

30 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
Set the joystick channels Double click on each joystick and set its channel: Valid channels are from 1 to 4 September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

31 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
Set the digital button channels Double click on each digital button and set its channel and the button: Valid channels are from 5 to 8, valid buttons are UP and DOWN September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

32 Set channel for Digital Input Limit Switches
Double click on each digital limit switch and set its channel: Valid channels are from 1 to 12 September 10, 2016 Bison BEST

33 Set motor and servo channels
Double click on each motor and each servo and setting their channels: Valid channels are from 1 to 10 Leave gear ratio at 1/13.5 September 10, 2016 Bison BEST

34 Working with Digital Buttons
Motors and servos require inputs of from -127 to +127 to run in either direction at full speed, full range. Analog joysticks spits numbers from -127 to +127, so can drive motors and servos as required. At this time joysticks are ready to run Digital buttons spits only two numbers, 0 and 1, therefore it cannot drive motors and servos. If the output is multiplied by 127, then it can drive the motor full speed on one direction or open servo full range one direction. The direction can be reversed by multiplying by output by -127. No way to drive the motor or servo in both directions September 10, 2016 Bison BEST

35 Multiplication by 127 The Math Library has a Gain icon
You can place the gain between the digital button and the servo Double click on it and set the gain to 127 September 10, 2016 Bison BEST

36 Minimize the Vex Library, click MATLAB’s Home Tab and Open the Simulink Library
September 10, 2016 Bison BEST

37 Conditioning the digital command
Open Ports & Subsystems Library, and click and drag “Subsystems” into your model. September 10, 2016 Bison BEST

38 Conditioning the digital signal
Double click on that subsystem box Click on the line that joins In1 and Out1, and delete it September 10, 2016 Bison BEST

39 Conditioning the digital signal
Make a copy of In1 so you have two inputs In Simulink Library again choose the Stateflow Library, click and drag the Chart into your subsystem September 10, 2016 Bison BEST

40 Conditioning the digital signal
Double click on the Chart to pen the chart editor September 10, 2016 Bison BEST

41 Click and drag three states; label the first as UP_KEY, the second as NO_KEY and the third as DOWN_KEY Put the mouse pointer at the left edge of the NO-KEY icon, press the left Key (of the mouse), and move the mouse pointer( while the key is still pressed) towards the UP-KEY icon. This draws an arrow from the NO_KEY state to the UP_KEY state. September 10, 2016 Bison BEST

42 [UP==1&&OUT<127]{OUT=OUT+127;}
Put the mouse pointer at the left edge of the NO-KEY icon, press the left Key (of the mouse), and move the mouse pointer( while the key is still pressed) towards the UP-KEY icon. This draws an arrow from the NO_KEY state to the UP_KEY state. Point and click at the leftmost part of the arrow to move the question mark there. Fill the question mark with the following command: [UP==1&&OUT<127]{OUT=OUT+127;} September 10, 2016 Bison BEST

43 [DOWN==1&&OUT>-127]{OUT=OUT-127;}
Repeat the process using the following equations From UP_KEY to NO_KEY [UP==0] From NO_KEY to DOWN_KEY [DOWN==1&&OUT>-127]{OUT=OUT-127;} From DOWN_KEY to NO_KEY [DOWN==0] September 10, 2016

44 Now add the default setting with {OUT=0;}
September 20th, 2014 Bison BEST

45 Choose Tools -> Model Explorer
Choose chart Filter: States/Functions… Transitions… Data … September 10, 2016 Bison BEST

46 Add Data September 10, 2016 Bison BEST

47 Assign created data to functions Change View to Stateflow,
For the first data change scope to Output and Name to OUT (case sensitive). Click Apply September 10, 2016 Bison BEST

48 For the second and third elements, change Scope to Input; Name them UP and DOWN
September 10, 2016 Bison BEST

49 Drag the Gain icon and make as many copies as the digital joysticks that you have
September 10, 2016 Bison BEST

50 Close the Model explorer, (File->Close)
Rename the nodes as follows (case sensitive): In1 becomes UP In2 becomes DOWN Out1 becomes OUT September 20th, 2014 Bison BEST

51 Complete the connections
Click the Back Arrow September 10, 2016 Bison BEST

52 Finish Two buttons will now control one servor in both directions, so we remove one servo or we add another button September 10, 2016 Bison BEST

53 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
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 September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

54 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

55 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
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 September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

56 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
Simulation Control August 1, 2010 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

57 Copyright © 2010 BEST Robotics, Inc. All rights reserved.
After Simulation Remove all simulation signals and Simulation inputs on all joysticks and digital buttons and inputs. Double click and uncheck “Add Input Port for Simulation” Do the same to remove simulation outputs from motors and servos Save your model file September 10, 2016 Copyright © 2010 BEST Robotics, Inc. All rights reserved.

58 Upload program into VEX controller and run
Deploy to Hardware September 10th, 2016 Bison BEST

59 Additional support September 10th, 2016 Bison BEST


Download ppt "BEST Robotic, Inc. MATLAB/Simulink Team Training"

Similar presentations


Ads by Google