VESC and Simulink in windows

General topics and discussions about the VESC and its development.
yosoufe
Posts: 50
Joined: 18 Jul 2016, 11:26
Location: USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

VESC and Simulink in windows

Postby yosoufe » 17 Aug 2016, 14:12

Hi guys. I have created a simulink block to communicate with the VESC in real-time for windows.

I am sharing the block files. I am not a profi S-function writer. So I do not guarantee anything. For me it is working properly. Use it with your own responsibility.

You need to extract the file and copy VESC folder and VESClib.slx file in your current workspace of the Matlab. Right click on VESC folder -> add to path -> selected folder and subfolders. Create a new Simulink file. open the VESClib.slx. This is the library. Copy the block in your simulink model. Set the sampling rate, baudrrate and com port number. if you double click on the block, it is written there how to use it.

I have a question although. The following images show the usage of it when the VESC is programmed once with FOC and one with BLDC mode. Why the speed measurement in FOC moce is that much nice but in BLDC mode it is that much noisy? How can I make the measurement as nice as FOC?

FOC mode:
Image

BLDC mode:
Image

Open the images in a new tab and full screen for a better quality.
Attachments
library.zip
VESC communication with Simulink real time
(105.33 KiB) Downloaded 234 times

yosoufe
Posts: 50
Joined: 18 Jul 2016, 11:26
Location: USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby yosoufe » 22 Aug 2016, 09:58

Why the speed measurement in the BLDC mode is very nosiy but in FOC mode is very smooth? It is the same using BLDC-tool.

BLDC:
Image

FOC:
Image

arvidb
Posts: 234
Joined: 26 Dec 2015, 14:38
Location: Sweden, Stockholm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby arvidb » 22 Aug 2016, 20:02

Probably because the speed is measured differently in the different control modes:

In BLDC the value is based on the number of commutations per time passed (stored as rpm_now in ).

In FOC the rpm is calculated based on something called m_pll_speed, which value is calculated in pll_run() in . I have not studied the code enough to understand what this is, so cannot explain any further.

(Much functionality is duplicated between the BLDC and the FOC code, with more or less differing implementations in different cases. It's like Benjamin started with a copy of the BLDC code when he wrote FOC support, and then took the opportunity to rewrite much of the functionality, but left BLDC as-is. I'm thinking about/experimenting with possible improvements there, by extracting similar functionality to their own source files and leaving only the specifics for BLDC and FOC in mcpwm.c and mcpwm_foc.c, respectively.)

arvidb
Posts: 234
Joined: 26 Dec 2015, 14:38
Location: Sweden, Stockholm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby arvidb » 22 Aug 2016, 21:38

My idea for a long-term solution would be to break out the code for the different sensors to their own source files, and give them a common interface (the Linux kernel uses this technique in many places to write more object oriented C). Then one could add pure software-based "sensors" as well, that used a combination of physical sensors, sensorless observers, linear/quadratic/cubic extrapolation, any kind of advanced estimation really, for position and speed. Then it would also be possible to hook in a FIR filter in that chain.

Problem is, I have very little time, so this won't happen anytime soon (not from me at any rate).

yosoufe: Why is the noise a problem for you? Maybe a good solution would be to simply filter the signal in Simulink?

yosoufe
Posts: 50
Joined: 18 Jul 2016, 11:26
Location: USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby yosoufe » 31 Aug 2016, 13:03

Speed measurement on VESC:

BLDC:
The number of commutations and their time are recorded in update_rpm_tacho() in variable rpm_dep based on the TIM2. This function is called on every call of commute().

In the pwm_thread it is doing the speed calculation and makes the recorded values again zero.

FOC:
Image
http://cas.ensmp.fr/~praly/Telechargeme ... stolfi.pdf
Based on the above picture it is implemented in pll_run().

The nonlinear position observer is based on the same paper above.

arvidb
Posts: 234
Joined: 26 Dec 2015, 14:38
Location: Sweden, Stockholm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby arvidb » 31 Aug 2016, 15:26

Ah, so that's what the pll code implements! I tried to read up on phase locked loops but still couldn't really grasp in detail how the speed & position estimation worked in mcpwm_foc.c. Much easier now when I know it's from the observer paper. Thanks!

michael_wintergarden
Posts: 85
Joined: 10 Aug 2016, 16:14
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby michael_wintergarden » 23 Oct 2016, 12:21

Hi guys,

has anyone continued working on Simulink?

I wonder if somebody might have implemented the position control.

see ya

yosoufe
Posts: 50
Joined: 18 Jul 2016, 11:26
Location: USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby yosoufe » 15 Dec 2016, 09:15


michael_wintergarden
Posts: 85
Joined: 10 Aug 2016, 16:14
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby michael_wintergarden » 18 Dec 2016, 20:58


yosoufe
Posts: 50
Joined: 18 Jul 2016, 11:26
Location: USA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Re: VESC and Simulink in windows

Postby yosoufe » 19 Dec 2016, 15:54



[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1236: count(): Parameter must be an array or an object that implements Countable

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests