I asked a question earlier how can I change speed by means of
adjusting a varidrive. The varidrive is operated by means of pneumatic
solenoids called SPEED INCREASE and SPEED DECREASE.
I had a realization that perhaps, I would be better off writing a M100
command perl script to do so, rather than doing this in HAL.
I wrote this script, which I cannot yet test, but if anyone could have
a look and tell me if I am on the right track, I will appreciate. I
use halcmd and write pretty banal logic for speed changes.
It may be summarized as follows:
- if spindle is not running, start it and wait 1 second.
- calculate acceptable boundaries for actual speed.
- If speed is below acceptable boundary, turn on SPEED INCREASE solenoid.
- If speed is above acceptable boundary, turn on SPEED DECREASE solenoid.
- Assuming speed needed changing, wait up to 20 seconds until speed is
"in range".
- If after 20 seconds speed is in range, good, otherwise bad.
- if spindle was not running prior to this code, stop spindle and wait
until VFD stops is.
The advantage of this approach is that it is done in a totally self
evident script that can be debugged. The disadvantage is that S300
reads better than M141 P300. But I can live with it and leave S
command control VFD speed, which I do not really need to do with
varidrive that much, but just to look cleaner.
Here's a script. It is untested because I am away from home. I would
love to hear comments, esp. about use of halui and hal pins.
#!/usr/bin/perl
print STDERR "$0: " . join( ',', @ARGV ) . ".\n";
sub Kaput {
my ($msg) = @_;
die $msg;
}
sub get_hal {
my ($signal) = @_;
my $out = `halcmd getp $signal`;
chomp $out;
return $out;
}
sub set_hal {
my ($pin, $value) = @_;
system( "halcmd setp $pin $value" )
&& Kaput( "Could not halcmd $pin $value" );
}
my $P = $ARGV[0];
my $Q = $ARGV[1];
my $min_speed = 60;
my $max_speed = 4200;
my $min_delta = 5;
my $pct_delta = 0.05;
my $time_limit = 20; # seconds
my $commanded_speed = $P;
unless ( $min_speed <= $commanded_speed && $commanded_speed <= $max_speed ) {
die "Commanded speed $commanded_speed NOT between limits of
$min_speed and $max_speed";
}
my $lower_limit = max( $min_speed, $commanded_speed * (1-$pct_delta) );
my $upper_limit = min( $max_speed, $commanded_speed * (1+$pct_delta) );
my $was_running = get_hal( 'motion.spindle-on' );
unless ( $was_running ) {
set_hal( "motion.spindle-forward", "TRUE" );
sleep 1;
}
my $start_time = time;
my $ok = undef;
my $speed = get_hal( 'motion.spindle-forward' );
my $increasing;
if ( $speed < $lower_limit ) {
set_hal( 'halui.spindle.increase', 1 );
$increasing = 1;
} elsif ( $speed > $upper_limit ) {
set_hal( 'halui.spindle.decrease', 1 );
$increasing = undef;
} else {
$ok = 1;
}
while( !$ok && time < $start_time+$time_limit ) {
if ( $lower_limit <= $speed && $speed <= $upper_limit ) {
$ok = 1;
last;
}
sleep 0.01;
}
if ( $increasing ) {
set_hal( 'halui.spindle.increase', 0 );
} else {
set_hal( 'halui.spindle.decrease', 0 );
}
unless ( $ok ) {
# Stop spindle. We screwed up
set_hal( 'halui.spindle.is-on', 0 );
Kaput "Could not reach desired speed in $time_limit sec."
unless $ok;
}
unless ( $was_running ) {
# Spindle was not originally running, stop it
set_hal( 'halui.spindle.is-on', 0 );
}
exit 0;
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Emc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-users