This approach uses Python with the module
The advantage of Python for this project is that the Python model
You have to install the module
Necessary packages: Simulink Steps to activate Python :
-
make sure that Python 3.8 is installed (MATLAB doesn't support any more recent version).
-
find where the Python library is located. The path should be : /usr/lib/x86_64-linux-gnu/libpython3.8.so. Import the folder in MATLAB path.
-
run following command in MATLAB command shell : pyenv('Version', "/usr/bin/python3.8")
You have to change the Scopes to the expected behaviour of your motor (Change y-access scaling).
We decided to use buttons in Simulink to set the axis stat. For this, it
is only necessary to
![Set states in Simulink with buttons](Figure/Set States.png)
At all times you can use this information (category: output-name <unity>):
-
Axis State: current_state <String>
-
Position: pos <turn> (0
$\widehat{=}$ 0°; 0.25$\widehat{=}$ 90°; 1$\widehat{=}$ 360°$\widehat{=}$ 0° and one revolutions$\neq$ 0) -
Velocity: vel <turn/s>
-
Torque: torque <torque in Nm>
![Example Output for Position and Velocity](Figure/Ausgabe Pos + Vel.png)
For controlling the motor, there are several ways. In this project 3 of them are implemented (category (File): input-name <unity>):
-
Position (
$poscontroll.slx$ ): i_pos <turn> (0$\widehat{=}$ 0°; 0.25$\widehat{=}$ 90°; 1$\widehat{=}$ 360°$\widehat{=}$ 0° and one revolutions$\neq$ 0) -
Torque (
$torquecontroll.slx$ ): torque <Nm>
For each of them, there is an example module.
There is an additional button 'Set new Starting Point' to set the
current position as starting Point (pos
-
Add method to Python script (
$controller.py$ ) -
restart Matlab
-
test in Matlab with py.controller.FUNCTION_NAME(VARIABLE)
-
For Callback Button: create a button and copy the code from
$3.$ -
For MATLAB Function: Create Function and include the method call and coder.extrinsic ('py.controller.FUNCTION_NAME')