Microstepping capable stepper motor
Quote from LWT98709 on December 12, 2024, 7:46 pmThe stepper motor in the standard library is not capable of microstepping. The motor cannot stop between 2 poles.
It is not possible to send PWM signals to pins A+, A-, B+, B-, the motor will have erratic movements.The attached model proposes to recreate a stepper motor capable of microstepping.
For the moment, the motor only works in unipolar mode.The input signals A+, A-, B+, B- are filtered to obtain DC voltages (they therefore accept PWM signals). Depending on the values of the input signals, the rotor movement is simulated using the fundamental relationship of dynamics, although the magnetic forces are very roughly approximated.
This is a scripted component. The operation is in the AngelScript file "mstepper.as". Mathematical functions (sin(), cos(), sqrt(), ...) had to be recreated since they are not available. And graphical functions (drawLine(), drawArc()) were recreated as well, since the only function available for drawing in scripts at the moment is setPixel().
The stepper motor in the standard library is not capable of microstepping. The motor cannot stop between 2 poles.
It is not possible to send PWM signals to pins A+, A-, B+, B-, the motor will have erratic movements.
The attached model proposes to recreate a stepper motor capable of microstepping.
For the moment, the motor only works in unipolar mode.
The input signals A+, A-, B+, B- are filtered to obtain DC voltages (they therefore accept PWM signals). Depending on the values of the input signals, the rotor movement is simulated using the fundamental relationship of dynamics, although the magnetic forces are very roughly approximated.
This is a scripted component. The operation is in the AngelScript file "mstepper.as". Mathematical functions (sin(), cos(), sqrt(), ...) had to be recreated since they are not available. And graphical functions (drawLine(), drawArc()) were recreated as well, since the only function available for drawing in scripts at the moment is setPixel().
Uploaded files:Quote from arcachofo on December 12, 2024, 9:17 pmThank you for sharing, interesting project.
I think that some functions could be moved to libraries to be reusable.
Script libraries can be added to a folder "scriptlib" in user data folder and you can include in any script like this:
#include <libname.h>Some aclarations:
As far as I can remember stepper motor can do half step but not PWM.
Maybe part of your code could be used to create a more accurate model in addition to use inductors instead of resistors.
So we could have 2 models to choose: simple & fast and accurate & slow.Display has a drawLine function:
void drawLine( uint x0, uint y0, uint x1, uint y1, int color )
Thank you for sharing, interesting project.
I think that some functions could be moved to libraries to be reusable.
Script libraries can be added to a folder "scriptlib" in user data folder and you can include in any script like this:
#include <libname.h>
Some aclarations:
As far as I can remember stepper motor can do half step but not PWM.
Maybe part of your code could be used to create a more accurate model in addition to use inductors instead of resistors.
So we could have 2 models to choose: simple & fast and accurate & slow.
Display has a drawLine function:
void drawLine( uint x0, uint y0, uint x1, uint y1, int color )
Quote from LWT98709 on December 12, 2024, 11:43 pmIn fact, I've search around the source and found already the drawLine() fonction available. However, when I test it, there seems to have a bug and can only draw 45° diagonal lines ...
In fact, I've search around the source and found already the drawLine() fonction available. However, when I test it, there seems to have a bug and can only draw 45° diagonal lines ...
Quote from arcachofo on December 13, 2024, 11:56 amQuote from LWT98709 on December 12, 2024, 11:43 pmIn fact, I've search around the source and found already the drawLine() fonction available. However, when I test it, there seems to have a bug and can only draw 45° diagonal lines ...
Thanks, it's fixed now.
I used your algorithm which seems to be working ok.
Quote from LWT98709 on December 12, 2024, 11:43 pmIn fact, I've search around the source and found already the drawLine() fonction available. However, when I test it, there seems to have a bug and can only draw 45° diagonal lines ...
Thanks, it's fixed now.
I used your algorithm which seems to be working ok.
Quote from LWT98709 on December 14, 2024, 1:42 amQuote from arcachofo on December 12, 2024, 9:17 pmI think that some functions could be moved to libraries to be reusable.
Script libraries can be added to a folder "scriptlib" in user data folder and you can include in any script like this:
#include <libname.h>I tried what you said. I placed the *.h files in the user directory, that is, in Windows "c:/users/<username>/scriptlib". It works.
However, is it possible to place the *.h files in the "data" directory next to the .sim1 file?
The .as script file is located at "data/<component>/component.as".I tried:
- "data/scriptlib/*.h"
- "data/component/scriptlib/*.h"
- or the *.h files directly next to component.as
None of these work. SimulIDE does not find the *.h file when loading the .sim1 file.It is important to be able to place the *.h files with the custom components with the .sim1 file. This makes the file portable. No files or libraries to install. In a school environment, this is important. The machines are usually very "restricted", under Windows and integrated into a domain with policies. The library installation requires preparation that could be heavy if the teacher does not have administrator access, because it is reserved only for IT technicians, who may not be available.
Quote from arcachofo on December 12, 2024, 9:17 pmI think that some functions could be moved to libraries to be reusable.
Script libraries can be added to a folder "scriptlib" in user data folder and you can include in any script like this:
#include <libname.h>
I tried what you said. I placed the *.h files in the user directory, that is, in Windows "c:/users/<username>/scriptlib". It works.
However, is it possible to place the *.h files in the "data" directory next to the .sim1 file?
The .as script file is located at "data/<component>/component.as".
I tried:
- "data/scriptlib/*.h"
- "data/component/scriptlib/*.h"
- or the *.h files directly next to component.as
None of these work. SimulIDE does not find the *.h file when loading the .sim1 file.
It is important to be able to place the *.h files with the custom components with the .sim1 file. This makes the file portable. No files or libraries to install. In a school environment, this is important. The machines are usually very "restricted", under Windows and integrated into a domain with policies. The library installation requires preparation that could be heavy if the teacher does not have administrator access, because it is reserved only for IT technicians, who may not be available.
Quote from arcachofo on December 14, 2024, 9:49 amYou can use relative path like this:
#include "libname.h"
#include "../mylibs/libname.h"
You can use relative path like this:
#include "libname.h"
#include "../mylibs/libname.h"
Quote from LWT98709 on December 14, 2024, 3:44 pmThanks, it works now.
Here are two librairies :
- math.h for the math functions : cos(), sin(), sqrt(), log(), exp(), randomFloat(), randomInt() ...
- graphics.h for the graphics function. Works with a <display name="screen" .../> component.
graphics.h includes math.h already. So, must not include "math.h" if you have "graphics.h".
Thanks, it works now.
Here are two librairies :
- math.h for the math functions : cos(), sin(), sqrt(), log(), exp(), randomFloat(), randomInt() ...
- graphics.h for the graphics function. Works with a <display name="screen" .../> component.
graphics.h includes math.h already. So, must not include "math.h" if you have "graphics.h".
Uploaded files:Quote from LWT98709 on December 20, 2024, 8:19 pmLatest version.
Bipolar and Unipolar mode.Can link to other components :
- To the linked component 0, send an integer number representing the position. Number of values per turn can be set in the property "Linked_value".
- To the linked component 1, send the position in -180 to 180 degree.(Works with the 1.2.0 tester build)
Latest version.
Bipolar and Unipolar mode.
Can link to other components :
- To the linked component 0, send an integer number representing the position. Number of values per turn can be set in the property "Linked_value".
- To the linked component 1, send the position in -180 to 180 degree.
(Works with the 1.2.0 tester build)
Uploaded files: