Spindle pulley ratio and PWM control
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
No.Do you want the system to automatically change gear to suit the selected speed?
Pulley ratio coefficient need to calculate the correct PWM to control the spindle motor.
Please Log in or Create an account to join the conversation.
wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Clo...pindle_Speed_Control
There is also a HAL component called gearchange, but I am not completely clear what it does:
www.linuxcnc.org/docview/html//man/man9/gearchange.9.html
To do what I think you want to do you can use the mux8 (or mux4, mux2, mux16, depending on how many gears you have)
www.linuxcnc.org/docview/html//man/man9/mux8.9.html
You will need to add lines to the HAL file (probably the custom.hal file) with entries like
loadrt mux8
loadrt mult2
addf mux8.0 servo-thread
addf mult2.0 servo-thread
net speed-cmd motion.spindle-speed-out => mult2.in0
net speed_scale mux8.0.out => mult2.0.in1
net speed-out mult2.0.out => {You will need to put the PWM or whatever you are controlling spindle speed with here}
setp mult2.in0 10
setp mult2.in1 20
setp mult2.in3 30
setp mult2.in4 40
(etc)
You also need to connect up the mux8.0.sel0, sel1 and sel2 pins. These would normally be connected to switches on the gearbox shafts which encode the gearchange position. The details of that are rather application-specific.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
I modified the standard component gearchange, this work test code:
pin in bit sel1 "Gear range 1 selection input";
pin in bit sel2 "Gear range 2 selection input";
pin in bit sel3 "Gear range 3 selection input";
pin in float speed_in "Speed command input";
pin out float speed_out "Speed command to DAC/PWM";
param rw float min1 = 0 "Minimum allowed speed in gear range 1";
param rw float max1 = 100000 "Maximum allowed speed in gear range 1";
param rw float min2 = 0 "Minimum allowed speed in gear range 2";
param rw float max2 = 100000 "Maximum allowed speed in gear range 2";
param rw float min3 = 0 "Minimum allowed speed in gear range 3";
param rw float max3 = 100000 "Maximum allowed speed in gear range 3";
param rw float scale1 = 1.0 "Ratio in gear range 1";
param rw float scale2 = 1.0 "Ratio in gear range 2";
param rw float scale3 = 1.0 "Ratio in gear range 3";
function _;
license "GPL";
;;
FUNCTION(_) {
hal_float_t temp_in = speed_in;
if (temp_in < 0) temp_in = -temp_in;
if(sel1){ /*first gear range*/
if (scale1 <= 0){
if (scale1 < 0) scale1 = -scale1;
else if (scale1 == 0) scale1 = 1;
}
if (temp_in < min1) temp_in = min1;
else if (temp_in > max1) temp_in = max1;
temp_in *= scale1; /* scale up to first gear output range */
}
if(sel2){ /*second gear range*/
if (scale2 <= 0){
if (scale2 < 0) scale2 = -scale2;
else if (scale2 == 0) scale2 = 1;
}
if (temp_in < min2) temp_in = min2;
else if (temp_in > max2) temp_in = max2;
temp_in *= scale2; /* scale up to second gear output range */
}
if(sel3){ /*third gear range*/
if (scale3 <= 0){
if (scale3 < 0) scale3 = -scale3;
else if (scale3 == 0) scale3 = 1;
}
if (temp_in < min3) temp_in = min3;
else if (temp_in > max3) temp_in = max3;
temp_in *= scale3; /* scale up to third gear output range */
}
speed_out = temp_in;
}
...
loadrt gearchange
addf gearchange.0 servo-thread
setp gearchange.0.min1 65
setp gearchange.0.min2 150
setp gearchange.0.min3 330
setp gearchange.0.max1 650
setp gearchange.0.max2 1500
setp gearchange.0.max3 3300
setp gearchange.0.scale1 5.076923077
setp gearchange.0.scale2 2.2
setp gearchange.0.scale3 1
net spindle-cmd-ns <= motion.spindle-speed-out => gearchange.0.speed-in
net spindle-cmd <= gearchange.0.speed-out => pwmgen.0.value
...
Who thinks about this component?
Please Log in or Create an account to join the conversation.
Who thinks about this component?
It would be nice to make it as a component with "personality" which could have a configurable number of gears.
Please Log in or Create an account to join the conversation.
Even now, this component is not difficult to modify for the required number of gears.andypugh wrote:
It would be nice to make it as a component with "personality" which could have a configurable number of gears.
Or you can add the maximum amount of gear (10-15), and the required amount set in the hal file?
Please Log in or Create an account to join the conversation.
pin in bit sel1 "Gear range 1 selection input";
pin in bit sel2 "Gear range 2 selection input";
pin in bit sel3 "Gear range 3 selection input";
pin in float speed_in "Speed command input";
pin out float speed_filtred "Speed command to display";
pin out float speed_out "Speed command to DAC/PWM";
param rw float min1 = 0 "Minimum allowed speed in gear range 1";
param rw float max1 = 100000 "Maximum allowed speed in gear range 1";
param rw float min2 = 0 "Minimum allowed speed in gear range 2";
param rw float max2 = 100000 "Maximum allowed speed in gear range 2";
param rw float min3 = 0 "Minimum allowed speed in gear range 3";
param rw float max3 = 100000 "Maximum allowed speed in gear range 3";
param rw float scale1 = 1.0 "Ratio in gear range 1";
param rw float scale2 = 1.0 "Ratio in gear range 2";
param rw float scale3 = 1.0 "Ratio in gear range 3";
function _;
license "GPL";
;;
FUNCTION(_) {
hal_float_t temp_in = speed_in;
if (temp_in != 0){
if (temp_in < 0) temp_in = -temp_in;
if(sel1){ /*first gear range*/
if (scale1 <= 0){
if (scale1 < 0) scale1 = -scale1;
else if (scale1 == 0) scale1 = 1;
}
if (temp_in < min1) temp_in = min1;
else if (temp_in > max1) temp_in = max1;
speed_filtred = temp_in;
temp_in *= scale1; /* scale up to first gear output range */
}
if(sel2){ /*second gear range*/
if (scale2 <= 0){
if (scale2 < 0) scale2 = -scale2;
else if (scale2 == 0) scale2 = 1;
}
if (temp_in < min2) temp_in = min2;
else if (temp_in > max2) temp_in = max2;
speed_filtred = temp_in;
temp_in *= scale2; /* scale up to second gear output range */
}
if(sel3){ /*third gear range*/
if (scale3 <= 0){
if (scale3 < 0) scale3 = -scale3;
else if (scale3 == 0) scale3 = 1;
}
if (temp_in < min3) temp_in = min3;
else if (temp_in > max3) temp_in = max3;
speed_filtred = temp_in;
temp_in *= scale3; /* scale up to third gear output range */
}
speed_out = temp_in;
}else{
speed_filtred = 0;
speed_out = 0;
}
}
I accept any comments and ideas on this component.
Please Log in or Create an account to join the conversation.
This should work for up to 32 gears using:
loadrt gearchange count=2 personality=5,6
It accepts negative speeds, negative outputs and negative scales to allow for gear ranges that reverse the motion.
pin in bit sel-## [32 : personality+1] "Gear range N selection input";
pin in unsigned gear-number "Gear selection as a numeric"
pin in float speed_in "Speed command input";
pin out float speed_filtered "Speed command to display";
pin out float speed_out "Speed command to DAC/PWM";
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";
function _;
license "GPL";
;;
#include <rtapi_math.h>
FUNCTION(_) {
int gear;
if (gear_number) gear = gear_number;
else for (gear = personality ; sel_(gear) || gear=0 ; gear--) {}
speed_filtered = fabs(speed_in);
speed_out = speed in * (scale_(gear) != 0)? scale_(gear) : 1;
if (speed_filtered > max_(gear)) speed_out = max_(gear) * (speed_out/speed_filtered); // no "sign" function in rtapi maths
elseif ((speed_filtered < min_(gear)) speed_out = min_(gear) * (speed_out/speed_filtered) ;
}
Please Log in or Create an account to join the conversation.