SOLO Simulink Block-Set Hello World Guides!

Introduction

SOLO now has a block-set library that allows all of our products to be directly controlled or monitored in a powerful Simulink Mathworks environment, this can be a great feature for those in the R&D stages trying to speed up the developments or putting SOLO beside their other blocks in a sophisticated system, our Simulink block-set is capable of communicating with up to 256 SOLO units in a network at the same time.

The model-based design approach of Simulink will enable our users to do things that with conventional coding in programming languages might take months instead of a couple of days in the Simulink environment and that’s why we believe this can be a game-changer for all SOLO users, below we will discuss more on how this library is structured and how to use it.

The Block-set can be downloaded from our Git repository in below link:

https://github.com/Solo-FL/SOLO-Motor-Controllers-SIMULINK

Now our Blockset supports two different communication protocols:

UART or USB protocol: The user can directly connect SOLO to their PC using the USB port on SOLO or by using a UART to USB converter

CANopen protocol: The user can communicate with SOLO through KVASER devices on the CAN lines and runing the Simulink Model with Data transferred on the CAN bus, to use the KVASER devices please make sure all the required software libraries and SDKs published by KVASER are installed on your PC.

SOLO Simulink Block-Set Hello World Guides! 1

Necessary setups for using SOLO Simulink DLL

1. Checking MinGW Compiler

For checking if MinGW compiler is installed in your system, you should open command prompt and run the “g++ –version” command. Then, if the following message appeared, you can jump to the next step otherwise you need to install it based on the next section instructions. One more thing is that your compiler version should be sjlj.

SOLO Simulink Block-Set Hello World Guides! 2

Figure 1-1 Message when MinGW is installed

SOLO Simulink Block-Set Hello World Guides! 3

Figure 1-2 Message when MinGW is not installed

1.1. MinGW installation instructions

First you need to download it from this link. You should download the one which is highlighted in the picture.

SOLO Simulink Block-Set Hello World Guides! 4

Figure 1-3 MinGW sjlj Webpage Address

After you have downloaded the file, you need to extract it on your C drive. Afterwards, you need to add the compiler path to system files. For this purpose, open the “Control Panel” window, choose “small icon” for “View by” section like is shown below.
SOLO Simulink Block-Set Hello World Guides! 5

Figure 1-4 Control Panel

Click on the “System” icon. On of the following windows should be opened.
SOLO Simulink Block-Set Hello World Guides! 6

Figure 1-5 System Setting window

SOLO Simulink Block-Set Hello World Guides! 7

Figure 1-6 System Setting window

In the opened window click on the “Advanced system settings”. The window which is shown below should appear.
SOLO Simulink Block-Set Hello World Guides! 8

Figure 1-7 System Properties window

In the opened window click on the “Environment Variables”. Then, you should follow the steps which are shown in the figure.
SOLO Simulink Block-Set Hello World Guides! 9

Figure 1-8 Add MinGW to System Path

After this step the path should be added to user variables like the following figure.
SOLO Simulink Block-Set Hello World Guides! 10

Figure 1-9 Environment Variables window

If you followed the instructions properly, in command prompt if you now write “g++ –version” command you should now see a message like the figure1-1.

1.2. Necessary files and Installations

Now as the last step, you will need to make sure all the below required installations and instructions are met

1.2.1 KVASER windows driver intallation

Go to the Kvaser website at https://www.kvaser.com/download/ and download and install the latest version of Kvaser Driver for Windows

SOLO Simulink Block-Set Hello World Guides! 11

1.2.2 Directing the Matlab root to the Blockset folder

Next thing is to make sure is the Matlab root is properly selected to the project’s folder root

SOLO Simulink Block-Set Hello World Guides! 12

1.2.3 Checking Critical files

There are 3 necessary files which have to be in the same folder where S-functions files are, these files are:

  • SoloDLL_Sim.dll
  • SoloDLL_Sim.h
  • Canlib32.dll

All these files are necessary and if you lose them, you must download them again.

The SOLO Simulink block-set Structure

Our Simulink block-set is built on top of our C++ dll that is designed to support all the UART, USB and CANopen command sets of SOLO in a very efficient and easy-to-use manner, to learn more about these command sets please refer to our USB, UART or CANopen user manuals. Our C++ dll then is called within the S-function structure of Simulink to Call all the Write and Read functions on SOLO.

It worth mentioning that this C++ dll will also enable the SOLO users to use our command sets in Labview environment and soon we will publish some examples for that.

The SOLO’s Simulink Block-set has three main Block types which are explained in below

The Serial Setup Block

This block will set up and initialize for the first time the Serial port of SOLO in case of using USB or UART protocols of SOLO, thus this block can just be called only during the initializations or possible re-connection to SOLO and there is no need to call it afterwards.
SOLO Simulink Block-Set Hello World Guides! 13

The inputs of this block are as followings:

Address: This input defines the Device address of SOLO unit that you want to initialize, to set or change the device address of your unit you can use SOLO Motion Terminal.

COM Port: This defines what COM port is assigned to SOLO unit on your PC, on Windows devices you can check that in Device Manager.

Baud Rate: This defines at what baudrate your SOLO unit operates for UART communications, you can set the baudrate of the UART line in SOLO Motion Terminal.

If you are using the native USB on your SOLO unit, the value of baudrate you put here has no effect and any value will be acceptable as the notion of Baud-rate for the USB-2 protocol on SOLO is non existent.

If you are using SOLO with a UART to USB converter connected to your PC then setting of this Baudrate will be necessary and it’s highly recommended to use the highest baudrates possible ( 937500 bits/s in SOLO UNO and MINI) to have the highest performances.

Timeout: This defines the timeout for commands in terms of milliseconds, if the dll fails to communicate with SOLO within the timeout time, you will receive the timeout error code at the “Result” output.

Trials on Failure: This defines how many times the dll should try automatically sending a failed command to SOLO later when you try to Write or Read some parameters, in case after finishing all the trials the command fails to be sent or received you will receive an error at the “Result” and “Error” outputs in your Write or Read functions.

Result: This output defines if the setup process went successful or if an error occurred during the process.

The Write Blocks

Any Write block will attemp to set the value of a parameter within your SOLO unit, each of these blocks will provide you with some inputs and some outputs that are explained in below.

Note: once you are dealing with Write blocks, you need to make sure you don’t over-use the Write action on the parameters that are stored in the NVM memory (non-volatile memory) of SOLO, this memory can be used for Millions of Writes, however it will be wiser to use it only when necessary, to know more about the NVM memory of SOLO and what commands are stored there please refer to our USB, UART or CANopen user manuals.

SOLO Simulink Block-Set Hello World Guides! 14

Address: This input defines the Device address of SOLO unit that you want to command, in other words, as our Simulink block-set can work with multiple SOLO units at the same time, using this input you will tell to the C++ dll to communicate with what SOLO unit in the network

Value: this is the value that you possibly want to set on your SOLO unit based on the particular action you want to take, for instance for the Write block shown above, this will set the Speed Reference for your SOLO unit with the address of 0.

Result: This output will return a possible result if required after the Write action, in general this output is not used frequently in Write actions except for knowing if the process went right or some errors occurred.

Error: this output will return a possible Error that might occur during the Writing process.

The Read Blocks

The Read blocks provide you the possibility of reading any existing parameter on the command set of SOLO, the input and outputs of a generic Read block are as followings:
SOLO Simulink Block-Set Hello World Guides! 15

Address: This input defines the Device address of SOLO unit that you want to read from, in other words, as our Simulink block-set can work with multiple SOLO units at the same time, using this input you will tell to the C++ dll to communicate with what SOLO unit in the network.

Result: This output will return the request Read value, for instance on the block above, you will receive the Speed Feedback value read or estimated by SOLO.

Error: this output will return a possible Error that might occur during the Reading process.

How to Integerate the SOLO’s C++ dll in Simulink environment

This part of the tutorial is only for those who want to delve deep in how actually our C++ dll works with Simulink and in case if they want to change or develop on top of it.

The steps

1. You need to create a new folder and put SOLO’s c++ library for Simulink .dll and .h files in that folder.
SOLO Simulink Block-Set Hello World Guides! 16
2. Open Matlab and select the project folder
SOLO Simulink Block-Set Hello World Guides! 17
3. Start Simulink and create a blank model
SOLO Simulink Block-Set Hello World Guides! 18
SOLO Simulink Block-Set Hello World Guides! 19

4. Open the library browser, in the search bar and search for “S-Function” and then add “S-Function Builder” to your Simulink

SOLO Simulink Block-Set Hello World Guides! 20
5. Now you can add more “S-Function Builder” blocks to your Simulink for any special Read or Write actions, in practice each individual command on SOLO can have its own S-Function block.
SOLO Simulink Block-Set Hello World Guides! 21
6. double click on the first S-Function builder block to change its configurations, We use the first block to map on “serialsetup” function of dll, If we look at this function inputs with the .h file we find out how many inputs and outputs it has, for the serialSetup function, for instance, we see the following
SOLO Simulink Block-Set Hello World Guides! 22
7. set a name for your block and add all of its inputs and output ports like below.
SOLO Simulink Block-Set Hello World Guides! 23
SOLO Simulink Block-Set Hello World Guides! 24
8. Now click on the Build button. You must see a successful message at the end.
SOLO Simulink Block-Set Hello World Guides! 25

9. close the window
10. You can make any Write or Read block with the same way as the images below:

SOLO Simulink Block-Set Hello World Guides! 26
SOLO Simulink Block-Set Hello World Guides! 27
SOLO Simulink Block-Set Hello World Guides! 28
Following these steps, you should be able to add any arbitrary function inside of the dll and expand it to the Simulink environment as you wish.
Share This

Share This

Share this post with your friends!