Spindle pulley ratio and PWM control
29 Nov 2010 18:03 #5738
by Ivan
Replied by Ivan on topic Re:Spindle pulley ratio and PWM control
Hi andypugh, excellent work.
I have two comments on the code:
1. speed_out = speed_in * (scale_(gear) != 0)? scale_(gear) : 1;
2. speed_filtered - speed for display, for example: s700 reduced up 650rpm and displayed 650rpm, and speed_out = 5.07*650
andypugh, I'm not a C coder, last time I programmed the 8 years ago, in Visual Basic
I have two comments on the code:
1. speed_out = speed_in * (scale_(gear) != 0)? scale_(gear) : 1;
2. speed_filtered - speed for display, for example: s700 reduced up 650rpm and displayed 650rpm, and speed_out = 5.07*650
andypugh, I'm not a C coder, last time I programmed the 8 years ago, in Visual Basic
Please Log in or Create an account to join the conversation.
30 Nov 2010 00:51 #5758
by andypugh
Replied by andypugh on topic Re:Spindle pulley ratio and PWM control
Another version. This retains all the pins names and functions of the previous version, so that upgrades do not break any existing configs.
This one has the extra advantage of working and having been tested.
component gearchange """Select from one two speed ranges
The output will be a value scaled for the selected gear, and clamped to
the min/max values for that gear.
This should work for up to 32 gears using (for two instances, one with 5 gears
and one with 6):
loadrt gearchange count=2 personality=5,6
for a single instance with 11 gears you can use:
loadrt gearchange personality=11
It accepts negative speeds, negative outputs and negative scales to allow for
gear ranges that reverse the motion.
The scale is the ratio between input speed and output speed, so the same VFD
scale parameter will work for any gear. If gear 1 is the slowest gear then other
ratios will probably need to be fractional. If the highest numbered gear is the
slowest then the scales will probably need to be greater than one.
The gear can be input either as a numeric value (possibly assembled from
/fBweighted_sum/fR components to convert the positions of several levers into a
gear) or as an individual select bit for each gear. """;
pin in float speed-in "Speed command input";
pin out float speed-out "Speed command to DAC/PWM";
pin in bit gear-#-sel [32 : personality+1] "Gear range N selection input";
pin in bit sel "alias for sel2 for compatibility with the previous version ";
pin in bit dir_in "direction input";
pin out bit dir_out "direction output (will be reversed for negative scales)";
pin in unsigned gear-number "Gear selection as a numeric";
pin out float speed-filtered "Speed command to display";
pin out unsigned gn;
param rw float min#[32: personality+1] = 0 "Minimum allowed speed in gear range N";
param rw float max#[32:personality+1] = 100000 "Maximum allowed speed in gear range N";
param rw float scale#[32:personality+1] = 1.0 "Ratio in gear range 1";
param rw bit reverse "negates the value of scale2, for compatibility";
option extra_setup;
function _;
license "GPL";
;;
#include <rtapi_math.h>
FUNCTION(_) {
int gear;
if (sel) gear = 2; // Backwards compatibility
else if (gear_number) gear = gear_number;
else for (gear = personality ; gear > 0 && !gear_sel(gear) ; gear--) {}
gn = gear;
speed_filtered = fabs(speed_in);
if (speed_filtered > max(gear)) speed_filtered = max(gear);
else if (speed_filtered < min(gear)) speed_filtered = min(gear);
speed_out = speed_filtered * ((scale(gear) != 0)? scale(gear) : 1);
speed_out *= (speed_in < 0)? -1 : 1 ;
dir_out = ((scale(gear) < 0)? !dir_in : dir_in);
dir_out = ((reverse && gear == 2)? !dir_out : dir_out); // Backwards compatibility
}
EXTRA_SETUP( ) {
if (personality == 0) personality = 2;
return 0;
}
This one has the extra advantage of working and having been tested.
component gearchange """Select from one two speed ranges
The output will be a value scaled for the selected gear, and clamped to
the min/max values for that gear.
This should work for up to 32 gears using (for two instances, one with 5 gears
and one with 6):
loadrt gearchange count=2 personality=5,6
for a single instance with 11 gears you can use:
loadrt gearchange personality=11
It accepts negative speeds, negative outputs and negative scales to allow for
gear ranges that reverse the motion.
The scale is the ratio between input speed and output speed, so the same VFD
scale parameter will work for any gear. If gear 1 is the slowest gear then other
ratios will probably need to be fractional. If the highest numbered gear is the
slowest then the scales will probably need to be greater than one.
The gear can be input either as a numeric value (possibly assembled from
/fBweighted_sum/fR components to convert the positions of several levers into a
gear) or as an individual select bit for each gear. """;
pin in float speed-in "Speed command input";
pin out float speed-out "Speed command to DAC/PWM";
pin in bit gear-#-sel [32 : personality+1] "Gear range N selection input";
pin in bit sel "alias for sel2 for compatibility with the previous version ";
pin in bit dir_in "direction input";
pin out bit dir_out "direction output (will be reversed for negative scales)";
pin in unsigned gear-number "Gear selection as a numeric";
pin out float speed-filtered "Speed command to display";
pin out unsigned gn;
param rw float min#[32: personality+1] = 0 "Minimum allowed speed in gear range N";
param rw float max#[32:personality+1] = 100000 "Maximum allowed speed in gear range N";
param rw float scale#[32:personality+1] = 1.0 "Ratio in gear range 1";
param rw bit reverse "negates the value of scale2, for compatibility";
option extra_setup;
function _;
license "GPL";
;;
#include <rtapi_math.h>
FUNCTION(_) {
int gear;
if (sel) gear = 2; // Backwards compatibility
else if (gear_number) gear = gear_number;
else for (gear = personality ; gear > 0 && !gear_sel(gear) ; gear--) {}
gn = gear;
speed_filtered = fabs(speed_in);
if (speed_filtered > max(gear)) speed_filtered = max(gear);
else if (speed_filtered < min(gear)) speed_filtered = min(gear);
speed_out = speed_filtered * ((scale(gear) != 0)? scale(gear) : 1);
speed_out *= (speed_in < 0)? -1 : 1 ;
dir_out = ((scale(gear) < 0)? !dir_in : dir_in);
dir_out = ((reverse && gear == 2)? !dir_out : dir_out); // Backwards compatibility
}
EXTRA_SETUP( ) {
if (personality == 0) personality = 2;
return 0;
}
Please Log in or Create an account to join the conversation.
30 Nov 2010 01:29 #5759
by cmorley
Replied by cmorley on topic Re:Spindle pulley ratio and PWM control
Can you add acceleration limiting too?
pncconf is looking for a gear change component that has velocity and acceleration limiting built in.
pins for at-max and at-min status would be nice too.
Chris M
pncconf is looking for a gear change component that has velocity and acceleration limiting built in.
pins for at-max and at-min status would be nice too.
Chris M
Please Log in or Create an account to join the conversation.
30 Nov 2010 12:34 #5763
by andypugh
Replied by andypugh on topic Re:Spindle pulley ratio and PWM control
cmorley wrote:
If all that is needed is an array of accel values, then yes, no trouble. If it is more complicated than that then I think I need a more detailed description.
Cut you a deal, I can put that into the gearchange component if you put 8i20 NVRAM programming into pncconf
Can you add acceleration limiting too?
If all that is needed is an array of accel values, then yes, no trouble. If it is more complicated than that then I think I need a more detailed description.
Cut you a deal, I can put that into the gearchange component if you put 8i20 NVRAM programming into pncconf
Please Log in or Create an account to join the conversation.
30 Nov 2010 20:17 #5779
by Ivan
Replied by Ivan on topic Re:Spindle pulley ratio and PWM control
andypugh, how to make a dynamic change min / max values for the progress bar? And is it possible to dynamically change the color of progress bar?
For example:
<pyvcp>
<label>
<text>"Spindle speed:"</text>
</label>
<bar>
<halpin>"spindle-speed"</halpin>
<min_>65</min_> #dynamic change for each gear range
<max_>650</max_>
</bar>
</pyvcp>
For example:
<pyvcp>
<label>
<text>"Spindle speed:"</text>
</label>
<bar>
<halpin>"spindle-speed"</halpin>
<min_>65</min_> #dynamic change for each gear range
<max_>650</max_>
</bar>
</pyvcp>
Please Log in or Create an account to join the conversation.
30 Nov 2010 20:37 #5780
by andypugh
Replied by andypugh on topic Re:Spindle pulley ratio and PWM control
Ivan wrote:
As far as I know, neither is possible. You might be able to add the ability by editing the pyvcp_widgets.py file.
(and I might be wrong on both counts)
andypugh, how to make a dynamic change min / max values for the progress bar? And is it possible to dynamically change the color of progress bar?
As far as I know, neither is possible. You might be able to add the ability by editing the pyvcp_widgets.py file.
(and I might be wrong on both counts)
Please Log in or Create an account to join the conversation.
30 Nov 2010 20:52 #5781
by Ivan
Replied by Ivan on topic Re:Spindle pulley ratio and PWM control
Thanks, I'll try to edit pyvcp_widgets.py file.
Please Log in or Create an account to join the conversation.
30 Nov 2010 22:08 #5782
by Ivan
Replied by Ivan on topic Re:Spindle pulley ratio and PWM control
andypugh, you programmed in python?
Please Log in or Create an account to join the conversation.
30 Nov 2010 22:54 #5785
by andypugh
Replied by andypugh on topic Re:Spindle pulley ratio and PWM control
Never. Sorry. It's incomprehensible to me.
Please Log in or Create an account to join the conversation.
Time to create page: 0.154 seconds