Written by SOLO Team
30/05/2022
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

 

 

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! 1

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! 2

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! 3

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! 4
2. Open Matlab and select the project folder
SOLO Simulink Block-Set Hello World Guides! 5
3. Start Simulink and create a blank model
SOLO Simulink Block-Set Hello World Guides! 6
SOLO Simulink Block-Set Hello World Guides! 7

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! 8
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! 9
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! 10
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! 11
SOLO Simulink Block-Set Hello World Guides! 12
8. Now click on the Build button. You must see a successful message at the end.
SOLO Simulink Block-Set Hello World Guides! 13

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! 14
SOLO Simulink Block-Set Hello World Guides! 15
SOLO Simulink Block-Set Hello World Guides! 16
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.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Share This

Share This

Share this post with your friends!